This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Split perlmod
[perl5.git] / pod / perlmodlib.pod
CommitLineData
f102b883
TC
1=head1 NAME
2
3perlmodlib - constructing new Perl modules and finding existing ones
4
5=head1 DESCRIPTION
6
7=head1 THE PERL MODULE LIBRARY
8
9A number of modules are included the Perl distribution. These are
10described below, and all end in F<.pm>. You may also discover files in
11the library directory that end in either F<.pl> or F<.ph>. These are old
12libraries supplied so that old programs that use them still run. The
13F<.pl> files will all eventually be converted into standard modules, and
14the F<.ph> files made by B<h2ph> will probably end up as extension modules
15made by B<h2xs>. (Some F<.ph> values may already be available through the
16POSIX module.) The B<pl2pm> file in the distribution may help in your
17conversion, but it's just a mechanical process and therefore far from
18bulletproof.
19
20=head2 Pragmatic Modules
21
22They work somewhat like pragmas in that they tend to affect the compilation of
23your program, and thus will usually work well only when used within a
24C<use>, or C<no>. Most of these are locally scoped, so an inner BLOCK
25may countermand any of these by saying:
26
27 no integer;
28 no strict 'refs';
29
30which lasts until the end of that BLOCK.
31
32Unlike the pragmas that effect the C<$^H> hints variable, the C<use
33vars> and C<use subs> declarations are not BLOCK-scoped. They allow
34you to predeclare a variables or subroutines within a particular
35I<file> rather than just a block. Such declarations are effective
36for the entire file for which they were declared. You cannot rescind
37them with C<no vars> or C<no subs>.
38
39The following pragmas are defined (and have their own documentation).
40
41=over 12
42
43=item use autouse MODULE => qw(sub1 sub2 sub3)
44
45Defers C<require MODULE> until someone calls one of the specified
46subroutines (which must be exported by MODULE). This pragma should be
47used with caution, and only when necessary.
48
49=item blib
50
51manipulate @INC at compile time to use MakeMaker's uninstalled version
52of a package
53
54=item diagnostics
55
56force verbose warning diagnostics
57
58=item integer
59
60compute arithmetic in integer instead of double
61
62=item less
63
64request less of something from the compiler
65
66=item lib
67
68manipulate @INC at compile time
69
70=item locale
71
72use or ignore current locale for builtin operations (see L<perllocale>)
73
74=item ops
75
76restrict named opcodes when compiling or running Perl code
77
78=item overload
79
80overload basic Perl operations
81
82=item sigtrap
83
84enable simple signal handling
85
86=item strict
87
88restrict unsafe constructs
89
90=item subs
91
92predeclare sub names
93
94=item vmsish
95
96adopt certain VMS-specific behaviors
97
98=item vars
99
100predeclare global variable names
101
102=back
103
104=head2 Standard Modules
105
106Standard, bundled modules are all expected to behave in a well-defined
107manner with respect to namespace pollution because they use the
108Exporter module. See their own documentation for details.
109
110=over 12
111
112=item AnyDBM_File
113
114provide framework for multiple DBMs
115
116=item AutoLoader
117
118load functions only on demand
119
120=item AutoSplit
121
122split a package for autoloading
123
124=item Benchmark
125
126benchmark running times of code
127
128=item CPAN
129
130interface to Comprehensive Perl Archive Network
131
132=item CPAN::FirstTime
133
134create a CPAN configuration file
135
136=item CPAN::Nox
137
138run CPAN while avoiding compiled extensions
139
140=item Carp
141
142warn of errors (from perspective of caller)
143
144=item Class::Struct
145
146declare struct-like datatypes
147
148=item Config
149
150access Perl configuration information
151
152=item Cwd
153
154get pathname of current working directory
155
156=item DB_File
157
158access to Berkeley DB
159
160=item Devel::SelfStubber
161
162generate stubs for a SelfLoading module
163
164=item DirHandle
165
166supply object methods for directory handles
167
168=item DynaLoader
169
170dynamically load C libraries into Perl code
171
172=item English
173
174use nice English (or awk) names for ugly punctuation variables
175
176=item Env
177
178import environment variables
179
180=item Exporter
181
182implements default import method for modules
183
184=item ExtUtils::Embed
185
186utilities for embedding Perl in C/C++ applications
187
188=item ExtUtils::Install
189
190install files from here to there
191
192=item ExtUtils::Liblist
193
194determine libraries to use and how to use them
195
196=item ExtUtils::MM_OS2
197
198methods to override Unix behaviour in ExtUtils::MakeMaker
199
200=item ExtUtils::MM_Unix
201
202methods used by ExtUtils::MakeMaker
203
204=item ExtUtils::MM_VMS
205
206methods to override Unix behaviour in ExtUtils::MakeMaker
207
208=item ExtUtils::MakeMaker
209
210create an extension Makefile
211
212=item ExtUtils::Manifest
213
214utilities to write and check a MANIFEST file
215
216=item ExtUtils::Mkbootstrap
217
218make a bootstrap file for use by DynaLoader
219
220=item ExtUtils::Mksymlists
221
222write linker options files for dynamic extension
223
224=item ExtUtils::testlib
225
226add blib/* directories to @INC
227
228=item Fcntl
229
230load the C Fcntl.h defines
231
232=item File::Basename
233
234split a pathname into pieces
235
236=item File::CheckTree
237
238run many filetest checks on a tree
239
240=item File::Compare
241
242compare files or filehandles
243
244=item File::Copy
245
246copy files or filehandles
247
248=item File::Find
249
250traverse a file tree
251
252=item File::Path
253
254create or remove a series of directories
255
256=item File::stat
257
258by-name interface to Perl's builtin stat() functions
259
260=item FileCache
261
262keep more files open than the system permits
263
264=item FileHandle
265
266supply object methods for filehandles
267
268=item FindBin
269
270locate directory of original perl script
271
272=item GDBM_File
273
274access to the gdbm library
275
276=item Getopt::Long
277
278extended processing of command line options
279
280=item Getopt::Std
281
282process single-character switches with switch clustering
283
284=item I18N::Collate
285
286compare 8-bit scalar data according to the current locale
287
288=item IO
289
290load various IO modules
291
292=item IO::File
293
294supply object methods for filehandles
295
296=item IO::Handle
297
298supply object methods for I/O handles
299
300=item IO::Pipe
301
302supply object methods for pipes
303
304=item IO::Seekable
305
306supply seek based methods for I/O objects
307
308=item IO::Select
309
310OO interface to the select system call
311
312=item IO::Socket
313
314object interface to socket communications
315
316=item IPC::Open2
317
318open a process for both reading and writing
319
320=item IPC::Open3
321
322open a process for reading, writing, and error handling
323
324=item Math::BigFloat
325
326arbitrary length float math package
327
328=item Math::BigInt
329
330arbitrary size integer math package
331
332=item Math::Complex
333
334complex numbers and associated mathematical functions
335
336=item NDBM_File
337
338tied access to ndbm files
339
340=item Net::Ping
341
342Hello, anybody home?
343
344=item Net::hostent
345
346by-name interface to Perl's builtin gethost*() functions
347
348=item Net::netent
349
350by-name interface to Perl's builtin getnet*() functions
351
352=item Net::protoent
353
354by-name interface to Perl's builtin getproto*() functions
355
356=item Net::servent
357
358by-name interface to Perl's builtin getserv*() functions
359
360=item Opcode
361
362disable named opcodes when compiling or running perl code
363
364=item Pod::Text
365
366convert POD data to formatted ASCII text
367
368=item POSIX
369
370interface to IEEE Standard 1003.1
371
372=item SDBM_File
373
374tied access to sdbm files
375
376=item Safe
377
378compile and execute code in restricted compartments
379
380=item Search::Dict
381
382search for key in dictionary file
383
384=item SelectSaver
385
386save and restore selected file handle
387
388=item SelfLoader
389
390load functions only on demand
391
392=item Shell
393
394run shell commands transparently within perl
395
396=item Socket
397
398load the C socket.h defines and structure manipulators
399
400=item Symbol
401
402manipulate Perl symbols and their names
403
404=item Sys::Hostname
405
406try every conceivable way to get hostname
407
408=item Sys::Syslog
409
410interface to the Unix syslog(3) calls
411
412=item Term::Cap
413
414termcap interface
415
416=item Term::Complete
417
418word completion module
419
420=item Term::ReadLine
421
422interface to various C<readline> packages
423
424=item Test::Harness
425
426run perl standard test scripts with statistics
427
428=item Text::Abbrev
429
430create an abbreviation table from a list
431
432=item Text::ParseWords
433
434parse text into an array of tokens
435
436=item Text::Soundex
437
438implementation of the Soundex Algorithm as described by Knuth
439
440=item Text::Tabs
441
442expand and unexpand tabs per the Unix expand(1) and unexpand(1)
443
444=item Text::Wrap
445
446line wrapping to form simple paragraphs
447
448=item Tie::Hash
449
450base class definitions for tied hashes
451
452=item Tie::RefHash
453
454base class definitions for tied hashes with references as keys
455
456=item Tie::Scalar
457
458base class definitions for tied scalars
459
460=item Tie::SubstrHash
461
462fixed-table-size, fixed-key-length hashing
463
464=item Time::Local
465
466efficiently compute time from local and GMT time
467
468=item Time::gmtime
469
470by-name interface to Perl's builtin gmtime() function
471
472=item Time::localtime
473
474by-name interface to Perl's builtin localtime() function
475
476=item Time::tm
477
478internal object used by Time::gmtime and Time::localtime
479
480=item UNIVERSAL
481
482base class for ALL classes (blessed references)
483
484=item User::grent
485
486by-name interface to Perl's builtin getgr*() functions
487
488=item User::pwent
489
490by-name interface to Perl's builtin getpw*() functions
491
492=back
493
494To find out I<all> the modules installed on your system, including
495those without documentation or outside the standard release, do this:
496
497 find `perl -e 'print "@INC"'` -name '*.pm' -print
498
499They should all have their own documentation installed and accessible via
500your system man(1) command. If that fails, try the I<perldoc> program.
501
502=head2 Extension Modules
503
504Extension modules are written in C (or a mix of Perl and C) and may be
505statically linked or in general are
506dynamically loaded into Perl if and when you need them. Supported
507extension modules include the Socket, Fcntl, and POSIX modules.
508
509Many popular C extension modules do not come bundled (at least, not
510completely) due to their sizes, volatility, or simply lack of time for
511adequate testing and configuration across the multitude of platforms on
512which Perl was beta-tested. You are encouraged to look for them in
513archie(1L), the Perl FAQ or Meta-FAQ, the WWW page, and even with their
514authors before randomly posting asking for their present condition and
515disposition.
516
517=head1 CPAN
518
519CPAN stands for the Comprehensive Perl Archive Network. This is a globally
520replicated collection of all known Perl materials, including hundreds
521of unbundled modules. Here are the major categories of modules:
522
523=over
524
525=item *
526Language Extensions and Documentation Tools
527
528=item *
529Development Support
530
531=item *
532Operating System Interfaces
533
534=item *
535Networking, Device Control (modems) and InterProcess Communication
536
537=item *
538Data Types and Data Type Utilities
539
540=item *
541Database Interfaces
542
543=item *
544User Interfaces
545
546=item *
547Interfaces to / Emulations of Other Programming Languages
548
549=item *
550File Names, File Systems and File Locking (see also File Handles)
551
552=item *
553String Processing, Language Text Processing, Parsing, and Searching
554
555=item *
556Option, Argument, Parameter, and Configuration File Processing
557
558=item *
559Internationalization and Locale
560
561=item *
562Authentication, Security, and Encryption
563
564=item *
565World Wide Web, HTML, HTTP, CGI, MIME
566
567=item *
568Server and Daemon Utilities
569
570=item *
571Archiving and Compression
572
573=item *
574Images, Pixmap and Bitmap Manipulation, Drawing, and Graphing
575
576=item *
577Mail and Usenet News
578
579=item *
580Control Flow Utilities (callbacks and exceptions etc)
581
582=item *
583File Handle and Input/Output Stream Utilities
584
585=item *
586Miscellaneous Modules
587
588=back
589
590The registered CPAN sites as of this writing include the following.
591You should try to choose one close to you:
592
593=over
594
595=item *
596Africa
597
598 South Africa ftp://ftp.is.co.za/programming/perl/CPAN/
599
600=item *
601Asia
602
603 Hong Kong ftp://ftp.hkstar.com/pub/CPAN/
604 Japan ftp://ftp.jaist.ac.jp/pub/lang/perl/CPAN/
605 ftp://ftp.lab.kdd.co.jp/lang/perl/CPAN/
606 South Korea ftp://ftp.nuri.net/pub/CPAN/
607 Taiwan ftp://dongpo.math.ncu.edu.tw/perl/CPAN/
608 ftp://ftp.wownet.net/pub2/PERL/
609
610=item *
611Australasia
612
613 Australia ftp://ftp.netinfo.com.au/pub/perl/CPAN/
614 New Zealand ftp://ftp.tekotago.ac.nz/pub/perl/CPAN/
615
616=item *
617Europe
618
619 Austria ftp://ftp.tuwien.ac.at/pub/languages/perl/CPAN/
620 Belgium ftp://ftp.kulnet.kuleuven.ac.be/pub/mirror/CPAN/
621 Czech Republic ftp://sunsite.mff.cuni.cz/Languages/Perl/CPAN/
622 Denmark ftp://sunsite.auc.dk/pub/languages/perl/CPAN/
623 Finland ftp://ftp.funet.fi/pub/languages/perl/CPAN/
624 France ftp://ftp.ibp.fr/pub/perl/CPAN/
625 ftp://ftp.pasteur.fr/pub/computing/unix/perl/CPAN/
626 Germany ftp://ftp.gmd.de/packages/CPAN/
627 ftp://ftp.leo.org/pub/comp/programming/languages/perl/CPAN/
628 ftp://ftp.mpi-sb.mpg.de/pub/perl/CPAN/
629 ftp://ftp.rz.ruhr-uni-bochum.de/pub/CPAN/
630 ftp://ftp.uni-erlangen.de/pub/source/Perl/CPAN/
631 ftp://ftp.uni-hamburg.de/pub/soft/lang/perl/CPAN/
632 Greece ftp://ftp.ntua.gr/pub/lang/perl/
633 Hungary ftp://ftp.kfki.hu/pub/packages/perl/CPAN/
634 Italy ftp://cis.utovrm.it/CPAN/
635 the Netherlands ftp://ftp.cs.ruu.nl/pub/PERL/CPAN/
636 ftp://ftp.EU.net/packages/cpan/
637 Norway ftp://ftp.uit.no/pub/languages/perl/cpan/
638 Poland ftp://ftp.pk.edu.pl/pub/lang/perl/CPAN/
639 ftp://sunsite.icm.edu.pl/pub/CPAN/
640 Portugal ftp://ftp.ci.uminho.pt/pub/lang/perl/
641 ftp://ftp.telepac.pt/pub/CPAN/
642 Russia ftp://ftp.sai.msu.su/pub/lang/perl/CPAN/
643 Slovenia ftp://ftp.arnes.si/software/perl/CPAN/
644 Spain ftp://ftp.etse.urv.es/pub/mirror/perl/
645 ftp://ftp.rediris.es/mirror/CPAN/
646 Sweden ftp://ftp.sunet.se/pub/lang/perl/CPAN/
647 UK ftp://ftp.demon.co.uk/pub/mirrors/perl/CPAN/
648 ftp://sunsite.doc.ic.ac.uk/packages/CPAN/
649 ftp://unix.hensa.ac.uk/mirrors/perl-CPAN/
650
651=item *
652North America
653
654 Ontario ftp://ftp.utilis.com/public/CPAN/
655 ftp://enterprise.ic.gc.ca/pub/perl/CPAN/
656 Manitoba ftp://theory.uwinnipeg.ca/pub/CPAN/
657 California ftp://ftp.digital.com/pub/plan/perl/CPAN/
658 ftp://ftp.cdrom.com/pub/perl/CPAN/
659 Colorado ftp://ftp.cs.colorado.edu/pub/perl/CPAN/
660 Florida ftp://ftp.cis.ufl.edu/pub/perl/CPAN/
661 Illinois ftp://uiarchive.uiuc.edu/pub/lang/perl/CPAN/
662 Massachusetts ftp://ftp.iguide.com/pub/mirrors/packages/perl/CPAN/
663 New York ftp://ftp.rge.com/pub/languages/perl/
664 North Carolina ftp://ftp.duke.edu/pub/perl/
665 Oklahoma ftp://ftp.ou.edu/mirrors/CPAN/
666 Oregon http://www.perl.org/CPAN/
667 ftp://ftp.orst.edu/pub/packages/CPAN/
668 Pennsylvania ftp://ftp.epix.net/pub/languages/perl/
669 Texas ftp://ftp.sedl.org/pub/mirrors/CPAN/
670 ftp://ftp.metronet.com/pub/perl/
671
672=item *
673South America
674
675 Chile ftp://sunsite.dcc.uchile.cl/pub/Lang/perl/CPAN/
676
677=back
678
679For an up-to-date listing of CPAN sites,
680see F<http://www.perl.com/perl/CPAN> or F<ftp://ftp.perl.com/perl/>.
681
682=head1 Modules: Creation, Use, and Abuse
683
684(The following section is borrowed directly from Tim Bunce's modules
685file, available at your nearest CPAN site.)
686
687Perl implements a class using a package, but the presence of a
688package doesn't imply the presence of a class. A package is just a
689namespace. A class is a package that provides subroutines that can be
690used as methods. A method is just a subroutine that expects, as its
691first argument, either the name of a package (for "static" methods),
692or a reference to something (for "virtual" methods).
693
694A module is a file that (by convention) provides a class of the same
695name (sans the .pm), plus an import method in that class that can be
696called to fetch exported symbols. This module may implement some of
697its methods by loading dynamic C or C++ objects, but that should be
698totally transparent to the user of the module. Likewise, the module
699might set up an AUTOLOAD function to slurp in subroutine definitions on
700demand, but this is also transparent. Only the F<.pm> file is required to
701exist. See L<perlsub>, L<perltoot>, and L<AutoLoader> for details about
702the AUTOLOAD mechanism.
703
704=head2 Guidelines for Module Creation
705
706=over 4
707
708=item Do similar modules already exist in some form?
709
710If so, please try to reuse the existing modules either in whole or
711by inheriting useful features into a new class. If this is not
712practical try to get together with the module authors to work on
713extending or enhancing the functionality of the existing modules.
714A perfect example is the plethora of packages in perl4 for dealing
715with command line options.
716
717If you are writing a module to expand an already existing set of
718modules, please coordinate with the author of the package. It
719helps if you follow the same naming scheme and module interaction
720scheme as the original author.
721
722=item Try to design the new module to be easy to extend and reuse.
723
724Use blessed references. Use the two argument form of bless to bless
725into the class name given as the first parameter of the constructor,
726e.g.,:
727
728 sub new {
729 my $class = shift;
730 return bless {}, $class;
731 }
732
733or even this if you'd like it to be used as either a static
734or a virtual method.
735
736 sub new {
737 my $self = shift;
738 my $class = ref($self) || $self;
739 return bless {}, $class;
740 }
741
742Pass arrays as references so more parameters can be added later
743(it's also faster). Convert functions into methods where
744appropriate. Split large methods into smaller more flexible ones.
745Inherit methods from other modules if appropriate.
746
747Avoid class name tests like: C<die "Invalid" unless ref $ref eq 'FOO'>.
748Generally you can delete the "C<eq 'FOO'>" part with no harm at all.
749Let the objects look after themselves! Generally, avoid hard-wired
750class names as far as possible.
751
752Avoid C<$r-E<gt>Class::func()> where using C<@ISA=qw(... Class ...)> and
753C<$r-E<gt>func()> would work (see L<perlbot> for more details).
754
755Use autosplit so little used or newly added functions won't be a
756burden to programs which don't use them. Add test functions to
757the module after __END__ either using AutoSplit or by saying:
758
759 eval join('',<main::DATA>) || die $@ unless caller();
760
761Does your module pass the 'empty subclass' test? If you say
762"C<@SUBCLASS::ISA = qw(YOURCLASS);>" your applications should be able
763to use SUBCLASS in exactly the same way as YOURCLASS. For example,
764does your application still work if you change: C<$obj = new YOURCLASS;>
765into: C<$obj = new SUBCLASS;> ?
766
767Avoid keeping any state information in your packages. It makes it
768difficult for multiple other packages to use yours. Keep state
769information in objects.
770
771Always use B<-w>. Try to C<use strict;> (or C<use strict qw(...);>).
772Remember that you can add C<no strict qw(...);> to individual blocks
773of code which need less strictness. Always use B<-w>. Always use B<-w>!
774Follow the guidelines in the perlstyle(1) manual.
775
776=item Some simple style guidelines
777
778The perlstyle manual supplied with perl has many helpful points.
779
780Coding style is a matter of personal taste. Many people evolve their
781style over several years as they learn what helps them write and
782maintain good code. Here's one set of assorted suggestions that
783seem to be widely used by experienced developers:
784
785Use underscores to separate words. It is generally easier to read
786$var_names_like_this than $VarNamesLikeThis, especially for
787non-native speakers of English. It's also a simple rule that works
788consistently with VAR_NAMES_LIKE_THIS.
789
790Package/Module names are an exception to this rule. Perl informally
791reserves lowercase module names for 'pragma' modules like integer
792and strict. Other modules normally begin with a capital letter and
793use mixed case with no underscores (need to be short and portable).
794
795You may find it helpful to use letter case to indicate the scope
796or nature of a variable. For example:
797
798 $ALL_CAPS_HERE constants only (beware clashes with perl vars)
799 $Some_Caps_Here package-wide global/static
800 $no_caps_here function scope my() or local() variables
801
802Function and method names seem to work best as all lowercase.
803e.g., C<$obj-E<gt>as_string()>.
804
805You can use a leading underscore to indicate that a variable or
806function should not be used outside the package that defined it.
807
808=item Select what to export.
809
810Do NOT export method names!
811
812Do NOT export anything else by default without a good reason!
813
814Exports pollute the namespace of the module user. If you must
815export try to use @EXPORT_OK in preference to @EXPORT and avoid
816short or common names to reduce the risk of name clashes.
817
818Generally anything not exported is still accessible from outside the
819module using the ModuleName::item_name (or C<$blessed_ref-E<gt>method>)
820syntax. By convention you can use a leading underscore on names to
821indicate informally that they are 'internal' and not for public use.
822
823(It is actually possible to get private functions by saying:
824C<my $subref = sub { ... }; &$subref;>. But there's no way to call that
825directly as a method, because a method must have a name in the symbol
826table.)
827
828As a general rule, if the module is trying to be object oriented
829then export nothing. If it's just a collection of functions then
830@EXPORT_OK anything but use @EXPORT with caution.
831
832=item Select a name for the module.
833
834This name should be as descriptive, accurate, and complete as
835possible. Avoid any risk of ambiguity. Always try to use two or
836more whole words. Generally the name should reflect what is special
837about what the module does rather than how it does it. Please use
838nested module names to group informally or categorize a module.
839There should be a very good reason for a module not to have a nested name.
840Module names should begin with a capital letter.
841
842Having 57 modules all called Sort will not make life easy for anyone
843(though having 23 called Sort::Quick is only marginally better :-).
844Imagine someone trying to install your module alongside many others.
845If in any doubt ask for suggestions in comp.lang.perl.misc.
846
847If you are developing a suite of related modules/classes it's good
848practice to use nested classes with a common prefix as this will
849avoid namespace clashes. For example: Xyz::Control, Xyz::View,
850Xyz::Model etc. Use the modules in this list as a naming guide.
851
852If adding a new module to a set, follow the original author's
853standards for naming modules and the interface to methods in
854those modules.
855
856To be portable each component of a module name should be limited to
85711 characters. If it might be used on MS-DOS then try to ensure each is
858unique in the first 8 characters. Nested modules make this easier.
859
860=item Have you got it right?
861
862How do you know that you've made the right decisions? Have you
863picked an interface design that will cause problems later? Have
864you picked the most appropriate name? Do you have any questions?
865
866The best way to know for sure, and pick up many helpful suggestions,
867is to ask someone who knows. Comp.lang.perl.misc is read by just about
868all the people who develop modules and it's the best place to ask.
869
870All you need to do is post a short summary of the module, its
871purpose and interfaces. A few lines on each of the main methods is
872probably enough. (If you post the whole module it might be ignored
873by busy people - generally the very people you want to read it!)
874
875Don't worry about posting if you can't say when the module will be
876ready - just say so in the message. It might be worth inviting
877others to help you, they may be able to complete it for you!
878
879=item README and other Additional Files.
880
881It's well known that software developers usually fully document the
882software they write. If, however, the world is in urgent need of
883your software and there is not enough time to write the full
884documentation please at least provide a README file containing:
885
886=over 10
887
888=item *
889A description of the module/package/extension etc.
890
891=item *
892A copyright notice - see below.
893
894=item *
895Prerequisites - what else you may need to have.
896
897=item *
898How to build it - possible changes to Makefile.PL etc.
899
900=item *
901How to install it.
902
903=item *
904Recent changes in this release, especially incompatibilities
905
906=item *
907Changes / enhancements you plan to make in the future.
908
909=back
910
911If the README file seems to be getting too large you may wish to
912split out some of the sections into separate files: INSTALL,
913Copying, ToDo etc.
914
915=over 4
916
917=item Adding a Copyright Notice.
918
919How you choose to license your work is a personal decision.
920The general mechanism is to assert your Copyright and then make
921a declaration of how others may copy/use/modify your work.
922
923Perl, for example, is supplied with two types of licence: The GNU
924GPL and The Artistic Licence (see the files README, Copying, and
925Artistic). Larry has good reasons for NOT just using the GNU GPL.
926
927My personal recommendation, out of respect for Larry, Perl, and the
928perl community at large is to state something simply like:
929
930 Copyright (c) 1995 Your Name. All rights reserved.
931 This program is free software; you can redistribute it and/or
932 modify it under the same terms as Perl itself.
933
934This statement should at least appear in the README file. You may
935also wish to include it in a Copying file and your source files.
936Remember to include the other words in addition to the Copyright.
937
938=item Give the module a version/issue/release number.
939
940To be fully compatible with the Exporter and MakeMaker modules you
941should store your module's version number in a non-my package
942variable called $VERSION. This should be a floating point
943number with at least two digits after the decimal (i.e., hundredths,
944e.g, C<$VERSION = "0.01">). Don't use a "1.3.2" style version.
945See Exporter.pm in Perl5.001m or later for details.
946
947It may be handy to add a function or method to retrieve the number.
948Use the number in announcements and archive file names when
949releasing the module (ModuleName-1.02.tar.Z).
950See perldoc ExtUtils::MakeMaker.pm for details.
951
952=item How to release and distribute a module.
953
954It's good idea to post an announcement of the availability of your
955module (or the module itself if small) to the comp.lang.perl.announce
956Usenet newsgroup. This will at least ensure very wide once-off
957distribution.
958
959If possible you should place the module into a major ftp archive and
960include details of its location in your announcement.
961
962Some notes about ftp archives: Please use a long descriptive file
963name which includes the version number. Most incoming directories
964will not be readable/listable, i.e., you won't be able to see your
965file after uploading it. Remember to send your email notification
966message as soon as possible after uploading else your file may get
967deleted automatically. Allow time for the file to be processed
968and/or check the file has been processed before announcing its
969location.
970
971FTP Archives for Perl Modules:
972
973Follow the instructions and links on
974
975 http://franz.ww.tu-berlin.de/modulelist
976
977or upload to one of these sites:
978
979 ftp://franz.ww.tu-berlin.de/incoming
980 ftp://ftp.cis.ufl.edu/incoming
981
982and notify <F<upload@franz.ww.tu-berlin.de>>.
983
984By using the WWW interface you can ask the Upload Server to mirror
985your modules from your ftp or WWW site into your own directory on
986CPAN!
987
988Please remember to send me an updated entry for the Module list!
989
990=item Take care when changing a released module.
991
992Always strive to remain compatible with previous released versions
993(see 2.2 above) Otherwise try to add a mechanism to revert to the
994old behaviour if people rely on it. Document incompatible changes.
995
996=back
997
998=back
999
1000=head2 Guidelines for Converting Perl 4 Library Scripts into Modules
1001
1002=over 4
1003
1004=item There is no requirement to convert anything.
1005
1006If it ain't broke, don't fix it! Perl 4 library scripts should
1007continue to work with no problems. You may need to make some minor
1008changes (like escaping non-array @'s in double quoted strings) but
1009there is no need to convert a .pl file into a Module for just that.
1010
1011=item Consider the implications.
1012
1013All the perl applications which make use of the script will need to
1014be changed (slightly) if the script is converted into a module. Is
1015it worth it unless you plan to make other changes at the same time?
1016
1017=item Make the most of the opportunity.
1018
1019If you are going to convert the script to a module you can use the
1020opportunity to redesign the interface. The 'Guidelines for Module
1021Creation' above include many of the issues you should consider.
1022
1023=item The pl2pm utility will get you started.
1024
1025This utility will read *.pl files (given as parameters) and write
1026corresponding *.pm files. The pl2pm utilities does the following:
1027
1028=over 10
1029
1030=item *
1031Adds the standard Module prologue lines
1032
1033=item *
1034Converts package specifiers from ' to ::
1035
1036=item *
1037Converts die(...) to croak(...)
1038
1039=item *
1040Several other minor changes
1041
1042=back
1043
1044Being a mechanical process pl2pm is not bullet proof. The converted
1045code will need careful checking, especially any package statements.
1046Don't delete the original .pl file till the new .pm one works!
1047
1048=back
1049
1050=head2 Guidelines for Reusing Application Code
1051
1052=over 4
1053
1054=item Complete applications rarely belong in the Perl Module Library.
1055
1056=item Many applications contain some perl code which could be reused.
1057
1058Help save the world! Share your code in a form that makes it easy
1059to reuse.
1060
1061=item Break-out the reusable code into one or more separate module files.
1062
1063=item Take the opportunity to reconsider and redesign the interfaces.
1064
1065=item In some cases the 'application' can then be reduced to a small
1066
1067fragment of code built on top of the reusable modules. In these cases
1068the application could invoked as:
1069
1070 perl -e 'use Module::Name; method(@ARGV)' ...
1071or
1072 perl -mModule::Name ... (in perl5.002 or higher)
1073
1074=back
1075
1076=head1 NOTE
1077
1078Perl does not enforce private and public parts of its modules as you may
1079have been used to in other languages like C++, Ada, or Modula-17. Perl
1080doesn't have an infatuation with enforced privacy. It would prefer
1081that you stayed out of its living room because you weren't invited, not
1082because it has a shotgun.
1083
1084The module and its user have a contract, part of which is common law,
1085and part of which is "written". Part of the common law contract is
1086that a module doesn't pollute any namespace it wasn't asked to. The
1087written contract for the module (A.K.A. documentation) may make other
1088provisions. But then you know when you C<use RedefineTheWorld> that
1089you're redefining the world and willing to take the consequences.