Pack the perl module and add it to the external dependency program

Source: Internet
Author: User
Tags movable type smokeping


Not all things in the Perl community are published on CPAN. The Module: ThirdParty Module records the list of non-CPAN perl projects. The most famous one is the blog's Movable Type and monitoring SmokePing.

However, if you want to easily package smokeping and deploy and use your personal images, you will find a small problem: packaging them into rpm, and many perl dependency modules may not necessarily exist in the system repo; when packaged into a perl module, the most common probe FOR smokeping, such as fping and curl, is a non-perl program. cpanm cannot solve this requires_external_bin problem and can only report an error and exit at most.

In fact, some other methods can be taken here, although stupid, but to solve the problem.

First, let's create an example module:


The Code is as follows: cpanm Module: Starter Module: Build
Module-starter -- module Alien: FPing -- author = "Jeff Rao" -- email = "myname@gmail.com" -- mb

Then, an Alien-FPing directory will be created under this directory, and the Build. PL and other module files will be provided. The Alien: namespace is a potential rule. Some projects depend on the C source code library and header file, and are installed on the perl Package layer, for example, Alien: V8, Alien: Gearmand, Alien: IE7, and so on.

Now let's download the source code of fping and put it in the module:


The Code is 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 compile Build. PL. However, to make Build. PL look concise and clear at a glance. We 'd better define a separate module for the compilation operation:

The Code is 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 = "running successfully 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 just calling shell. The only thing you need to talk about is this ACTION_build. This is the Module: the method that the Build defines to provide to subclass. In fact,./Build help shows that all the actions can be used in a similar way.

Then, modify Build. PL as follows:

Code: 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. Ms ',
Release_status => 'stable ',
Configure_requires => {
'Module: built' => 0,
},
Build_requires => {
'Test: More '=> 0,
},
Requires => {
# 'Abc' = & gt; 1.6,
# 'Foo: Bar: module' => 5.0401,
},
Add_to_cleanup => ['alien-FPing-* '],
Create_makefile_pl => 'traditional ',
);
$ Builder-> create_build_script ();

Replace Module: Build with Alien: FPing: Build.

Then, give it a try:

The Code is as follows: cd Alien-FPing
Perl Build. PL
./Build

Check the compilation output and install/usr/sbin/fping. You can package it now. Note that the inc directory is excluded from the default generated ignore.txt. You need to remove the Directory and modify the MANIFEST file to add the files in inc and src, then the packaged perl module can be used directly.

The Code is 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.