Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Creating modules for installation

by wwvuillemot (Initiate)
on Apr 21, 2002 at 16:55 UTC ( [id://160897]=perlquestion: print w/replies, xml ) Need Help??

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

I have looked for a complete introduction to creating modules, but have yet to find the following questions.

Background: I have a large library of modules that I have written. I am working on three machines (Win2k, Linux, Mac) that are not connected. I want to have an easy way to distribute/update modifications to the modules, including the dependent modules (e.g. DBI, DBD::mysql) using CPAN.

  1. Is h2xs sufficient for my needs?
  2. Will it handle other modules (e.g. DBI, DBD::mysql) if they are not loaded on the machine?
  3. Does CPAN handle this automatically? I do not want to necessarily include the other modules, just have CPAN know enough to install them as dependencies if they are not already installed.
  4. How should I handle versioning of the module collection? Once installed, I want to easily update the files.

2002-04-21 Edit by Corion : Closed <OL> tag.

Replies are listed 'Best First'.
Re: Creating modules for installation
by andreychek (Parson) on Apr 21, 2002 at 17:42 UTC
    If you intend on putting your modules on CPAN, what you're looking to do is fairly straightforward. Your question is well timed -- just the other day, a tutorial was created on How to make a CPAN Module Distribution. I highly recommend checking that out, it will get you started in the right direction.

    Regarding your specific points above:

    1. Is h2xs sufficient for my needs?

    All your requirements that you mentioned, believe it or not, are fairly typical. Using h2xs should be just fine for you, and the previously mentioned tutorial shows you how you can use it properly.

    2. Will it handle other modules (e.g. DBI, DBD::mysql) if they are not loaded on the machine?

    Sure! The tutorial doesn't really get into this, but the perldoc for ExtUtils::MakeMaker can help you out here. What you need to use is the parameter "PREREQ_PM". Also, be sure to take a peek at how some other modules make use of this, that should really help you out.

    3. Does CPAN handle this automatically? I do not want to necessarily include the other modules, just have CPAN know enough to install them as dependencies if they are not already installed.

    If you intend on putting your modules on CPAN, then yes, downloading prerequisite modules is handled for you, assuming you put your requirements in the "PREREQ_PM" mentioned above.

    If you don't want to put your modules on CPAN for some reason, perhaps you should look into ExtUtils::AutoInstall. From the Description:

    ExtUtils::AutoInstall lets module writers to specify a more sophisticated form of dependency information than the PREREQ_PM option offered by ExtUtils::MakeMaker.

    Basically, it properly handles installing module dependencies, whether or not you are running under CPAN. Additionally, it allows you the flexibility of having optional features, and it can ask at install-time of your module which dependencies you desire to load.

    4. How should I handle versioning of the module collection? Once installed, I want to easily update the files.

    Versioning is also handled by a combination of ExtUtils::MakeMaker (or ExtUtils::AutoInstall if you decide to use it), and a package variable in your module. In your Makefile.PL, you could use the "VERSION_FROM" parameter like so:

    VERSION_FROM => 'lib/MyModule.pm'

    And then, in MyModule.pm, you would need to include this line:

    $MyModule::VERSION="1.23";

    With this setup, CPAN or CPANPLUS will be capable of determining the version of your module, and from that will be able to know whether or not to update it.

    I hope that helps!
    -Eric

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-03-28 13:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found