Perl Module Packaging Add external dependencies _perl

Source: Internet
Author: User
Tags pack movable type smokeping

Not everything in the Perl community is posted on CPAN. There is even a module::thirdparty module that records the list of these CPAN Perl projects. One of the most famous should be the movable Type of blogging and the smokeping of monitoring.

But if your personal chart is convenient and you want to pack smokeping for deployment, you'll find a small problem: packaging into RPM, many of Perl's dependent modules do not necessarily exist in the system repo, packaged into Perl modules, smokeping most commonly used probe such as FP ing, curl or something, is not a Perl program, CPANM can not solve the requires_external_bin, at most only the error exit.

In fact, there can be some other way, although a bit stupid, but to solve the problem.

First, let's Create a sample module:

Copy Code code as follows:

Cpanm Module::starter Module::build
Module-starter--module alien::fping--author= "Jeff Rao"--email= "myname@gmail.com"--MB

Then in this directory will create a alien-fping directory, with the build.pl module files. Here uses the Alien:: The name space, is a latent rule, some projects rely on C source of the library and header files, with Perl package layer to install, are placed in this space, such as ALIEN::V8, Alien::gearmand, Alien::ie7 and so on.

Now let's download Fping's source stacking into the module:

Copy Code code as follows:

mkdir ALIEN-FPING/SRC
wget Http://www.fping.org/dist/fping-3.4.tar.gz-O alien-fping/src/fping-3.4.tar.gz

The next step is to write build.pl. But to try to make build.pl look neat and to see the purpose. We'd better define a single module to use for the compilation operation:

Copy Code code as follows:

Package alien::fping::build;
Use base QW (Module::build);
Use File::spec;
Use Archive::tar;
My $RootDir = File::spec->rel2abs (".");
My $SrcDir = File::spec->catdir ($RootDir, "src");
My $FPingVersion = ' 3.4 ';
My $FPingName = "fping-${fpingversion}";
My $FPINGSRC = "${fpingname}.tar.gz";
Sub Action_build {
my $self = shift;
ChDir ($SrcDir);
if (!-x "/usr/sbin/fping" and!-d $FPingName) {
My $tar = Archive::tar->new ();
$tar->read ($FPINGSRC);
$tar->extract ();
ChDir ($FPingName);
System ('./configure ', '--prefix=/usr/', '--enable-ipv6 ');
System (' make ');
System (' make install ');
}
$self->super::action_build ();
};
1;

It's almost like calling the shell, and the only thing that needs to be said is this action_build. This is the module::build definition of the method provided to subclass, in fact. All the action that/build help sees has a similar approach.

Then slightly modify the build.pl as follows:

Copy Code code as follows:

Use 5.006;
Use strict;
Use warnings FATAL => ' all ';
Use Lib ' inc ';
Use Alien::fping::build;
My $builder = Alien::fping::build->new (
Module_name => ' alien::fping ',
License => ' Perl ',
Dist_author => Q{jeff Rao <myname@gmail.com>
Dist_version_from => ' lib/alien/fping.pm ',
Release_status => ' stable ',
Configure_requires => {
' Module::build ' => 0,
},
Build_requires => {
' Test::More ' => 0,
},
Requires => {
# ' ABC ' => 1.6,
# ' Foo::bar::module ' => 5.0401,
},
Add_to_cleanup => [' alien-fping-* '],
CREATE_MAKEFILE_PL => ' traditional ',
);
$builder->create_build_script ();

Replace the module::build with Alien::fping::build, and nothing else to move.

Then try it:

Copy Code code as follows:

CD alien-fping
Perl build.pl
./build

See the compilation output, and the successful installation has/usr/sbin/fping it. It's ready to pack now. Note that the default generated Ignore.txt, which excludes the INC directory, needs to be removed, and then the MANIFEST file is added to the files in the Inc and SRC, and the Perl modules that are packaged out can be used directly.

Copy Code code as follows:

Sed-i '/INC/D ' ignore.txt
Echo ' inc/alien/fping/build.pm ' >> MANIFEST
Echo ' src/fping-3.4.tar.gz ' >> MANIFEST
./build Dist

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.