3 perlmod - Perl modules (packages)
9 Perl provides a mechanism for alternative namespaces to protect packages
10 from stomping on each other's variables. In fact, apart from certain
11 magical variables, there's really no such thing as a global variable in
12 Perl. The package statement declares the compilation unit as being in the
13 given namespace. The scope of the package declaration is from the
14 declaration itself through the end of the enclosing block (the same scope
15 as the local() operator). All further unqualified dynamic identifiers
16 will be in this namespace. A package statement only affects dynamic
17 variables--including those you've used local() on--but I<not> lexical
18 variables created with my(). Typically it would be the first declaration
19 in a file to be included by the C<require> or C<use> operator. You can
20 switch into a package in more than one place; it merely influences which
21 symbol table is used by the compiler for the rest of that block. You can
22 refer to variables and filehandles in other packages by prefixing the
23 identifier with the package name and a double colon:
24 C<$Package::Variable>. If the package name is null, the C<main> package
25 is assumed. That is, C<$::sail> is equivalent to C<$main::sail>.
27 (The old package delimiter was a single quote, but double colon
28 is now the preferred delimiter, in part because it's more readable
29 to humans, and in part because it's more readable to B<emacs> macros.
30 It also makes C++ programmers feel like they know what's going on.)
32 Packages may be nested inside other packages: C<$OUTER::INNER::var>. This
33 implies nothing about the order of name lookups, however. All symbols
34 are either local to the current package, or must be fully qualified
35 from the outer package name down. For instance, there is nowhere
36 within package C<OUTER> that C<$INNER::var> refers to C<$OUTER::INNER::var>.
37 It would treat package C<INNER> as a totally separate global package.
39 Only identifiers starting with letters (or underscore) are stored in a
40 package's symbol table. All other symbols are kept in package C<main>,
41 including all of the punctuation variables like $_. In addition, the
42 identifiers STDIN, STDOUT, STDERR, ARGV, ARGVOUT, ENV, INC and SIG are
43 forced to be in package C<main>, even when used for other purposes than
44 their built-in one. Note also that, if you have a package called C<m>,
45 C<s> or C<y>, then you can't use the qualified form of an identifier
46 because it will be interpreted instead as a pattern match, a substitution,
49 (Variables beginning with underscore used to be forced into package
50 main, but we decided it was more useful for package writers to be able
51 to use leading underscore to indicate private variables and method names.
52 $_ is still global though.)
54 Eval()ed strings are compiled in the package in which the eval() was
55 compiled. (Assignments to C<$SIG{}>, however, assume the signal
56 handler specified is in the C<main> package. Qualify the signal handler
57 name if you wish to have a signal handler in a package.) For an
58 example, examine F<perldb.pl> in the Perl library. It initially switches
59 to the C<DB> package so that the debugger doesn't interfere with variables
60 in the script you are trying to debug. At various points, however, it
61 temporarily switches back to the C<main> package to evaluate various
62 expressions in the context of the C<main> package (or wherever you came
63 from). See L<perldebug>.
65 See L<perlsub> for other scoping issues related to my() and local(),
66 or L<perlref> regarding closures.
70 The symbol table for a package happens to be stored in the associative
71 array of that name appended with two colons. The main symbol table's
72 name is thus C<%main::>, or C<%::> for short. Likewise symbol table for
73 the nested package mentioned earlier is named C<%OUTER::INNER::>.
75 The value in each entry of the associative array is what you are referring
76 to when you use the C<*name> typeglob notation. In fact, the following
77 have the same effect, though the first is more efficient because it does
78 the symbol table lookups at compile time:
80 local(*main::foo) = *main::bar; local($main::{'foo'}) =
83 You can use this to print out all the variables in a package, for
84 instance. Here is F<dumpvar.pl> from the Perl library:
89 local(*stab) = eval("*${package}::");
90 while (($key,$val) = each(%stab)) {
93 print "\$$key = '$entry'\n";
98 foreach $num ($[ .. $#entry) {
99 print " $num\t'",$entry[$num],"'\n";
104 if ($key ne "${package}::" && defined %entry) {
105 print "\%$key = (\n";
106 foreach $key (sort keys(%entry)) {
107 print " $key\t'",$entry{$key},"'\n";
114 Note that even though the subroutine is compiled in package C<dumpvar>,
115 the name of the subroutine is qualified so that its name is inserted
116 into package C<main>.
118 Assignment to a typeglob performs an aliasing operation, i.e.,
122 causes variables, subroutines and file handles accessible via the
123 identifier C<richard> to also be accessible via the identifier C<dick>. If
124 you only want to alias a particular variable or subroutine, you can
125 assign a reference instead:
129 makes $richard and $dick the same variable, but leaves
130 @richard and @dick as separate arrays. Tricky, eh?
132 This mechanism may be used to pass and return cheap references
133 into or from subroutines if you won't want to copy the whole
137 *some_hash = fn( \%another_hash );
139 local *hashsym = shift;
140 # now use %hashsym normally, and you
141 # will affect the caller's %another_hash
142 my %nhash = (); # do what you want
146 On return, the reference wil overwrite the hash slot in the
147 symbol table specified by the *some_hash typeglob. This
148 is a somewhat tricky way of passing around references cheaply
149 when you won't want to have to remember to dereference variables
152 Another use of symbol tables is for making "constant" scalars.
154 *PI = \3.14159265358979;
156 Now you cannot alter $PI, which is probably a good thing all in all.
158 =head2 Package Constructors and Destructors
160 There are two special subroutine definitions that function as package
161 constructors and destructors. These are the C<BEGIN> and C<END>
162 routines. The C<sub> is optional for these routines.
164 A C<BEGIN> subroutine is executed as soon as possible, that is, the
165 moment it is completely defined, even before the rest of the containing
166 file is parsed. You may have multiple C<BEGIN> blocks within a
167 file--they will execute in order of definition. Because a C<BEGIN>
168 block executes immediately, it can pull in definitions of subroutines
169 and such from other files in time to be visible to the rest of the
172 An C<END> subroutine is executed as late as possible, that is, when the
173 interpreter is being exited, even if it is exiting as a result of a
174 die() function. (But not if it's is being blown out of the water by a
175 signal--you have to trap that yourself (if you can).) You may have
176 multiple C<END> blocks within a file--they will execute in reverse
177 order of definition; that is: last in, first out (LIFO).
179 Inside an C<END> subroutine C<$?> contains the value that the script is
180 going to pass to C<exit()>. You can modify C<$?> to change the exit
181 value of the script. Beware of changing C<$?> by accident (eg, by
182 running something via C<system>).
184 Note that when you use the B<-n> and B<-p> switches to Perl, C<BEGIN>
185 and C<END> work just as they do in B<awk>, as a degenerate case.
189 There is no special class syntax in Perl, but a package may function
190 as a class if it provides subroutines that function as methods. Such a
191 package may also derive some of its methods from another class package
192 by listing the other package name in its @ISA array.
194 For more on this, see L<perlobj>.
198 A module is just a package that is defined in a library file of
199 the same name, and is designed to be reusable. It may do this by
200 providing a mechanism for exporting some of its symbols into the symbol
201 table of any package using it. Or it may function as a class
202 definition and make its semantics available implicitly through method
203 calls on the class and its objects, without explicit exportation of any
204 symbols. Or it can do a little of both.
206 For example, to start a normal module called Fred, create
207 a file called Fred.pm and put this at the start of it:
212 @EXPORT = qw(func1 func2);
213 @EXPORT_OK = qw($sally @listabob %harry func3);
215 Then go on to declare and use your variables in functions
216 without any qualifications.
217 See L<Exporter> and the I<Perl Modules File> for details on
218 mechanics and style issues in module creation.
220 Perl modules are included into your program by saying
228 This is exactly equivalent to
230 BEGIN { require "Module.pm"; import Module; }
234 BEGIN { require "Module.pm"; import Module LIST; }
240 is exactly equivalent to
242 BEGIN { require "Module.pm"; }
244 All Perl module files have the extension F<.pm>. C<use> assumes this so
245 that you don't have to spell out "F<Module.pm>" in quotes. This also
246 helps to differentiate new modules from old F<.pl> and F<.ph> files.
247 Module names are also capitalized unless they're functioning as pragmas,
248 "Pragmas" are in effect compiler directives, and are sometimes called
249 "pragmatic modules" (or even "pragmata" if you're a classicist).
251 Because the C<use> statement implies a C<BEGIN> block, the importation
252 of semantics happens at the moment the C<use> statement is compiled,
253 before the rest of the file is compiled. This is how it is able
254 to function as a pragma mechanism, and also how modules are able to
255 declare subroutines that are then visible as list operators for
256 the rest of the current file. This will not work if you use C<require>
257 instead of C<use>. With require you can get into this problem:
259 require Cwd; # make Cwd:: accessible
260 $here = Cwd::getcwd();
262 use Cwd; # import names from Cwd::
265 require Cwd; # make Cwd:: accessible
266 $here = getcwd(); # oops! no main::getcwd()
268 In general C<use Module ();> is recommended over C<require Module;>.
270 Perl packages may be nested inside other package names, so we can have
271 package names containing C<::>. But if we used that package name
272 directly as a filename it would makes for unwieldy or impossible
273 filenames on some systems. Therefore, if a module's name is, say,
274 C<Text::Soundex>, then its definition is actually found in the library
275 file F<Text/Soundex.pm>.
277 Perl modules always have a F<.pm> file, but there may also be dynamically
278 linked executables or autoloaded subroutine definitions associated with
279 the module. If so, these will be entirely transparent to the user of
280 the module. It is the responsibility of the F<.pm> file to load (or
281 arrange to autoload) any additional functionality. The POSIX module
282 happens to do both dynamic loading and autoloading, but the user can
283 just say C<use POSIX> to get it all.
285 For more information on writing extension modules, see L<perlxs>
290 Perl does not enforce private and public parts of its modules as you may
291 have been used to in other languages like C++, Ada, or Modula-17. Perl
292 doesn't have an infatuation with enforced privacy. It would prefer
293 that you stayed out of its living room because you weren't invited, not
294 because it has a shotgun.
296 The module and its user have a contract, part of which is common law,
297 and part of which is "written". Part of the common law contract is
298 that a module doesn't pollute any namespace it wasn't asked to. The
299 written contract for the module (AKA documentation) may make other
300 provisions. But then you know when you C<use RedefineTheWorld> that
301 you're redefining the world and willing to take the consequences.
303 =head1 THE PERL MODULE LIBRARY
305 A number of modules are included the the Perl distribution. These are
306 described below, and all end in F<.pm>. You may also discover files in
307 the library directory that end in either F<.pl> or F<.ph>. These are old
308 libraries supplied so that old programs that use them still run. The
309 F<.pl> files will all eventually be converted into standard modules, and
310 the F<.ph> files made by B<h2ph> will probably end up as extension modules
311 made by B<h2xs>. (Some F<.ph> values may already be available through the
312 POSIX module.) The B<pl2pm> file in the distribution may help in your
313 conversion, but it's just a mechanical process, so is far from bulletproof.
315 =head2 Pragmatic Modules
317 They work somewhat like pragmas in that they tend to affect the compilation of
318 your program, and thus will usually only work well when used within a
319 C<use>, or C<no>. These are locally scoped, so an inner BLOCK
320 may countermand any of these by saying
325 which lasts until the end of that BLOCK.
327 The following programs are defined (and have their own documentation).
333 Pragma to produce enhanced diagnostics
337 Pragma to compute arithmetic in integer instead of double
341 Pragma to request less of something from the compiler
345 Pragma to restrict use of unsafe opcodes
349 Pragma for overloading operators
353 Pragma to enable stack backtrace on unexpected signals
357 Pragma to restrict unsafe constructs
361 Pragma to predeclare sub names
365 Pragma to predeclare global symbols
369 =head2 Standard Modules
371 Standard, bundled modules are all expected to behave in a well-defined
372 manner with respect to namespace pollution because they use the
373 Exporter module. See their own documentation for details.
379 provide framework for multiple DBMs
383 load functions only on demand
387 split a package for autoloading
391 benchmark running times of code
395 warn of errors (from perspective of caller)
399 access Perl configuration option
403 get pathname of current working directory
407 Perl access to Berkeley DB
409 =item Devel::SelfStubber
411 generate stubs for a SelfLoading module
415 Dynamically load C libraries into Perl code
419 use nice English (or B<awk>) names for ugly punctuation variables
423 perl module that imports environment variables
427 provide import/export controls for Perl modules
429 =item ExtUtils::Liblist
431 determine libraries to use and how to use them
433 =item ExtUtils::MakeMaker
435 create an extension Makefile
437 =item ExtUtils::Manifest
439 utilities to write and check a MANIFEST file
441 =item ExtUtils::Mkbootstrap
443 make a bootstrap file for use by DynaLoader
445 =item ExtUtils::Miniperl
451 load the C Fcntl.h defines
455 parse file specifications
457 =item File::CheckTree
459 run many filetest checks on a tree
467 supply object methods for filehandles
471 create or remove a series of directories
475 extended getopt processing
479 Process single-character switches with switch clustering
483 compare 8-bit scalar data according to the current locale
487 a process for both reading and writing
491 open a process for reading, writing, and error handling
495 check a host for upness
499 Perl interface to IEEE Std 1003.1
503 load functions only on demand
507 Creation controlled compartments in which perl code can be evaluated.
511 load the C socket.h defines and structure manipulators
515 run perl standard test scripts with statistics
519 create an abbreviation table from a list
523 To find out I<all> the modules installed on your system, including
524 those without documentation or outside the standard release, do this:
526 find `perl -e 'print "@INC"'` -name '*.pm' -print
528 They should all have their own documentation installed and accessible via
529 your system man(1) command. If that fails, try the I<perldoc> program.
531 =head2 Extension Modules
533 Extension modules are written in C (or a mix of Perl and C) and get
534 dynamically loaded into Perl if and when you need them. Supported
535 extension modules include the Socket, Fcntl, and POSIX modules.
537 Many popular C extension modules do not come bundled (at least, not
538 completely) due to their size, volatility, or simply lack of time for
539 adequate testing and configuration across the multitude of platforms on
540 which Perl was beta-tested. You are encouraged to look for them in
541 archie(1L), the Perl FAQ or Meta-FAQ, the WWW page, and even with their
542 authors before randomly posting asking for their present condition and
547 CPAN stands for the Comprehensive Perl Archive Network. This is a globally
548 replicated collection of all known Perl materials, including hundreds
549 of unbundled modules. Here are the major categories of modules:
554 Language Extensions and Documentation Tools
560 Operating System Interfaces
563 Networking, Device Control (modems) and InterProcess Communication
566 Data Types and Data Type Utilities
575 Interfaces to / Emulations of Other Programming Languages
578 File Names, File Systems and File Locking (see also File Handles)
581 String Processing, Language Text Processing, Parsing and Searching
584 Option, Argument, Parameter and Configuration File Processing
587 Internationalization and Locale
590 Authentication, Security and Encryption
593 World Wide Web, HTML, HTTP, CGI, MIME
596 Server and Daemon Utilities
599 Archiving and Compression
602 Images, Pixmap and Bitmap Manipulation, Drawing and Graphing
608 Control Flow Utilities (callbacks and exceptions etc)
611 File Handle and Input/Output Stream Utilities
614 Miscellaneous Modules
618 The registered CPAN sites as of this writing include the following.
619 You should try to choose one close to you:
624 ftp://ftp.sterling.com/programming/languages/perl/
627 ftp://ftp.sedl.org/pub/mirrors/CPAN/
630 ftp://ftp.uoknor.edu/mirrors/CPAN/
633 ftp://ftp.delphi.com/pub/mirrors/packages/perl/CPAN/
636 ftp://uiarchive.cso.uiuc.edu/pub/lang/perl/CPAN/
639 ftp://ftp.cis.ufl.edu/pub/perl/CPAN/
642 ftp://ftp.switch.ch/mirror/CPAN/
645 ftp://ftp.sunet.se/pub/lang/perl/CPAN/
648 ftp://ftp.ci.uminho.pt/pub/lang/perl/
651 ftp://ftp.cs.ruu.nl/pub/PERL/CPAN/
654 ftp://ftp.demon.co.uk/pub/mirrors/perl/CPAN/
657 ftp://ftp.rz.ruhr-uni-bochum.de/pub/programming/languages/perl/CPAN/
660 ftp://ftp.leo.org/pub/comp/programming/languages/perl/CPAN/
663 ftp://ftp.pasteur.fr/pub/computing/unix/perl/CPAN/
666 ftp://ftp.ibp.fr/pub/perl/CPAN/
669 ftp://ftp.funet.fi/pub/languages/perl/CPAN/
672 ftp://ftp.tekotago.ac.nz/pub/perl/CPAN/
675 ftp://ftp.mame.mu.oz.au/pub/perl/CPAN/
678 ftp://coombs.anu.edu.au/pub/perl/
681 ftp://dongpo.math.ncu.edu.tw/perl/CPAN/
684 ftp://ftp.lab.kdd.co.jp/lang/perl/CPAN/
687 ftp://ftp.is.co.za/programming/perl/CPAN/
691 For an up-to-date listing of CPAN sites,
692 see F<http://www.perl.com/perl/CPAN> or F<ftp://ftp.perl.com/perl/>.
694 =head1 Modules: Creation, Use and Abuse
696 (The following section is borrowed directly from Tim Bunce's modules
697 file, available at your nearest CPAN site.)
699 Perl 5 implements a class using a package, but the presence of a
700 package doesn't imply the presence of a class. A package is just a
701 namespace. A class is a package that provides subroutines that can be
702 used as methods. A method is just a subroutine that expects, as its
703 first argument, either the name of a package (for "static" methods),
704 or a reference to something (for "virtual" methods).
706 A module is a file that (by convention) provides a class of the same
707 name (sans the .pm), plus an import method in that class that can be
708 called to fetch exported symbols. This module may implement some of
709 its methods by loading dynamic C or C++ objects, but that should be
710 totally transparent to the user of the module. Likewise, the module
711 might set up an AUTOLOAD function to slurp in subroutine definitions on
712 demand, but this is also transparent. Only the .pm file is required to
715 =head2 Guidelines for Module Creation
719 =item Do similar modules already exist in some form?
721 If so, please try to reuse the existing modules either in whole or
722 by inheriting useful features into a new class. If this is not
723 practical try to get together with the module authors to work on
724 extending or enhancing the functionality of the existing modules.
725 A perfect example is the plethora of packages in perl4 for dealing
726 with command line options.
728 If you are writing a module to expand an already existing set of
729 modules, please coordinate with the author of the package. It
730 helps if you follow the same naming scheme and module interaction
731 scheme as the original author.
733 =item Try to design the new module to be easy to extend and reuse.
735 Use blessed references. Use the two argument form of bless to bless
736 into the class name given as the first parameter of the constructor,
741 return bless {}, $class;
744 or even this if you'd like it to be used as either a static
749 my $class = ref($self) || $self;
750 return bless {}, $class;
753 Pass arrays as references so more parameters can be added later
754 (it's also faster). Convert functions into methods where
755 appropriate. Split large methods into smaller more flexible ones.
756 Inherit methods from other modules if appropriate.
758 Avoid class name tests like: C<die "Invalid" unless ref $ref eq 'FOO'>.
759 Generally you can delete the "C<eq 'FOO'>" part with no harm at all.
760 Let the objects look after themselves! Generally, avoid hardwired
761 class names as far as possible.
763 Avoid C<$r-E<gt>Class::func()> where using C<@ISA=qw(... Class ...)> and
764 C<$r-E<gt>func()> would work (see L<perlbot> for more details).
766 Use autosplit so little used or newly added functions won't be a
767 burden to programs which don't use them. Add test functions to
768 the module after __END__ either using AutoSplit or by saying:
770 eval join('',<main::DATA>) || die $@ unless caller();
772 Does your module pass the 'empty sub-class' test? If you say
773 "C<@SUBCLASS::ISA = qw(YOURCLASS);>" your applications should be able
774 to use SUBCLASS in exactly the same way as YOURCLASS. For example,
775 does your application still work if you change: C<$obj = new YOURCLASS;>
776 into: C<$obj = new SUBCLASS;> ?
778 Avoid keeping any state information in your packages. It makes it
779 difficult for multiple other packages to use yours. Keep state
780 information in objects.
782 Always use B<-w>. Try to C<use strict;> (or C<use strict qw(...);>).
783 Remember that you can add C<no strict qw(...);> to individual blocks
784 of code which need less strictness. Always use B<-w>. Always use B<-w>!
785 Follow the guidelines in the perlstyle(1) manual.
787 =item Some simple style guidelines
789 The perlstyle manual supplied with perl has many helpful points.
791 Coding style is a matter of personal taste. Many people evolve their
792 style over several years as they learn what helps them write and
793 maintain good code. Here's one set of assorted suggestions that
794 seem to be widely used by experienced developers:
796 Use underscores to separate words. It is generally easier to read
797 $var_names_like_this than $VarNamesLikeThis, especially for
798 non-native speakers of English. It's also a simple rule that works
799 consistently with VAR_NAMES_LIKE_THIS.
801 Package/Module names are an exception to this rule. Perl informally
802 reserves lowercase module names for 'pragma' modules like integer
803 and strict. Other modules normally begin with a capital letter and
804 use mixed case with no underscores (need to be short and portable).
806 You may find it helpful to use letter case to indicate the scope
807 or nature of a variable. For example:
809 $ALL_CAPS_HERE constants only (beware clashes with perl vars)
810 $Some_Caps_Here package-wide global/static
811 $no_caps_here function scope my() or local() variables
813 Function and method names seem to work best as all lowercase.
814 E.g., C<$obj-E<gt>as_string()>.
816 You can use a leading underscore to indicate that a variable or
817 function should not be used outside the package that defined it.
819 =item Select what to export.
821 Do NOT export method names!
823 Do NOT export anything else by default without a good reason!
825 Exports pollute the namespace of the module user. If you must
826 export try to use @EXPORT_OK in preference to @EXPORT and avoid
827 short or common names to reduce the risk of name clashes.
829 Generally anything not exported is still accessible from outside the
830 module using the ModuleName::item_name (or C<$blessed_ref-E<gt>method>)
831 syntax. By convention you can use a leading underscore on names to
832 informally indicate that they are 'internal' and not for public use.
834 (It is actually possible to get private functions by saying:
835 C<my $subref = sub { ... }; &$subref;>. But there's no way to call that
836 directly as a method, since a method must have a name in the symbol
839 As a general rule, if the module is trying to be object oriented
840 then export nothing. If it's just a collection of functions then
841 @EXPORT_OK anything but use @EXPORT with caution.
843 =item Select a name for the module.
845 This name should be as descriptive, accurate and complete as
846 possible. Avoid any risk of ambiguity. Always try to use two or
847 more whole words. Generally the name should reflect what is special
848 about what the module does rather than how it does it. Please use
849 nested module names to informally group or categorise a module.
850 A module should have a very good reason not to have a nested name.
851 Module names should begin with a capital letter.
853 Having 57 modules all called Sort will not make life easy for anyone
854 (though having 23 called Sort::Quick is only marginally better :-).
855 Imagine someone trying to install your module alongside many others.
856 If in any doubt ask for suggestions in comp.lang.perl.misc.
858 If you are developing a suite of related modules/classes it's good
859 practice to use nested classes with a common prefix as this will
860 avoid namespace clashes. For example: Xyz::Control, Xyz::View,
861 Xyz::Model etc. Use the modules in this list as a naming guide.
863 If adding a new module to a set, follow the original author's
864 standards for naming modules and the interface to methods in
867 To be portable each component of a module name should be limited to
868 11 characters. If it might be used on DOS then try to ensure each is
869 unique in the first 8 characters. Nested modules make this easier.
871 =item Have you got it right?
873 How do you know that you've made the right decisions? Have you
874 picked an interface design that will cause problems later? Have
875 you picked the most appropriate name? Do you have any questions?
877 The best way to know for sure, and pick up many helpful suggestions,
878 is to ask someone who knows. Comp.lang.perl.misc is read by just about
879 all the people who develop modules and it's the best place to ask.
881 All you need to do is post a short summary of the module, its
882 purpose and interfaces. A few lines on each of the main methods is
883 probably enough. (If you post the whole module it might be ignored
884 by busy people - generally the very people you want to read it!)
886 Don't worry about posting if you can't say when the module will be
887 ready - just say so in the message. It might be worth inviting
888 others to help you, they may be able to complete it for you!
890 =item README and other Additional Files.
892 It's well known that software developers usually fully document the
893 software they write. If, however, the world is in urgent need of
894 your software and there is not enough time to write the full
895 documentation please at least provide a README file containing:
900 A description of the module/package/extension etc.
903 A copyright notice - see below.
906 Prerequisites - what else you may need to have.
909 How to build it - possible changes to Makefile.PL etc.
915 Recent changes in this release, especially incompatibilities
918 Changes / enhancements you plan to make in the future.
922 If the README file seems to be getting too large you may wish to
923 split out some of the sections into separate files: INSTALL,
928 =item Adding a Copyright Notice.
930 How you choose to license your work is a personal decision.
931 The general mechanism is to assert your Copyright and then make
932 a declaration of how others may copy/use/modify your work.
934 Perl, for example, is supplied with two types of license: The GNU
935 GPL and The Artistic License (see the files README, Copying and
936 Artistic). Larry has good reasons for NOT just using the GNU GPL.
938 My personal recommendation, out of respect for Larry, Perl and the
939 perl community at large is to simply state something like:
941 Copyright (c) 1995 Your Name. All rights reserved.
942 This program is free software; you can redistribute it and/or
943 modify it under the same terms as Perl itself.
945 This statement should at least appear in the README file. You may
946 also wish to include it in a Copying file and your source files.
947 Remember to include the other words in addition to the Copyright.
949 =item Give the module a version/issue/release number.
951 To be fully compatible with the Exporter and MakeMaker modules you
952 should store your module's version number in a non-my package
953 variable called $VERSION. This should be a valid floating point
954 number with at least two digits after the decimal (ie hundredths,
955 e.g, C<$VERSION = "0.01">). Don't use a "1.3.2" style version.
956 See Exporter.pm in Perl5.001m or later for details.
958 It may be handy to add a function or method to retrieve the number.
959 Use the number in announcements and archive file names when
960 releasing the module (ModuleName-1.02.tar.Z).
961 See perldoc ExtUtils::MakeMaker.pm for details.
963 =item How to release and distribute a module.
965 It's good idea to post an announcement of the availability of your
966 module (or the module itself if small) to the comp.lang.perl.announce
967 Usenet newsgroup. This will at least ensure very wide once-off
970 If possible you should place the module into a major ftp archive and
971 include details of it's location in your announcement.
973 Some notes about ftp archives: Please use a long descriptive file
974 name which includes the version number. Most incoming directories
975 will not be readable/listable, i.e., you won't be able to see your
976 file after uploading it. Remember to send your email notification
977 message as soon as possible after uploading else your file may get
978 deleted automatically. Allow time for the file to be processed
979 and/or check the file has been processed before announcing its
982 FTP Archives for Perl Modules:
984 Follow the instructions and links on
986 http://franz.ww.tu-berlin.de/modulelist
988 or upload to one of these sites:
990 ftp://franz.ww.tu-berlin.de/incoming
991 ftp://ftp.cis.ufl.edu/incoming
993 and notify upload@franz.ww.tu-berlin.de.
995 By using the WWW interface you can ask the Upload Server to mirror
996 your modules from your ftp or WWW site into your own directory on
999 Please remember to send me an updated entry for the Module list!
1001 =item Take care when changing a released module.
1003 Always strive to remain compatible with previous released versions
1004 (see 2.2 above) Otherwise try to add a mechanism to revert to the
1005 old behaviour if people rely on it. Document incompatible changes.
1011 =head2 Guidelines for Converting Perl 4 Library Scripts into Modules
1015 =item There is no requirement to convert anything.
1017 If it ain't broke, don't fix it! Perl 4 library scripts should
1018 continue to work with no problems. You may need to make some minor
1019 changes (like escaping non-array @'s in double quoted strings) but
1020 there is no need to convert a .pl file into a Module for just that.
1022 =item Consider the implications.
1024 All the perl applications which make use of the script will need to
1025 be changed (slightly) if the script is converted into a module. Is
1026 it worth it unless you plan to make other changes at the same time?
1028 =item Make the most of the opportunity.
1030 If you are going to convert the script to a module you can use the
1031 opportunity to redesign the interface. The 'Guidelines for Module
1032 Creation' above include many of the issues you should consider.
1034 =item The pl2pm utility will get you started.
1036 This utility will read *.pl files (given as parameters) and write
1037 corresponding *.pm files. The pl2pm utilities does the following:
1042 Adds the standard Module prologue lines
1045 Converts package specifiers from ' to ::
1048 Converts die(...) to croak(...)
1051 Several other minor changes
1055 Being a mechanical process pl2pm is not bullet proof. The converted
1056 code will need careful checking, especially any package statements.
1057 Don't delete the original .pl file till the new .pm one works!
1061 =head2 Guidelines for Reusing Application Code
1065 =item Complete applications rarely belong in the Perl Module Library.
1067 =item Many applications contain some perl code which could be reused.
1069 Help save the world! Share your code in a form that makes it easy
1072 =item Break-out the reusable code into one or more separate module files.
1074 =item Take the opportunity to reconsider and redesign the interfaces.
1076 =item In some cases the 'application' can then be reduced to a small
1078 fragment of code built on top of the reusable modules. In these cases
1079 the application could invoked as:
1081 perl -e 'use Module::Name; method(@ARGV)' ...
1083 perl -mModule::Name ... (in perl5.002)