Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: Re: MakeMaker, h2xs, and writing CPAN modules

by stajich (Chaplain)
on Jun 24, 2002 at 01:43 UTC ( [id://176666]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: MakeMaker, h2xs, and writing CPAN modules
in thread MakeMaker, h2xs, and writing CPAN modules

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.

Replies are listed 'Best First'.
Re: Re: Re: Re: MakeMaker, h2xs, and writing CPAN modules
by perrin (Chancellor) on Jun 24, 2002 at 01:48 UTC
    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.
      Okay - now that you mention it, I do remember h2xs being quite unhelpful when setting up namespaces. Aren't you kind of starting from scratch anyways though if you are creating modules with h2xs. Can you not just code up the correct directory and namespaces by hand or are you actually porting C code with h2xs? I think that the behavior is really quite unhelpful - I mean when you say you want h2xs -X -A -n Foo::Bar you shold get Foo/Bar.pm, no? But you get Foo/Bar/Bar.pm - maybe there's a cmd line arg that I am ignorant of.

      Now I think that setting up a Makefile.PL is actually really easy (barring the too many files problem), are you sure you can't just do:

      <code> (Makefile.PL) WriteMakefile( 'NAME' => 'Foo::Bar' 'VERSION' => '0.01', '$] >= 5.005 ? ## add keywords that 5.005 and beyond support ('AUTHOR' => 'perrin') ); Am I oversimplifying your needs? I found that a lot of the Exporter and AUTOLOAD crap that comes with the basic h2xs skeleton was causing me the problems when I just tried to test the install - I make sure and run h2xs with -A to avoid any problems resulting from that.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-29 07:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found