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