thor has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

As I continue to advance, I find that there are certain things that I just don't have experience with. One of these is module-based development. I've written a ton of self-contained scripts, but not a whole lot of modules. Well, I find myself in a situation where creating a module would be beneficial. So, I created the initial module with h2xs and everything was good. However, I find that now I want to add another pm file to the distribution. Is there an easy way to do this with h2xs or something else? I realize that I could just start writing it from scratch, but I like the code template (and test template) that h2xs uses. Copying my already existing pm file doesn't seem like the best way to go about this, especially given that if I've already created Foo, that Foo::Bar would go to lib/Foo/Bar.pm.

Thanks in advance,
thor

Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come

  • Comment on Adding a package to an already existing distribution

Replies are listed 'Best First'.
Re: Adding a package to an already existing distribution
by gam3 (Curate) on Sep 07, 2005 at 17:16 UTC
    All you need to do is create lib/Foo/Bar.pm and t/Foo_Bar.t. Then rerun perl Makefile.PL or Build.

    Everything else will be done for you.

    José's Guide for creating Perl modules has more information.

    -- gam3
    A picture is worth a thousand words, but takes 200K.
Re: Adding a package to an already existing distribution
by borisz (Canon) on Sep 07, 2005 at 17:14 UTC
    Just copy your new .pm file. If you have already lib/Foo.pm create the dir lib/Foo and copy Bar.pm into it. Then add lib/Foo/Bar.pm to the MANIFEST. Thats all.

    PS: Much more userfriendly than h2xs is Module::Starter
    Boris
      The problem is that I've already invested heavily in Foo.pm. So, in order to do this, I'd have to copy the module over, delete the already existing code, and change the name of the module not only in the package statement, but the POD as well. Repeat for the testing. It just seems rather silly that h2xs (and Module::Starter from what I've seen of it) assume that you'll know every class that will go into a distribution at the time of creation. CWould it be a bad idea to rework these tools so that instead of failing to create a file, it would test for existance first and if it exists say something like "Foo.pm skipped: already exists"? If it's not a bad idea, then I could even do the work. Ah...to see my name somewhere "official"...

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

        I think I messed the question. You have a module created with lib/Foo.pm Your module is named Foo. Then you like to extend Foo with Foo::Bar ( or at least add a module Bar. ) Then there is no need to change anything just add a new dir to your lib directory.
        lib/Foo.pm lib/Foo/Bar.pm
        If you want to rename something try perl's inplace edit or look if Module::Rename can help.
        Boris
Re: Adding a package to an already existing distribution
by ghenry (Vicar) on Sep 07, 2005 at 17:36 UTC

    There's also a lot of great info in Writing Solid CPAN Modules

    Walking the road to enlightenment... I found a penguin and a camel on the way.....
    Fancy a yourname@perl.me.uk? Just ask!!!