Jessada Thutkawkorapin
Jessada Thutkawkorapin

Reputation: 1346

Is there a simplest way to build perl package

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

Answers (2)

LeoNerd
LeoNerd

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:

  • The name of the primary module in the distribution - this is where the name of the distribution itself is taken from, as well as its version and abstract summary
  • Other modules that this distribution will depend on to build or run
  • Other modules that this distribution will depend on to build, but won't be required once it's installed (typically this will be Test:: modules or other build tools)
  • The licencing terms applied to the distribution
  • Create a legacy Makefile.PL for older CPAN clients that do not understand the Build.PL protocol
  • Create a LICENSE file automatically from the declared licencing terms above
  • Create a README file automatically by turning the main module's POD documentation into plaintext

Upvotes: 2

user554546
user554546

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

Related Questions