Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: MakeMaker, h2xs, and writing CPAN modules

by samtregar (Abbot)
on Jun 24, 2002 at 00:19 UTC ( #176652=note: print w/replies, xml ) Need Help??


in reply to MakeMaker, h2xs, and writing CPAN modules

Why do you want to use the module without installing it? Is it to test the module during development? If so, put your test code in test.pl and run it with make test. Alternately you can delete test.pl and create a t/ directory containing multiple test scripts with arbitary names that will be run by make test.

If you're just in the mood to run arbitrary scripts against your development copy of Bar.pm then a quick hack would be:

$ ln -s Foo/Bar/Bar.pm Foo/Bar.pm $ export PERL5LIB=`pwd`

Modulo your shell of choice - the above is for bash.

The blib solution mentioned already will also work but you'll need to do a make to copy Bar.pm into Foo/Bar/blib/ each time you make a change.

-sam

PS: I cover all this and more in my upcoming book - Writing Perl Modules for CPAN.

Replies are listed 'Best First'.
Re: Re: MakeMaker, h2xs, and writing CPAN modules
by perrin (Chancellor) on Jun 24, 2002 at 01:16 UTC
    Thanks, the symlink approach seems to fit what I'm after. There are subclasses in my module (Foo::Bar::Baz) so I guess I'll try linking the directory rather than just one file.

    What I'm trying to do seems like it should be easy: make a module skeleton with h2xs, work on it in place, and finally make a release from it. The "work on it in place" is turning out to be surprisingly difficult. So far I've just installed it into a local directory (so that I don't have to edit it as root) and I'll have to copy it back into my release directory structure when I have a version that's ready to go. I can live with that, but I expected to be able to work on it directly in place after creating it with h2xs.

    I'm using the module in the context of mod_perl, so being able to run it from scripts outside of the module's directory is necessary.

      Ahh - this really sounds like you are making this harder than it should be. I like to have the following kind of structure (below). In the XP fashion I like to write my tests first as I build up the object. I must admit to not using h2xs that much, but we have a template that is used to create new modules which need to inherit from a base class anyways so I guess we're still being structured (whew).
      project/lib/Foo/Bar/Baz.pm project/lib/Foo.pm project/t/test1.t $ cat t/test1.t use lib './lib'; use strict; my $error; BEGIN { use vars qw($TESTCOUNT); use Test; # so we actually do some more stuff # here to load the Test module # since we distribute it with our package # in case the user doesn't have it $TESTCOUNT = 3; plan tests => $TESTCOUNT; # do some other testing eval { Some::module::Needed; }; if( $@ ) { $error =1 } } END { # if we exit prematurely in the test the testcount # will still be okay (assuming we want to bail # when some module isn't installed or # or the network is unavailable, etc. foreach ( $Test::ntest..$TESTCOUN) { skip("unable to run all the tests",1); } } if( $error ) { exit(0) } use Foo; use Foo::Bar::Baz; my $foo = new Foo(-id => '10'); ok($foo); ok($foo->id, '10); my $baz = new Foo::Bar::Baz(-magicword => 'peanutbuttersandwiches'); ok($base->magic, 'peanutbuttersandwiches'); $ perl -I. -w t/test1.t 1..3 ok 1 ok 2 ok 3
      The above wasn't actually run but hopefully I didn't leave any typos in - if you don't want to put things in a lib directory you can always s/lib/ above and all will work (your would be doing use lib '.' instead). You can also have PERL5LIB set to include XXX/project/lib. I may be overzealous using the perl -I. -w for my tests when I have PERL5LIB set, but since often I have version of the toolkit installed while I'm working on the next one, I don't want to get confused about which code I am actually running.
        If I started from scratch, I would do it that way. However, I want this to go to CPAN, and I don't want to fuss with MakeMaker myself, so using the skeleton generated by h2xs seems like the way to go. Unfortunately, h2xs does not generate a directory structure that works if you just try to use the modules in place without installing them.
Re: Re: MakeMaker, h2xs, and writing CPAN modules
by tachyon (Chancellor) on Jun 24, 2002 at 20:02 UTC

    PPS: I covered this in a Perlmonks tutorial How to make a CPAN Module Distribution. Here, now, and available for free.... There is a good thread around it offering plenty of M to FWR if you need more details or would like to look at some of the alternatives to h2xs.

    Hope you get some mileage.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://176652]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2018-08-19 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:









    Results (186 votes). Check out past polls.

    Notices?