Subject Name: how to create Perl Packages (Node ID: 49       Group: i3d)




 

Web Resources:  Google It          Yahoo It          Bing It

We should definitely use 'h2xs' tool to create the work space and needed files, let's see if h2xs is available:
[~/mydev]# which h2xs
/usr/bin/h2xs
Next, choose the module name or package name, here I use "Mol" as the example:
[~/mydev]# h2xs -AXc -n Mol
Defaulting to backwards compatibility with perl 5.8.8
If you intend this module to be compatible with earlier perl versions, please
specify a minimum perl version with the -b option.
Writing Mol/lib/Mol.pm
Writing Mol/Makefile.PL
Writing Mol/README
Writing Mol/t/Mol.t
Writing Mol/Changes
Writing Mol/MANIFEST
[~/mydev]# cd Mol
[~/mydev/Mol]# ls
Changes
MANIFEST
Makefile.PL
README
lib/
t/
[~/mydev/Mol]# cd lib
[~/mydev/Mol/lib]# ls
./ ../ Mol.pm
Mol.pm is the file to write the perl code, just like any lib file, we can vi it and have a look here:
[~/mydev/Mol/lib]# vi Mol.pm
--------------------------------------------------------------------------------
package Mol;
use 5.008008;
use strict;
use warnings;

require Exporter;
our @ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.

# This allows declaration use Mol ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = ( 'all' => [ qw() ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw( );
our $VERSION = '0.01';

# Preloaded methods go here.
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME

Mol - Perl extension for blah blah blah

=head1 SYNOPSIS