3 perlmodlib - constructing new Perl modules and finding existing ones
7 =head1 THE PERL MODULE LIBRARY
9 Many modules are included the Perl distribution. These are described
10 below, and all end in F<.pm>. You may discover compiled library
11 file (usually ending in F<.so>) or small pieces of modules to be
12 autoloaded (ending in F<.al>); these were automatically generated
13 by the installation process. You may also discover files in the
14 library directory that end in either F<.pl> or F<.ph>. These are
15 old libraries supplied so that old programs that use them still
16 run. The F<.pl> files will all eventually be converted into standard
17 modules, and the F<.ph> files made by B<h2ph> will probably end up
18 as extension modules made by B<h2xs>. (Some F<.ph> values may
19 already be available through the POSIX, Errno, or Fcntl modules.)
20 The B<pl2pm> file in the distribution may help in your conversion,
21 but it's just a mechanical process and therefore far from bulletproof.
23 =head2 Pragmatic Modules
25 They work somewhat like compiler directives (pragmata) in that they
26 tend to affect the compilation of your program, and thus will usually
27 work well only when used within a C<use>, or C<no>. Most of these
28 are lexically scoped, so an inner BLOCK may countermand them
34 which lasts until the end of that BLOCK.
36 Some pragmas are lexically scoped--typically those that affect the
37 C<$^H> hints variable. Others affect the current package instead,
38 like C<use vars> and C<use subs>, whic allow you to predeclare a
39 variables or subroutines within a particular I<file> rather than
40 just a block. Such declarations are effective for the entire file
41 for which they were declared. You cannot rescind them with C<no
44 The following pragmas are defined (and have their own documentation).
50 set/get attributes of a subroutine
54 postpone load of modules until a function is used
58 Establish IS-A relationship with base class at compile time
62 Use MakeMaker's uninstalled version of a package
70 Perl compiler pragma to force verbose warning diagnostics
74 compile-time class fields
78 control the filetest permission operators
82 compute arithmetic in integer instead of double
86 perl pragma to request less of something from the compiler
90 manipulate @INC at compile time
94 use and avoid POSIX locales for built-in operations
98 restrict unsafe operations when compiling
102 Package for overloading perl operations
106 alter regular expression behavior
110 enable simple signal handling
114 restrict unsafe constructs
122 turn on UTF-8 and Unicode support
126 predeclare global variable names
130 control VMS-specific language features
134 control optional warnings
138 =head2 Standard Modules
140 Standard, bundled modules are all expected to behave in a well-defined
141 manner with respect to namespace pollution because they use the
142 Exporter module. See their own documentation for details.
148 provide framework for multiple DBMs
152 load subroutines only on demand
156 split a package for autoloading
160 The Perl Compiler; See also L<perlcc>.
164 Autogenerated data about Perl ops, used to generate bytecode
168 Assemble Perl bytecode
176 Perl compiler's bytecode backend
180 Perl compiler's C backend
184 Perl compiler's optimized C translation backend
188 Walk Perl syntax tree, printing debug info about ops
192 Perl compiler backend to produce perl code
194 =item B::Disassembler
196 Disassemble Perl bytecode
204 Show lexical variables used in functions or files
208 Helper module for CC backend
212 Walk Perl syntax tree, printing terse info about ops
216 Generates cross reference reports for Perl programs
220 benchmark running times of code
224 Simple Common Gateway Interface Class
228 Make things work with CGI.pm against Perl-Apache API
232 CGI routines for writing to the HTTPD (or other) error log
236 Interface to Netscape Cookies
240 CGI Interface for Fast CGI
244 Simple Interface to Server Push
248 Try more than one constructors and return the first object available
252 query, download and build perl modules from CPAN sites
254 =item CPAN::FirstTime
256 Utility for CPAN::Config file Initialization
260 Wrapper around CPAN.pm without using any XS module
264 warn of errors (from perspective of caller)
268 declare struct-like datatypes as Perl classes
272 access Perl configuration information
276 get pathname of current working directory
280 programmatic interface to the Perl debugging API
284 Perl5 access to Berkeley DB version 1.x
288 stringified perl data structures, suitable for both printing and C<eval>
292 A data debugging tool for the XS programmer
294 =item Devel::SelfStubber
296 generate stubs for a SelfLoading module
300 supply object methods for directory handles
304 provides screen dump of Perl data.
308 Dynamically load C libraries into Perl code
312 use nice English (or awk) names for ugly punctuation variables
316 perl module that imports environment variables
320 System errno constants
324 Implements default import method for modules
326 =item ExtUtils::Command
328 utilities to replace common UNIX commands in Makefiles etc.
330 =item ExtUtils::Embed
332 Utilities for embedding Perl in C/C++ applications
334 =item ExtUtils::Install
336 install files from here to there
338 =item ExtUtils::Installed
340 Inventory management of installed modules
342 =item ExtUtils::Liblist
344 determine libraries to use and how to use them
346 =item ExtUtils::MM_OS2
348 methods to override UN*X behavior in ExtUtils::MakeMaker
350 =item ExtUtils::MM_Unix
352 methods used by ExtUtils::MakeMaker
354 =item ExtUtils::MM_VMS
356 methods to override UN*X behavior in ExtUtils::MakeMaker
358 =item ExtUtils::MM_Win32
360 methods to override UN*X behavior in ExtUtils::MakeMaker
362 =item ExtUtils::MakeMaker
364 create an extension Makefile
366 =item ExtUtils::Manifest
368 utilities to write and check a MANIFEST file
370 =item ExtUtils::Miniperl
372 write the C code for perlmain.c
374 =item ExtUtils::Mkbootstrap
376 make a bootstrap file for use by DynaLoader
378 =item ExtUtils::Mksymlists
380 write linker options files for dynamic extension
382 =item ExtUtils::Packlist
384 manage .packlist files
386 =item ExtUtils::testlib
388 add blib/* directories to @INC
392 replace functions with equivalents which succeed or die
396 load the C Fcntl.h defines
400 split a pathname into pieces
404 Compare files or filehandles
408 Copy files or filehandles
412 DOS like globbing and then some
420 create or remove a series of directories
424 portably perform operations on file names
426 =item File::Spec::Functions
428 portably perform operations on file names
430 =item File::Spec::Mac
434 =item File::Spec::OS2
436 methods for OS/2 file specs
438 =item File::Spec::Unix
440 methods used by File::Spec
442 =item File::Spec::VMS
444 methods for VMS file specs
446 =item File::Spec::Win32
448 methods for Win32 file specs
452 by-name interface to Perl's built-in stat() functions
456 keep more files open than the system permits
460 supply object methods for filehandles
464 Locate directory of original perl script
468 Perl5 access to the gdbm library.
472 extended processing of command line options
476 Process single-character switches with switch clustering
480 compare 8-bit scalar data according to the current locale
484 load various IO modules
488 supply object methods for directory handles
492 supply object methods for filehandles
496 supply object methods for I/O handles
500 supply object methods for pipes
504 Object interface to system poll call
508 supply seek based methods for I/O objects
512 OO interface to the select system call
516 Object interface to socket communications
518 =item IO::Socket::INET
520 Object interface for AF_INET domain sockets
522 =item IO::Socket::UNIX
524 Object interface for AF_UNIX domain sockets
528 SysV Msg IPC object class
532 open a process for both reading and writing
536 open a process for reading, writing, and error handling
540 SysV Semaphore IPC object class
548 Arbitrary length float math package
552 Arbitrary size integer math package
556 complex numbers and associated mathematical functions
560 trigonometric functions
564 Tied access to ndbm files
568 check a remote host for reachability
572 by-name interface to Perl's built-in gethost*() functions
576 by-name interface to Perl's built-in getnet*() functions
580 by-name interface to Perl's built-in getproto*() functions
584 by-name interface to Perl's built-in getserv*() functions
588 Generic interface to Perl Compiler backends
592 Disable named opcodes when compiling perl code
596 Perl interface to IEEE Std 1003.1
600 module to convert pod files to HTML
604 convert POD data to formatted ASCII text
608 Tied access to sdbm files
612 Compile and execute code in restricted compartments
616 search for key in dictionary file
620 save and restore selected file handle
624 load functions only on demand
628 run shell commands transparently within perl
632 load the C socket.h defines and structure manipulators
636 manipulate Perl symbols and their names
640 Try every conceivable way to get hostname
644 Perl interface to the UNIX syslog(3) calls
648 Perl termcap interface
652 Perl word completion module
656 Perl interface to various C<readline> packages.
660 provides a simple framework for writing test scripts
664 run perl standard test scripts with statistics
668 create an abbreviation table from a list
670 =item Text::ParseWords
672 parse text into an array of tokens or array of arrays
676 Implementation of the Soundex Algorithm as Described by Knuth
678 =item Text::Tabs -- expand and unexpand tabs per the unix expand(1) and unexpand(1)
682 line wrapping to form simple paragraphs
692 =item Thread::Semaphore
694 thread-safe semaphores
698 Start a thread which runs signal handlers reliably
700 =item Thread::Specific
706 base class for tied arrays
710 base class definitions for tied handles
712 =item Tie::Hash, Tie::StdHash
714 base class definitions for tied hashes
718 use references as hash keys
720 =item Tie::Scalar, Tie::StdScalar
722 base class definitions for tied scalars
724 =item Tie::SubstrHash
726 Fixed-table-size, fixed-key-length hashing
730 efficiently compute time from local and GMT time
734 by-name interface to Perl's built-in gmtime() function
736 =item Time::localtime
738 by-name interface to Perl's built-in localtime() function
742 internal object used by Time::gmtime and Time::localtime
746 base class for ALL classes (blessed references)
750 by-name interface to Perl's built-in getgr*() functions
754 by-name interface to Perl's built-in getpw*() functions
758 To find out I<all> modules installed on your system, including
759 those without documentation or outside the standard release,
762 % find `perl -e 'print "@INC"'` -name '*.pm' -print
764 They should all have their own documentation installed and accessible
765 via your system man(1) command. If you do not have a B<find>
766 program, you can use the Perl B<find2perl> program instead, which
767 generates Perl code as output you can run through perl. If you
768 have a B<man> program but it doesn't find your modules, you'll have
769 to fix your manpath. See L<perl> for details. If you have no
770 system B<man> command, you might try the B<perldoc> program.
772 =head2 Extension Modules
774 Extension modules are written in C (or a mix of Perl and C). They
775 are usually dynamically loaded into Perl if and when you need them,
776 but may also be be linked in statically. Supported extension modules
777 include Socket, Fcntl, and POSIX.
779 Many popular C extension modules do not come bundled (at least, not
780 completely) due to their sizes, volatility, or simply lack of time
781 for adequate testing and configuration across the multitude of
782 platforms on which Perl was beta-tested. You are encouraged to
783 look for them on CPAN (described below), or using web search engines
784 like Alta Vista or Deja News.
788 CPAN stands for Comprehensive Perl Archive Network; it's a globally
789 replicated trove of Perl materials, including documentation, style
790 guides, tricks and trap, alternate ports to non-Unix systems and
791 occasional binary distributions for these. Search engines for
792 CPAN can be found at http://cpan.perl.com/ and at
793 http://theory.uwinnipeg.ca/mod_perl/cpan-search.pl .
795 Most importantly, CPAN includes around a thousand unbundled modules,
796 some of which require a C compiler to build. Major categories of
802 Language Extensions and Documentation Tools
808 Operating System Interfaces
811 Networking, Device Control (modems) and InterProcess Communication
814 Data Types and Data Type Utilities
823 Interfaces to / Emulations of Other Programming Languages
826 File Names, File Systems and File Locking (see also File Handles)
829 String Processing, Language Text Processing, Parsing, and Searching
832 Option, Argument, Parameter, and Configuration File Processing
835 Internationalization and Locale
838 Authentication, Security, and Encryption
841 World Wide Web, HTML, HTTP, CGI, MIME
844 Server and Daemon Utilities
847 Archiving and Compression
850 Images, Pixmap and Bitmap Manipulation, Drawing, and Graphing
856 Control Flow Utilities (callbacks and exceptions etc)
859 File Handle and Input/Output Stream Utilities
862 Miscellaneous Modules
866 Registered CPAN sites as of this writing include the following.
867 You should try to choose one close to you:
873 South Africa ftp://ftp.is.co.za/programming/perl/CPAN/
874 ftp://ftpza.co.za/pub/mirrors/cpan/
878 China ftp://freesoft.cei.gov.cn/pub/languages/perl/CPAN/
879 Hong Kong ftp://ftp.hkstar.com/pub/CPAN/
880 Israel ftp://bioinfo.weizmann.ac.il/pub/software/perl/CPAN/
881 Japan ftp://ftp.dti.ad.jp/pub/lang/CPAN/
882 ftp://ftp.jaist.ac.jp/pub/lang/perl/CPAN/
883 ftp://ftp.lab.kdd.co.jp/lang/perl/CPAN/
884 ftp://ftp.meisei-u.ac.jp/pub/CPAN/
885 ftp://ftp.ring.gr.jp/pub/lang/perl/CPAN/
886 ftp://mirror.nucba.ac.jp/mirror/Perl/
887 Singapore ftp://ftp.nus.edu.sg/pub/unix/perl/CPAN/
888 South Korea ftp://ftp.bora.net/pub/CPAN/
889 ftp://ftp.nuri.net/pub/CPAN/
890 Taiwan ftp://ftp.wownet.net/pub2/PERL/
891 ftp://ftp1.sinica.edu.tw/pub1/perl/CPAN/
892 Thailand ftp://ftp.cs.riubon.ac.th/pub/mirrors/CPAN/
893 ftp://ftp.nectec.or.th/pub/mirrors/CPAN/
897 Australia ftp://cpan.topend.com.au/pub/CPAN/
898 ftp://ftp.labyrinth.net.au/pub/perl/CPAN/
899 ftp://ftp.sage-au.org.au/pub/compilers/perl/CPAN/
900 ftp://mirror.aarnet.edu.au/pub/perl/CPAN/
901 New Zealand ftp://ftp.auckland.ac.nz/pub/perl/CPAN/
902 ftp://sunsite.net.nz/pub/languages/perl/CPAN/
906 Costa Rica ftp://ftp.ucr.ac.cr/pub/Unix/CPAN/
910 Austria ftp://ftp.tuwien.ac.at/pub/languages/perl/CPAN/
911 Belgium ftp://ftp.kulnet.kuleuven.ac.be/pub/mirror/CPAN/
912 Bulgaria ftp://ftp.ntrl.net/pub/mirrors/CPAN/
913 Croatia ftp://ftp.linux.hr/pub/CPAN/
914 Czech Republic ftp://ftp.fi.muni.cz/pub/perl/
915 ftp://sunsite.mff.cuni.cz/Languages/Perl/CPAN/
916 Denmark ftp://sunsite.auc.dk/pub/languages/perl/CPAN/
917 Estonia ftp://ftp.ut.ee/pub/languages/perl/CPAN/
918 Finland ftp://ftp.funet.fi/pub/languages/perl/CPAN/
919 France ftp://ftp.lip6.fr/pub/perl/CPAN/
920 ftp://ftp.oleane.net/pub/mirrors/CPAN/
921 ftp://ftp.pasteur.fr/pub/computing/CPAN/
922 Germany ftp://ftp.archive.de.uu.net/pub/CPAN/
923 ftp://ftp.gmd.de/packages/CPAN/
924 ftp://ftp.gwdg.de/pub/languages/perl/CPAN/
925 ftp://ftp.leo.org/pub/comp/programming/languages/script/perl/CPAN/
926 ftp://ftp.mpi-sb.mpg.de/pub/perl/CPAN/
927 ftp://ftp.rz.ruhr-uni-bochum.de/pub/CPAN/
928 ftp://ftp.uni-erlangen.de/pub/source/CPAN/
929 ftp://ftp.uni-hamburg.de/pub/soft/lang/perl/CPAN/
930 Greece ftp://ftp.ntua.gr/pub/lang/perl/
931 Hungary ftp://ftp.kfki.hu/pub/packages/perl/CPAN/
932 Ireland ftp://sunsite.compapp.dcu.ie/pub/perl/
933 Italy ftp://cis.uniRoma2.it/CPAN/
934 ftp://ftp.flashnet.it/pub/CPAN/
935 ftp://ftp.unina.it/pub/Other/CPAN/
936 ftp://ftp.unipi.it/pub/mirror/perl/CPAN/
937 Netherlands ftp://ftp.cs.uu.nl/mirror/CPAN/
938 ftp://ftp.EU.net/packages/cpan/
939 ftp://ftp.nluug.nl/pub/languages/perl/CPAN/
940 Norway ftp://ftp.uit.no/pub/languages/perl/cpan/
941 ftp://sunsite.uio.no/pub/languages/perl/CPAN/
942 Poland ftp://ftp.man.szczecin.pl/pub/perl/CPAN/
943 ftp://ftp.man.torun.pl/pub/doc/CPAN/
944 ftp://ftp.pk.edu.pl/pub/lang/perl/CPAN/
945 ftp://sunsite.icm.edu.pl/pub/CPAN/
946 Portugal ftp://ftp.ci.uminho.pt/pub/mirrors/cpan/
947 ftp://ftp.ist.utl.pt/pub/CPAN/
948 ftp://ftp.ua.pt/pub/CPAN/
949 Romania ftp://ftp.dntis.ro/pub/mirrors/perl-cpan/
950 ftp://ftp.dnttm.ro/pub/CPAN/
951 Russia ftp://ftp.chg.ru/pub/lang/perl/CPAN/
952 ftp://ftp.sai.msu.su/pub/lang/perl/CPAN/
953 Slovakia ftp://ftp.entry.sk/pub/languages/perl/CPAN/
954 Slovenia ftp://ftp.arnes.si/software/perl/CPAN/
955 Spain ftp://ftp.etse.urv.es/pub/perl/
956 ftp://ftp.rediris.es/mirror/CPAN/
957 Sweden ftp://ftp.sunet.se/pub/lang/perl/CPAN/
958 Switzerland ftp://sunsite.cnlab-switch.ch/mirror/CPAN/
959 Turkey ftp://sunsite.bilkent.edu.tr/pub/languages/CPAN/
960 United Kingdom ftp://ftp.demon.co.uk/pub/mirrors/perl/CPAN/
961 ftp://ftp.flirble.org/pub/languages/perl/CPAN/
962 ftp://ftp.plig.org/pub/CPAN/
963 ftp://sunsite.doc.ic.ac.uk/packages/CPAN/
964 ftp://unix.hensa.ac.uk/mirrors/perl-CPAN/
968 Alberta ftp://sunsite.ualberta.ca/pub/Mirror/CPAN/
969 California ftp://cpan.nas.nasa.gov/pub/perl/CPAN/
970 ftp://ftp.cdrom.com/pub/perl/CPAN/
971 ftp://ftp.digital.com/pub/plan/perl/CPAN/
972 Colorado ftp://ftp.cs.colorado.edu/pub/perl/CPAN/
973 Florida ftp://ftp.cise.ufl.edu/pub/perl/CPAN/
974 Illinois ftp://uiarchive.uiuc.edu/pub/lang/perl/CPAN/
975 Indiana ftp://csociety-ftp.ecn.purdue.edu/pub/CPAN/
976 ftp://ftp.uwsg.indiana.edu/pub/perl/CPAN/
977 Manitoba ftp://theory.uwinnipeg.ca/pub/CPAN/
978 Massachusetts ftp://ftp.ccs.neu.edu/net/mirrors/ftp.funet.fi/pub/languages/perl/CPAN/
979 ftp://ftp.iguide.com/pub/mirrors/packages/perl/CPAN/
980 Mexico ftp://ftp.msg.com.mx/pub/CPAN/
981 Minnesota ftp://ftp.midearthbbs.com/CPAN/
982 New York ftp://ftp.rge.com/pub/languages/perl/
983 North Carolina ftp://ftp.duke.edu/pub/perl/
984 Oklahoma ftp://ftp.ou.edu/mirrors/CPAN/
985 Ontario ftp://ftp.crc.ca/pub/packages/lang/perl/CPAN/
986 Oregon ftp://ftp.orst.edu/pub/packages/CPAN/
987 Pennsylvania ftp://ftp.epix.net/pub/languages/perl/
988 Texas ftp://ftp.sedl.org/pub/mirrors/CPAN/
989 Utah ftp://mirror.xmission.com/CPAN/
990 Virginia ftp://ftp.perl.org/pub/perl/CPAN/
991 ftp://ruff.cs.jmu.edu/pub/CPAN/
992 Washington ftp://ftp-mirror.internap.com/pub/CPAN/
993 ftp://ftp.spu.edu/pub/CPAN/
997 Brazil ftp://cpan.if.usp.br/pub/mirror/CPAN/
998 Chile ftp://sunsite.dcc.uchile.cl/pub/Lang/perl/CPAN/
1002 For an up-to-date listing of CPAN sites,
1003 see http://www.perl.com/perl/CPAN or ftp://www.perl.com/perl/ .
1005 =head1 Modules: Creation, Use, and Abuse
1007 (The following section is borrowed directly from Tim Bunce's modules
1008 file, available at your nearest CPAN site.)
1010 Perl implements a class using a package, but the presence of a
1011 package doesn't imply the presence of a class. A package is just a
1012 namespace. A class is a package that provides subroutines that can be
1013 used as methods. A method is just a subroutine that expects, as its
1014 first argument, either the name of a package (for "static" methods),
1015 or a reference to something (for "virtual" methods).
1017 A module is a file that (by convention) provides a class of the same
1018 name (sans the .pm), plus an import method in that class that can be
1019 called to fetch exported symbols. This module may implement some of
1020 its methods by loading dynamic C or C++ objects, but that should be
1021 totally transparent to the user of the module. Likewise, the module
1022 might set up an AUTOLOAD function to slurp in subroutine definitions on
1023 demand, but this is also transparent. Only the F<.pm> file is required to
1024 exist. See L<perlsub>, L<perltoot>, and L<AutoLoader> for details about
1025 the AUTOLOAD mechanism.
1027 =head2 Guidelines for Module Creation
1031 =item Do similar modules already exist in some form?
1033 If so, please try to reuse the existing modules either in whole or
1034 by inheriting useful features into a new class. If this is not
1035 practical try to get together with the module authors to work on
1036 extending or enhancing the functionality of the existing modules.
1037 A perfect example is the plethora of packages in perl4 for dealing
1038 with command line options.
1040 If you are writing a module to expand an already existing set of
1041 modules, please coordinate with the author of the package. It
1042 helps if you follow the same naming scheme and module interaction
1043 scheme as the original author.
1045 =item Try to design the new module to be easy to extend and reuse.
1049 Use blessed references. Use the two argument form of bless to bless
1050 into the class name given as the first parameter of the constructor,
1055 return bless {}, $class;
1058 or even this if you'd like it to be used as either a static
1059 or a virtual method.
1063 my $class = ref($self) || $self;
1064 return bless {}, $class;
1067 Pass arrays as references so more parameters can be added later
1068 (it's also faster). Convert functions into methods where
1069 appropriate. Split large methods into smaller more flexible ones.
1070 Inherit methods from other modules if appropriate.
1072 Avoid class name tests like: C<die "Invalid" unless ref $ref eq 'FOO'>.
1073 Generally you can delete the C<eq 'FOO'> part with no harm at all.
1074 Let the objects look after themselves! Generally, avoid hard-wired
1075 class names as far as possible.
1077 Avoid C<$r-E<gt>Class::func()> where using C<@ISA=qw(... Class ...)> and
1078 C<$r-E<gt>func()> would work (see L<perlbot> for more details).
1080 Use autosplit so little used or newly added functions won't be a
1081 burden to programs that don't use them. Add test functions to
1082 the module after __END__ either using AutoSplit or by saying:
1084 eval join('',<main::DATA>) || die $@ unless caller();
1086 Does your module pass the 'empty subclass' test? If you say
1087 C<@SUBCLASS::ISA = qw(YOURCLASS);> your applications should be able
1088 to use SUBCLASS in exactly the same way as YOURCLASS. For example,
1089 does your application still work if you change: C<$obj = new YOURCLASS;>
1090 into: C<$obj = new SUBCLASS;> ?
1092 Avoid keeping any state information in your packages. It makes it
1093 difficult for multiple other packages to use yours. Keep state
1094 information in objects.
1098 Try to C<use strict;> (or C<use strict qw(...);>).
1099 Remember that you can add C<no strict qw(...);> to individual blocks
1100 of code that need less strictness.
1104 Follow the guidelines in the perlstyle(1) manual.
1108 =item Some simple style guidelines
1110 The perlstyle manual supplied with Perl has many helpful points.
1112 Coding style is a matter of personal taste. Many people evolve their
1113 style over several years as they learn what helps them write and
1114 maintain good code. Here's one set of assorted suggestions that
1115 seem to be widely used by experienced developers:
1117 Use underscores to separate words. It is generally easier to read
1118 $var_names_like_this than $VarNamesLikeThis, especially for
1119 non-native speakers of English. It's also a simple rule that works
1120 consistently with VAR_NAMES_LIKE_THIS.
1122 Package/Module names are an exception to this rule. Perl informally
1123 reserves lowercase module names for 'pragma' modules like integer
1124 and strict. Other modules normally begin with a capital letter and
1125 use mixed case with no underscores (need to be short and portable).
1127 You may find it helpful to use letter case to indicate the scope
1128 or nature of a variable. For example:
1130 $ALL_CAPS_HERE constants only (beware clashes with Perl vars)
1131 $Some_Caps_Here package-wide global/static
1132 $no_caps_here function scope my() or local() variables
1134 Function and method names seem to work best as all lowercase.
1135 e.g., C<$obj-E<gt>as_string()>.
1137 You can use a leading underscore to indicate that a variable or
1138 function should not be used outside the package that defined it.
1140 =item Select what to export.
1142 Do NOT export method names!
1144 Do NOT export anything else by default without a good reason!
1146 Exports pollute the namespace of the module user. If you must
1147 export try to use @EXPORT_OK in preference to @EXPORT and avoid
1148 short or common names to reduce the risk of name clashes.
1150 Generally anything not exported is still accessible from outside the
1151 module using the ModuleName::item_name (or C<$blessed_ref-E<gt>method>)
1152 syntax. By convention you can use a leading underscore on names to
1153 indicate informally that they are 'internal' and not for public use.
1155 (It is actually possible to get private functions by saying:
1156 C<my $subref = sub { ... }; &$subref;>. But there's no way to call that
1157 directly as a method, because a method must have a name in the symbol
1160 As a general rule, if the module is trying to be object oriented
1161 then export nothing. If it's just a collection of functions then
1162 @EXPORT_OK anything but use @EXPORT with caution.
1164 =item Select a name for the module.
1166 This name should be as descriptive, accurate, and complete as
1167 possible. Avoid any risk of ambiguity. Always try to use two or
1168 more whole words. Generally the name should reflect what is special
1169 about what the module does rather than how it does it. Please use
1170 nested module names to group informally or categorize a module.
1171 There should be a very good reason for a module not to have a nested name.
1172 Module names should begin with a capital letter.
1174 Having 57 modules all called Sort will not make life easy for anyone
1175 (though having 23 called Sort::Quick is only marginally better :-).
1176 Imagine someone trying to install your module alongside many others.
1177 If in any doubt ask for suggestions in comp.lang.perl.misc.
1179 If you are developing a suite of related modules/classes it's good
1180 practice to use nested classes with a common prefix as this will
1181 avoid namespace clashes. For example: Xyz::Control, Xyz::View,
1182 Xyz::Model etc. Use the modules in this list as a naming guide.
1184 If adding a new module to a set, follow the original author's
1185 standards for naming modules and the interface to methods in
1188 To be portable each component of a module name should be limited to
1189 11 characters. If it might be used on MS-DOS then try to ensure each is
1190 unique in the first 8 characters. Nested modules make this easier.
1192 =item Have you got it right?
1194 How do you know that you've made the right decisions? Have you
1195 picked an interface design that will cause problems later? Have
1196 you picked the most appropriate name? Do you have any questions?
1198 The best way to know for sure, and pick up many helpful suggestions,
1199 is to ask someone who knows. Comp.lang.perl.misc is read by just about
1200 all the people who develop modules and it's the best place to ask.
1202 All you need to do is post a short summary of the module, its
1203 purpose and interfaces. A few lines on each of the main methods is
1204 probably enough. (If you post the whole module it might be ignored
1205 by busy people - generally the very people you want to read it!)
1207 Don't worry about posting if you can't say when the module will be
1208 ready - just say so in the message. It might be worth inviting
1209 others to help you, they may be able to complete it for you!
1211 =item README and other Additional Files.
1213 It's well known that software developers usually fully document the
1214 software they write. If, however, the world is in urgent need of
1215 your software and there is not enough time to write the full
1216 documentation please at least provide a README file containing:
1221 A description of the module/package/extension etc.
1224 A copyright notice - see below.
1227 Prerequisites - what else you may need to have.
1230 How to build it - possible changes to Makefile.PL etc.
1236 Recent changes in this release, especially incompatibilities
1239 Changes / enhancements you plan to make in the future.
1243 If the README file seems to be getting too large you may wish to
1244 split out some of the sections into separate files: INSTALL,
1249 =item Adding a Copyright Notice.
1251 How you choose to license your work is a personal decision.
1252 The general mechanism is to assert your Copyright and then make
1253 a declaration of how others may copy/use/modify your work.
1255 Perl, for example, is supplied with two types of licence: The GNU
1256 GPL and The Artistic Licence (see the files README, Copying, and
1257 Artistic). Larry has good reasons for NOT just using the GNU GPL.
1259 My personal recommendation, out of respect for Larry, Perl, and the
1260 Perl community at large is to state something simply like:
1262 Copyright (c) 1995 Your Name. All rights reserved.
1263 This program is free software; you can redistribute it and/or
1264 modify it under the same terms as Perl itself.
1266 This statement should at least appear in the README file. You may
1267 also wish to include it in a Copying file and your source files.
1268 Remember to include the other words in addition to the Copyright.
1270 =item Give the module a version/issue/release number.
1272 To be fully compatible with the Exporter and MakeMaker modules you
1273 should store your module's version number in a non-my package
1274 variable called $VERSION. This should be a floating point
1275 number with at least two digits after the decimal (i.e., hundredths,
1276 e.g, C<$VERSION = "0.01">). Don't use a "1.3.2" style version.
1277 See L<Exporter> for details.
1279 It may be handy to add a function or method to retrieve the number.
1280 Use the number in announcements and archive file names when
1281 releasing the module (ModuleName-1.02.tar.Z).
1282 See perldoc ExtUtils::MakeMaker.pm for details.
1284 =item How to release and distribute a module.
1286 It's good idea to post an announcement of the availability of your
1287 module (or the module itself if small) to the comp.lang.perl.announce
1288 Usenet newsgroup. This will at least ensure very wide once-off
1291 If possible, register the module with CPAN. You should
1292 include details of its location in your announcement.
1294 Some notes about ftp archives: Please use a long descriptive file
1295 name that includes the version number. Most incoming directories
1296 will not be readable/listable, i.e., you won't be able to see your
1297 file after uploading it. Remember to send your email notification
1298 message as soon as possible after uploading else your file may get
1299 deleted automatically. Allow time for the file to be processed
1300 and/or check the file has been processed before announcing its
1303 FTP Archives for Perl Modules:
1305 Follow the instructions and links on
1307 http://franz.ww.tu-berlin.de/modulelist
1309 or upload to one of these sites:
1311 ftp://franz.ww.tu-berlin.de/incoming
1312 ftp://ftp.cis.ufl.edu/incoming
1314 and notify <F<upload@franz.ww.tu-berlin.de>>.
1316 By using the WWW interface you can ask the Upload Server to mirror
1317 your modules from your ftp or WWW site into your own directory on
1320 Please remember to send me an updated entry for the Module list!
1322 =item Take care when changing a released module.
1324 Always strive to remain compatible with previous released versions.
1325 Otherwise try to add a mechanism to revert to the
1326 old behavior if people rely on it. Document incompatible changes.
1332 =head2 Guidelines for Converting Perl 4 Library Scripts into Modules
1336 =item There is no requirement to convert anything.
1338 If it ain't broke, don't fix it! Perl 4 library scripts should
1339 continue to work with no problems. You may need to make some minor
1340 changes (like escaping non-array @'s in double quoted strings) but
1341 there is no need to convert a .pl file into a Module for just that.
1343 =item Consider the implications.
1345 All Perl applications that make use of the script will need to
1346 be changed (slightly) if the script is converted into a module. Is
1347 it worth it unless you plan to make other changes at the same time?
1349 =item Make the most of the opportunity.
1351 If you are going to convert the script to a module you can use the
1352 opportunity to redesign the interface. The guidelines for module
1353 creation above include many of the issues you should consider.
1355 =item The pl2pm utility will get you started.
1357 This utility will read *.pl files (given as parameters) and write
1358 corresponding *.pm files. The pl2pm utilities does the following:
1363 Adds the standard Module prologue lines
1366 Converts package specifiers from ' to ::
1369 Converts die(...) to croak(...)
1372 Several other minor changes
1376 Being a mechanical process pl2pm is not bullet proof. The converted
1377 code will need careful checking, especially any package statements.
1378 Don't delete the original .pl file till the new .pm one works!
1382 =head2 Guidelines for Reusing Application Code
1386 =item Complete applications rarely belong in the Perl Module Library.
1388 =item Many applications contain some Perl code that could be reused.
1390 Help save the world! Share your code in a form that makes it easy
1393 =item Break-out the reusable code into one or more separate module files.
1395 =item Take the opportunity to reconsider and redesign the interfaces.
1397 =item In some cases the 'application' can then be reduced to a small
1399 fragment of code built on top of the reusable modules. In these cases
1400 the application could invoked as:
1402 % perl -e 'use Module::Name; method(@ARGV)' ...
1404 % perl -mModule::Name ... (in perl5.002 or higher)
1410 Perl does not enforce private and public parts of its modules as you may
1411 have been used to in other languages like C++, Ada, or Modula-17. Perl
1412 doesn't have an infatuation with enforced privacy. It would prefer
1413 that you stayed out of its living room because you weren't invited, not
1414 because it has a shotgun.
1416 The module and its user have a contract, part of which is common law,
1417 and part of which is "written". Part of the common law contract is
1418 that a module doesn't pollute any namespace it wasn't asked to. The
1419 written contract for the module (A.K.A. documentation) may make other
1420 provisions. But then you know when you C<use RedefineTheWorld> that
1421 you're redefining the world and willing to take the consequences.