Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Agenda
What a Perl Module is
Why it is convenient to use Perl Modules How to make Perl Modules
[Perl] code that can be used by a Perl program (or by other Perl modules) It is conceptually similar to:
The Perl interpreter has a list of directories in which it searches for modules (global array @INC)
Before making a PM
Chose an appropriate name for the PM
Each Perl Module has an unique name. Perl
provides a hierarchal name space for modules, similar to the name space for Java classes.
Components of a module name are separated
-A omits the Autoloader code (best used by modules that define a large number of infrequently used subroutines) -X omits XS elements (eXternal Subroutine, where eXternal means external to Perl, i.e. C) -n specifies the name of the module
Changes Makefile.PL MANIFEST (contains the list of all files in the package) README t/ (test files) PingER.pm (perl code goes here)
$VERSION=1.03;
@EXPORT = qw(ping_it); sub ping_it { }
1;
__END__
Recipe:
use 5.008; use strict; use warnings; use Carp; require Exporter; our @ISA = qw(Exporter); use Time::CTime; use DB_File;
$ping_interval, $ping_size, $ping_count) = @_; return ($time, $packets_sent, $packets_rcvd, $min, $avg, $max, \@seqno, \@pingtimes); }
timeping.pl
use IEPM::PingER; ($time, $packets_sent, $packets_rcvd, $min,
IEPM-PingER-1.03.tar.gz
13
References
Perl Module Mechanics
http://world.std.com/~swmcd/steven/perl/module_mechanics.html The Perl Module Library http://search.cpan.org/author/JHI/perl-5.8.0/pod/perlmodlib.pod Perl Modules http://search.cpan.org/author/JHI/perl-5.8.0/pod/perlmod.pod The Perl 5 Modules List http://www.cpan.org/modules/00modlist.long.html Practical Perl Programming http://www.cs.cf.ac.uk/Dave/PERL/node131.html Perlnewmod - preparing a new module for distribution http://www.perlpod.com/5.6.1/perlnewmod.html
14