Reputation: 1346
I wrote a few Perl libraries(.pm) and Perlscripts(.pl) on Ubuntu and I need to distribute them to my colleagues in my office. Those scripts and libraries require third party libraries. I want to make it very simple.
Infomation about me.
Upvotes: 12
Views: 1923
Reputation: 8532
My usual method these days is to simply copy a Build.PL
file from one of my existing distributions, and go from there. Obviously that's not a useful strategy for the first one, but CPAN is full of thousands of these files.
For a simple single-.pm
file pure-perl distribution it's probably easiest to start by copying someone else's Build.PL
file and edit the fields as appropriate for your case. Likely all you should need to change are the module_name
and requires
fields.
Here's a simple one of mine you can steal^W be inspired by:
use strict;
use warnings;
use Module::Build;
my $build = Module::Build->new(
module_name => 'Your::Name::Here',
requires => {
'Your::Requirements::Here' => '1.23',
},
build_requires => {
'Test::More' => 0,
},
license => 'perl',
create_makefile_pl => 'traditional',
create_license => 1,
create_readme => 1,
);
$build->create_build_script;
These fields, in order, mean:
Test::
modules or other build tools)Makefile.PL
for older CPAN clients that do not understand the Build.PL
protocolLICENSE
file automatically from the declared licencing terms aboveREADME
file automatically by turning the main module's POD documentation into plaintextUpvotes: 2
Reputation:
I'd recommend using Module::Starter
to set up a template for each module. Once it's installed, you can call module-starter
from the command line, eg:
module-starter --module=My::Module --author="Jessada Thutkawkorapin" [email protected]
or, if you want a distribution with multiple modules:
module-starter --distro=Foo --module=Foo,Foo::Bar,Foo::Baz --author="Jessada Thutkawkorapin" [email protected]
Then, just overwrite the .pm
files with your modules, include any unit tests that you want to run (the default tests basically check the syntax of the module along with the pod syntax). A basic installation of the modules is then done via
perl Makefile.PL
make
make test
make install
(technically, make test
is optional, but it's highly recommended).
Now, if these modules rely on other CPAN modules, then you can use the module CPAN
to install them, eg:
use strict;
use warnings;
use CPAN;
#populate however you'd like, either hard-coded, read from a file, etc.
my @modules_to_install=();
foreach(@modules_to_install)
{
CPAN::Shell->install($_);
}
So, you can distribute a zip/tarball/etc with the folders and files that module-starter
started (and that you modified) along with the above script to install any CPAN dependencies, and call it, say, cpan_install.pl
. If you want, you can then wrap everything up in a final script called, say, install.pl
that does all of these things.
Upvotes: 15