Difference between revisions of "Creating a Perl Module"
(Templates added for creating perl modules including using Exporter for short names) |
(replace content with our established procedure) |
||
Line 3: | Line 3: | ||
|role = dev | |role = dev | ||
}} | }} | ||
+ | A Perl module is essentially just a ''.pm'' file which has a specific structure allowing it to extend the native Perl runtime environment to add new namespaces, objects and subroutines etc. The ''.pm'' structure also allows for automatically generated documentation. | ||
− | == | + | == Create package skeleton == |
− | + | To ensure that the module is added to the operating system environment properly, it should be wrapped into a ''package'' so that it can be installed with ''make'' and ''make install'' in the usual way. We use the [http://linux.about.com/library/cmd/blcmdl1_h2xs.htm h2xs] utility. | |
− | + | h2xs -XAn OrganicDesign::Example | |
− | + | This will create a working structure which can be installed and then included in a Perl script with ''use OrganicDesign::Wiki''. | |
− | + | == Modify the module file == | |
− | + | In the directory structure created by ''h2xs'' is a subdirectory called ''lib'' which contains a template ''.pm'' module file which can be refined and extended to your needs. Generally the first thing to do would be to add comments at the beginning describing the module, and edit the documentation section at the end. Then create a constructor and other required methods. See [[OrganicDesign::Wiki.pm]] for an example of one of our modules. | |
− | + | == Updating the package == | |
− | package | + | ''Dunno how to do this properly yet'' |
− | |||
− | + | == See also == | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | ==See also== | ||
*[http://www.perlmonks.org/index.pl?node_id=431702 José's Guide for creating Perl modules] | *[http://www.perlmonks.org/index.pl?node_id=431702 José's Guide for creating Perl modules] | ||
*[http://www.perl.com/lpt/a/995 Making Perl Reusable with Modules - users Module::starter] | *[http://www.perl.com/lpt/a/995 Making Perl Reusable with Modules - users Module::starter] | ||
Line 104: | Line 24: | ||
*[http://world.std.com/~swmcd/steven/perl/module_mechanics.html Perl Module Mechanics] | *[http://world.std.com/~swmcd/steven/perl/module_mechanics.html Perl Module Mechanics] | ||
*[http://www.perlmonks.org/index.pl?node_id=431702 José's Guide for creating Perl modules] | *[http://www.perlmonks.org/index.pl?node_id=431702 José's Guide for creating Perl modules] | ||
+ | *[http://www.vromans.org/johan/articles/makemaker.html Makemaker made easy] |
Revision as of 23:57, 30 August 2008
Creating a Perl Module Organic Design procedure |
A Perl module is essentially just a .pm file which has a specific structure allowing it to extend the native Perl runtime environment to add new namespaces, objects and subroutines etc. The .pm structure also allows for automatically generated documentation.
Create package skeleton
To ensure that the module is added to the operating system environment properly, it should be wrapped into a package so that it can be installed with make and make install in the usual way. We use the h2xs utility.
h2xs -XAn OrganicDesign::Example
This will create a working structure which can be installed and then included in a Perl script with use OrganicDesign::Wiki.
Modify the module file
In the directory structure created by h2xs is a subdirectory called lib which contains a template .pm module file which can be refined and extended to your needs. Generally the first thing to do would be to add comments at the beginning describing the module, and edit the documentation section at the end. Then create a constructor and other required methods. See Wiki.pm for an example of one of our modules.
Updating the package
Dunno how to do this properly yet