This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
SelfLoader: fix prototype pattern, rename intrusive lexical
[perl5.git] / pod / perlmod.pod
CommitLineData
a0d0e21e
LW
1=head1 NAME
2
3perlmod - Perl modules (packages)
4
5=head1 DESCRIPTION
6
7=head2 Packages
8
748a9306 9Perl provides a mechanism for alternative namespaces to protect packages
d0c42abe 10from stomping on each other's variables. In fact, apart from certain
cb1a09d0
AD
11magical variables, there's really no such thing as a global variable in
12Perl. The package statement declares the compilation unit as being in the
13given namespace. The scope of the package declaration is from the
14declaration itself through the end of the enclosing block (the same scope
15as the local() operator). All further unqualified dynamic identifiers
5f05dabc 16will be in this namespace. A package statement affects only dynamic
cb1a09d0
AD
17variables--including those you've used local() on--but I<not> lexical
18variables created with my(). Typically it would be the first declaration
19in a file to be included by the C<require> or C<use> operator. You can
5f05dabc 20switch into a package in more than one place; it influences merely which
a0d0e21e
LW
21symbol table is used by the compiler for the rest of that block. You can
22refer to variables and filehandles in other packages by prefixing the
23identifier with the package name and a double colon:
24C<$Package::Variable>. If the package name is null, the C<main> package
d0c42abe 25is assumed. That is, C<$::sail> is equivalent to C<$main::sail>.
a0d0e21e
LW
26
27(The old package delimiter was a single quote, but double colon
28is now the preferred delimiter, in part because it's more readable
29to humans, and in part because it's more readable to B<emacs> macros.
30It also makes C++ programmers feel like they know what's going on.)
31
32Packages may be nested inside other packages: C<$OUTER::INNER::var>. This
33implies nothing about the order of name lookups, however. All symbols
34are either local to the current package, or must be fully qualified
35from the outer package name down. For instance, there is nowhere
36within package C<OUTER> that C<$INNER::var> refers to C<$OUTER::INNER::var>.
37It would treat package C<INNER> as a totally separate global package.
38
39Only identifiers starting with letters (or underscore) are stored in a
cb1a09d0
AD
40package's symbol table. All other symbols are kept in package C<main>,
41including all of the punctuation variables like $_. In addition, the
5f05dabc 42identifiers STDIN, STDOUT, STDERR, ARGV, ARGVOUT, ENV, INC, and SIG are
cb1a09d0 43forced to be in package C<main>, even when used for other purposes than
54310121 44their builtin one. Note also that, if you have a package called C<m>,
5f05dabc 45C<s>, or C<y>, then you can't use the qualified form of an identifier
cb1a09d0
AD
46because it will be interpreted instead as a pattern match, a substitution,
47or a translation.
a0d0e21e
LW
48
49(Variables beginning with underscore used to be forced into package
50main, but we decided it was more useful for package writers to be able
cb1a09d0
AD
51to use leading underscore to indicate private variables and method names.
52$_ is still global though.)
a0d0e21e
LW
53
54Eval()ed strings are compiled in the package in which the eval() was
55compiled. (Assignments to C<$SIG{}>, however, assume the signal
748a9306 56handler specified is in the C<main> package. Qualify the signal handler
a0d0e21e
LW
57name if you wish to have a signal handler in a package.) For an
58example, examine F<perldb.pl> in the Perl library. It initially switches
59to the C<DB> package so that the debugger doesn't interfere with variables
60in the script you are trying to debug. At various points, however, it
61temporarily switches back to the C<main> package to evaluate various
62expressions in the context of the C<main> package (or wherever you came
63from). See L<perldebug>.
64
5f05dabc 65See L<perlsub> for other scoping issues related to my() and local(),
cb1a09d0
AD
66or L<perlref> regarding closures.
67
a0d0e21e
LW
68=head2 Symbol Tables
69
aa689395
PP
70The symbol table for a package happens to be stored in the hash of that
71name with two colons appended. The main symbol table's name is thus
72C<%main::>, or C<%::> for short. Likewise symbol table for the nested
73package mentioned earlier is named C<%OUTER::INNER::>.
74
75The value in each entry of the hash is what you are referring to when you
76use the C<*name> typeglob notation. In fact, the following have the same
77effect, though the first is more efficient because it does the symbol
78table lookups at compile time:
a0d0e21e 79
54310121
PP
80 local(*main::foo) = *main::bar;
81 local($main::{'foo'}) = $main::{'bar'};
a0d0e21e
LW
82
83You can use this to print out all the variables in a package, for
84instance. Here is F<dumpvar.pl> from the Perl library:
85
86 package dumpvar;
87 sub main::dumpvar {
88 ($package) = @_;
89 local(*stab) = eval("*${package}::");
90 while (($key,$val) = each(%stab)) {
91 local(*entry) = $val;
92 if (defined $entry) {
93 print "\$$key = '$entry'\n";
94 }
95
96 if (defined @entry) {
97 print "\@$key = (\n";
98 foreach $num ($[ .. $#entry) {
99 print " $num\t'",$entry[$num],"'\n";
100 }
101 print ")\n";
102 }
103
104 if ($key ne "${package}::" && defined %entry) {
105 print "\%$key = (\n";
106 foreach $key (sort keys(%entry)) {
107 print " $key\t'",$entry{$key},"'\n";
108 }
109 print ")\n";
110 }
111 }
112 }
113
114Note that even though the subroutine is compiled in package C<dumpvar>,
115the name of the subroutine is qualified so that its name is inserted
116into package C<main>.
117
cb1a09d0 118Assignment to a typeglob performs an aliasing operation, i.e.,
a0d0e21e
LW
119
120 *dick = *richard;
121
5f05dabc 122causes variables, subroutines, and file handles accessible via the
d0c42abe 123identifier C<richard> to also be accessible via the identifier C<dick>. If
5f05dabc 124you want to alias only a particular variable or subroutine, you can
a0d0e21e
LW
125assign a reference instead:
126
127 *dick = \$richard;
128
129makes $richard and $dick the same variable, but leaves
130@richard and @dick as separate arrays. Tricky, eh?
131
cb1a09d0
AD
132This mechanism may be used to pass and return cheap references
133into or from subroutines if you won't want to copy the whole
134thing.
135
136 %some_hash = ();
137 *some_hash = fn( \%another_hash );
138 sub fn {
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
5f05dabc 143 return \%nhash;
cb1a09d0
AD
144 }
145
5f05dabc 146On return, the reference will overwrite the hash slot in the
cb1a09d0 147symbol table specified by the *some_hash typeglob. This
c36e9b62 148is a somewhat tricky way of passing around references cheaply
cb1a09d0
AD
149when you won't want to have to remember to dereference variables
150explicitly.
151
152Another use of symbol tables is for making "constant" scalars.
153
154 *PI = \3.14159265358979;
155
156Now you cannot alter $PI, which is probably a good thing all in all.
157
55497cff
PP
158You can say C<*foo{PACKAGE}> and C<*foo{NAME}> to find out what name and
159package the *foo symbol table entry comes from. This may be useful
160in a subroutine which is passed typeglobs as arguments
161
162 sub identify_typeglob {
163 my $glob = shift;
164 print 'You gave me ', *{$glob}{PACKAGE}, '::', *{$glob}{NAME}, "\n";
165 }
166 identify_typeglob *foo;
167 identify_typeglob *bar::baz;
168
169This prints
170
171 You gave me main::foo
172 You gave me bar::baz
173
174The *foo{THING} notation can also be used to obtain references to the
175individual elements of *foo, see L<perlref>.
176
a0d0e21e
LW
177=head2 Package Constructors and Destructors
178
179There are two special subroutine definitions that function as package
180constructors and destructors. These are the C<BEGIN> and C<END>
181routines. The C<sub> is optional for these routines.
182
183A C<BEGIN> subroutine is executed as soon as possible, that is, the
184moment it is completely defined, even before the rest of the containing
185file is parsed. You may have multiple C<BEGIN> blocks within a
186file--they will execute in order of definition. Because a C<BEGIN>
187block executes immediately, it can pull in definitions of subroutines
188and such from other files in time to be visible to the rest of the
189file.
190
191An C<END> subroutine is executed as late as possible, that is, when the
192interpreter is being exited, even if it is exiting as a result of a
193die() function. (But not if it's is being blown out of the water by a
194signal--you have to trap that yourself (if you can).) You may have
748a9306 195multiple C<END> blocks within a file--they will execute in reverse
a0d0e21e
LW
196order of definition; that is: last in, first out (LIFO).
197
c36e9b62
PP
198Inside an C<END> subroutine C<$?> contains the value that the script is
199going to pass to C<exit()>. You can modify C<$?> to change the exit
5f05dabc 200value of the script. Beware of changing C<$?> by accident (e.g.,, by
c36e9b62
PP
201running something via C<system>).
202
a0d0e21e
LW
203Note that when you use the B<-n> and B<-p> switches to Perl, C<BEGIN>
204and C<END> work just as they do in B<awk>, as a degenerate case.
205
206=head2 Perl Classes
207
4633a7c4 208There is no special class syntax in Perl, but a package may function
a0d0e21e
LW
209as a class if it provides subroutines that function as methods. Such a
210package may also derive some of its methods from another class package
5f05dabc 211by listing the other package name in its @ISA array.
4633a7c4
LW
212
213For more on this, see L<perlobj>.
a0d0e21e
LW
214
215=head2 Perl Modules
216
c07a80fd 217A module is just a package that is defined in a library file of
a0d0e21e
LW
218the same name, and is designed to be reusable. It may do this by
219providing a mechanism for exporting some of its symbols into the symbol
220table of any package using it. Or it may function as a class
221definition and make its semantics available implicitly through method
222calls on the class and its objects, without explicit exportation of any
223symbols. Or it can do a little of both.
224
9607fc9c
PP
225For example, to start a normal module called Some::Module, create
226a file called Some/Module.pm and start with this template:
227
228 package Some::Module; # assumes Some/Module.pm
229
230 use strict;
231
232 BEGIN {
233 use Exporter ();
234 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
235
236 # set the version for version checking
237 $VERSION = 1.00;
238 # if using RCS/CVS, this may be preferred
239 $VERSION = do { my @r = (q$Revision: 2.21 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
240
241 @ISA = qw(Exporter);
242 @EXPORT = qw(&func1 &func2 &func4);
243 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
244
245 # your exported package globals go here,
246 # as well as any optionally exported functions
247 @EXPORT_OK = qw($Var1 %Hashit &func3);
248 }
249 use vars @EXPORT_OK;
250
251 # non-exported package globals go here
252 use vars qw(@more $stuff);
253
254 # initalize package globals, first exported ones
255 $Var1 = '';
256 %Hashit = ();
257
258 # then the others (which are still accessible as $Some::Module::stuff)
259 $stuff = '';
260 @more = ();
261
262 # all file-scoped lexicals must be created before
263 # the functions below that use them.
264
265 # file-private lexicals go here
266 my $priv_var = '';
267 my %secret_hash = ();
268
269 # here's a file-private function as a closure,
270 # callable as &$priv_func; it cannot be prototyped.
271 my $priv_func = sub {
272 # stuff goes here.
273 };
274
275 # make all your functions, whether exported or not;
276 # remember to put something interesting in the {} stubs
277 sub func1 {} # no prototype
278 sub func2() {} # proto'd void
279 sub func3($$) {} # proto'd to 2 scalars
280
281 # this one isn't exported, but could be called!
282 sub func4(\%) {} # proto'd to 1 hash ref
283
284 END { } # module clean-up code here (global destructor)
4633a7c4
LW
285
286Then go on to declare and use your variables in functions
287without any qualifications.
5f05dabc 288See L<Exporter> and the I<Perl Modules File> for details on
4633a7c4
LW
289mechanics and style issues in module creation.
290
291Perl modules are included into your program by saying
a0d0e21e
LW
292
293 use Module;
294
295or
296
297 use Module LIST;
298
299This is exactly equivalent to
300
301 BEGIN { require "Module.pm"; import Module; }
302
303or
304
305 BEGIN { require "Module.pm"; import Module LIST; }
306
cb1a09d0
AD
307As a special case
308
309 use Module ();
310
311is exactly equivalent to
312
313 BEGIN { require "Module.pm"; }
314
a0d0e21e
LW
315All Perl module files have the extension F<.pm>. C<use> assumes this so
316that you don't have to spell out "F<Module.pm>" in quotes. This also
317helps to differentiate new modules from old F<.pl> and F<.ph> files.
318Module names are also capitalized unless they're functioning as pragmas,
319"Pragmas" are in effect compiler directives, and are sometimes called
320"pragmatic modules" (or even "pragmata" if you're a classicist).
321
322Because the C<use> statement implies a C<BEGIN> block, the importation
323of semantics happens at the moment the C<use> statement is compiled,
324before the rest of the file is compiled. This is how it is able
325to function as a pragma mechanism, and also how modules are able to
326declare subroutines that are then visible as list operators for
327the rest of the current file. This will not work if you use C<require>
cb1a09d0 328instead of C<use>. With require you can get into this problem:
a0d0e21e
LW
329
330 require Cwd; # make Cwd:: accessible
54310121 331 $here = Cwd::getcwd();
a0d0e21e 332
5f05dabc 333 use Cwd; # import names from Cwd::
a0d0e21e
LW
334 $here = getcwd();
335
336 require Cwd; # make Cwd:: accessible
337 $here = getcwd(); # oops! no main::getcwd()
338
cb1a09d0
AD
339In general C<use Module ();> is recommended over C<require Module;>.
340
a0d0e21e
LW
341Perl packages may be nested inside other package names, so we can have
342package names containing C<::>. But if we used that package name
343directly as a filename it would makes for unwieldy or impossible
344filenames on some systems. Therefore, if a module's name is, say,
345C<Text::Soundex>, then its definition is actually found in the library
346file F<Text/Soundex.pm>.
347
348Perl modules always have a F<.pm> file, but there may also be dynamically
349linked executables or autoloaded subroutine definitions associated with
350the module. If so, these will be entirely transparent to the user of
351the module. It is the responsibility of the F<.pm> file to load (or
352arrange to autoload) any additional functionality. The POSIX module
353happens to do both dynamic loading and autoloading, but the user can
5f05dabc 354say just C<use POSIX> to get it all.
a0d0e21e 355
8e07c86e 356For more information on writing extension modules, see L<perlxs>
a0d0e21e
LW
357and L<perlguts>.
358
359=head1 NOTE
360
361Perl does not enforce private and public parts of its modules as you may
362have been used to in other languages like C++, Ada, or Modula-17. Perl
363doesn't have an infatuation with enforced privacy. It would prefer
364that you stayed out of its living room because you weren't invited, not
365because it has a shotgun.
366
367The module and its user have a contract, part of which is common law,
368and part of which is "written". Part of the common law contract is
369that a module doesn't pollute any namespace it wasn't asked to. The
5f05dabc 370written contract for the module (A.K.A. documentation) may make other
a0d0e21e
LW
371provisions. But then you know when you C<use RedefineTheWorld> that
372you're redefining the world and willing to take the consequences.
373
374=head1 THE PERL MODULE LIBRARY
375
5f05dabc
PP
376A number of modules are included the Perl distribution. These are
377described below, and all end in F<.pm>. You may also discover files in
a0d0e21e 378the library directory that end in either F<.pl> or F<.ph>. These are old
748a9306 379libraries supplied so that old programs that use them still run. The
a0d0e21e
LW
380F<.pl> files will all eventually be converted into standard modules, and
381the F<.ph> files made by B<h2ph> will probably end up as extension modules
382made by B<h2xs>. (Some F<.ph> values may already be available through the
383POSIX module.) The B<pl2pm> file in the distribution may help in your
54310121 384conversion, but it's just a mechanical process and therefore far from
4fdae800 385bulletproof.
a0d0e21e
LW
386
387=head2 Pragmatic Modules
388
389They work somewhat like pragmas in that they tend to affect the compilation of
5f05dabc 390your program, and thus will usually work well only when used within a
55497cff
PP
391C<use>, or C<no>. Most of these are locally scoped, so an inner BLOCK
392may countermand any of these by saying:
a0d0e21e
LW
393
394 no integer;
395 no strict 'refs';
396
397which lasts until the end of that BLOCK.
398
5f05dabc 399Unlike the pragmas that effect the C<$^H> hints variable, the C<use
55497cff 400vars> and C<use subs> declarations are not BLOCK-scoped. They allow
54310121 401you to predeclare a variables or subroutines within a particular
4fdae800 402I<file> rather than just a block. Such declarations are effective
55497cff
PP
403for the entire file for which they were declared. You cannot rescind
404them with C<no vars> or C<no subs>.
405
406The following pragmas are defined (and have their own documentation).
a0d0e21e
LW
407
408=over 12
409
5f05dabc
PP
410=item blib
411
412manipulate @INC at compile time to use MakeMaker's uninstalled version
413of a package
414
cb1a09d0 415=item diagnostics
4633a7c4 416
55497cff 417force verbose warning diagnostics
4633a7c4 418
cb1a09d0 419=item integer
a0d0e21e 420
55497cff 421compute arithmetic in integer instead of double
a0d0e21e 422
cb1a09d0 423=item less
a0d0e21e 424
55497cff
PP
425request less of something from the compiler
426
427=item lib
428
429manipulate @INC at compile time
a0d0e21e 430
5f05dabc
PP
431=item locale
432
54310121 433use or ignore current locale for builtin operations (see L<perllocale>)
5f05dabc 434
d0c42abe
PP
435=item ops
436
5f05dabc 437restrict named opcodes when compiling or running Perl code
d0c42abe 438
cb1a09d0
AD
439=item overload
440
5f05dabc 441overload basic Perl operations
cb1a09d0
AD
442
443=item sigtrap
a0d0e21e 444
55497cff 445enable simple signal handling
a0d0e21e 446
cb1a09d0 447=item strict
a0d0e21e 448
55497cff 449restrict unsafe constructs
a0d0e21e 450
cb1a09d0 451=item subs
a0d0e21e 452
54310121 453predeclare sub names
a0d0e21e 454
ff0cee69
PP
455=item vmsish
456
457adopt certain VMS-specific behaviors
458
d0c42abe
PP
459=item vars
460
54310121 461predeclare global variable names
d0c42abe 462
a0d0e21e
LW
463=back
464
465=head2 Standard Modules
466
4633a7c4 467Standard, bundled modules are all expected to behave in a well-defined
a0d0e21e 468manner with respect to namespace pollution because they use the
4633a7c4 469Exporter module. See their own documentation for details.
a0d0e21e 470
cb1a09d0
AD
471=over 12
472
473=item AnyDBM_File
474
475provide framework for multiple DBMs
476
477=item AutoLoader
478
479load functions only on demand
480
481=item AutoSplit
482
483split a package for autoloading
484
485=item Benchmark
486
487benchmark running times of code
488
71be2cbc
PP
489=item CPAN
490
491interface to Comprehensive Perl Archive Network
492
493=item CPAN::FirstTime
494
495create a CPAN configuration file
496
497=item CPAN::Nox
498
499run CPAN while avoiding compiled extensions
500
cb1a09d0
AD
501=item Carp
502
503warn of errors (from perspective of caller)
504
8cc95fdb 505=item Class::Struct
5f05dabc 506
8cc95fdb 507declare struct-like datatypes
5f05dabc 508
cb1a09d0
AD
509=item Config
510
55497cff 511access Perl configuration information
cb1a09d0
AD
512
513=item Cwd
514
515get pathname of current working directory
516
517=item DB_File
518
55497cff 519access to Berkeley DB
cb1a09d0
AD
520
521=item Devel::SelfStubber
522
523generate stubs for a SelfLoading module
524
55497cff
PP
525=item DirHandle
526
527supply object methods for directory handles
528
cb1a09d0
AD
529=item DynaLoader
530
5f05dabc 531dynamically load C libraries into Perl code
cb1a09d0
AD
532
533=item English
534
55497cff 535use nice English (or awk) names for ugly punctuation variables
cb1a09d0
AD
536
537=item Env
538
55497cff 539import environment variables
cb1a09d0
AD
540
541=item Exporter
542
55497cff
PP
543implements default import method for modules
544
545=item ExtUtils::Embed
546
5f05dabc 547utilities for embedding Perl in C/C++ applications
55497cff
PP
548
549=item ExtUtils::Install
550
551install files from here to there
cb1a09d0
AD
552
553=item ExtUtils::Liblist
554
555determine libraries to use and how to use them
556
5f05dabc
PP
557=item ExtUtils::MM_OS2
558
54310121 559methods to override Unix behaviour in ExtUtils::MakeMaker
5f05dabc
PP
560
561=item ExtUtils::MM_Unix
562
563methods used by ExtUtils::MakeMaker
564
565=item ExtUtils::MM_VMS
566
54310121 567methods to override Unix behaviour in ExtUtils::MakeMaker
5f05dabc 568
cb1a09d0
AD
569=item ExtUtils::MakeMaker
570
571create an extension Makefile
572
573=item ExtUtils::Manifest
574
575utilities to write and check a MANIFEST file
576
577=item ExtUtils::Mkbootstrap
578
579make a bootstrap file for use by DynaLoader
580
55497cff
PP
581=item ExtUtils::Mksymlists
582
583write linker options files for dynamic extension
584
5f05dabc 585=item ExtUtils::testlib
55497cff 586
5f05dabc 587add blib/* directories to @INC
55497cff 588
cb1a09d0
AD
589=item Fcntl
590
591load the C Fcntl.h defines
592
593=item File::Basename
594
5f05dabc 595split a pathname into pieces
55497cff 596
cb1a09d0
AD
597=item File::CheckTree
598
599run many filetest checks on a tree
600
5f05dabc
PP
601=item File::Compare
602
603compare files or filehandles
604
55497cff
PP
605=item File::Copy
606
5f05dabc 607copy files or filehandles
55497cff 608
cb1a09d0
AD
609=item File::Find
610
611traverse a file tree
612
cb1a09d0
AD
613=item File::Path
614
615create or remove a series of directories
616
5f05dabc
PP
617=item File::stat
618
54310121 619by-name interface to Perl's builtin stat() functions
5f05dabc
PP
620
621=item FileCache
622
623keep more files open than the system permits
624
625=item FileHandle
626
627supply object methods for filehandles
628
55497cff
PP
629=item FindBin
630
631locate directory of original perl script
632
633=item GDBM_File
634
5f05dabc 635access to the gdbm library
55497cff 636
cb1a09d0
AD
637=item Getopt::Long
638
55497cff 639extended processing of command line options
cb1a09d0
AD
640
641=item Getopt::Std
642
55497cff 643process single-character switches with switch clustering
cb1a09d0
AD
644
645=item I18N::Collate
646
647compare 8-bit scalar data according to the current locale
648
55497cff
PP
649=item IO
650
651load various IO modules
652
653=item IO::File
654
655supply object methods for filehandles
656
657=item IO::Handle
658
659supply object methods for I/O handles
660
661=item IO::Pipe
662
663supply object methods for pipes
664
665=item IO::Seekable
666
667supply seek based methods for I/O objects
668
669=item IO::Select
670
671OO interface to the select system call
672
673=item IO::Socket
674
675object interface to socket communications
676
cb1a09d0
AD
677=item IPC::Open2
678
55497cff 679open a process for both reading and writing
cb1a09d0
AD
680
681=item IPC::Open3
682
683open a process for reading, writing, and error handling
684
55497cff
PP
685=item Math::BigFloat
686
687arbitrary length float math package
688
689=item Math::BigInt
690
691arbitrary size integer math package
692
693=item Math::Complex
694
695complex numbers and associated mathematical functions
696
697=item NDBM_File
698
699tied access to ndbm files
700
7e1af8bc
PP
701=item Net::Ping
702
703Hello, anybody home?
704
5f05dabc
PP
705=item Net::hostent
706
54310121 707by-name interface to Perl's builtin gethost*() functions
5f05dabc
PP
708
709=item Net::netent
710
54310121 711by-name interface to Perl's builtin getnet*() functions
5f05dabc
PP
712
713=item Net::protoent
714
54310121 715by-name interface to Perl's builtin getproto*() functions
5f05dabc
PP
716
717=item Net::servent
718
54310121 719by-name interface to Perl's builtin getserv*() functions
5f05dabc 720
55497cff
PP
721=item Opcode
722
5f05dabc 723disable named opcodes when compiling or running perl code
55497cff
PP
724
725=item Pod::Text
726
727convert POD data to formatted ASCII text
728
cb1a09d0
AD
729=item POSIX
730
5f05dabc 731interface to IEEE Standard 1003.1
55497cff
PP
732
733=item SDBM_File
734
735tied access to sdbm files
736
5f05dabc
PP
737=item Safe
738
739compile and execute code in restricted compartments
740
55497cff
PP
741=item Search::Dict
742
743search for key in dictionary file
744
745=item SelectSaver
746
747save and restore selected file handle
cb1a09d0
AD
748
749=item SelfLoader
750
751load functions only on demand
752
55497cff 753=item Shell
a2927560 754
55497cff 755run shell commands transparently within perl
a2927560 756
cb1a09d0
AD
757=item Socket
758
759load the C socket.h defines and structure manipulators
760
55497cff
PP
761=item Symbol
762
763manipulate Perl symbols and their names
764
765=item Sys::Hostname
766
767try every conceivable way to get hostname
768
769=item Sys::Syslog
770
54310121 771interface to the Unix syslog(3) calls
55497cff
PP
772
773=item Term::Cap
774
5f05dabc 775termcap interface
55497cff
PP
776
777=item Term::Complete
778
779word completion module
780
781=item Term::ReadLine
782
5f05dabc 783interface to various C<readline> packages
55497cff 784
cb1a09d0
AD
785=item Test::Harness
786
787run perl standard test scripts with statistics
788
789=item Text::Abbrev
790
c36e9b62 791create an abbreviation table from a list
cb1a09d0 792
55497cff
PP
793=item Text::ParseWords
794
795parse text into an array of tokens
796
797=item Text::Soundex
798
5f05dabc 799implementation of the Soundex Algorithm as described by Knuth
55497cff
PP
800
801=item Text::Tabs
802
54310121 803expand and unexpand tabs per the Unix expand(1) and unexpand(1)
55497cff
PP
804
805=item Text::Wrap
806
807line wrapping to form simple paragraphs
808
809=item Tie::Hash
810
811base class definitions for tied hashes
812
5f05dabc
PP
813=item Tie::RefHash
814
815base class definitions for tied hashes with references as keys
816
55497cff
PP
817=item Tie::Scalar
818
819base class definitions for tied scalars
820
821=item Tie::SubstrHash
822
823fixed-table-size, fixed-key-length hashing
824
825=item Time::Local
826
827efficiently compute time from local and GMT time
828
5f05dabc
PP
829=item Time::gmtime
830
54310121 831by-name interface to Perl's builtin gmtime() function
5f05dabc
PP
832
833=item Time::localtime
834
54310121 835by-name interface to Perl's builtin localtime() function
5f05dabc
PP
836
837=item Time::tm
838
839internal object used by Time::gmtime and Time::localtime
840
55497cff
PP
841=item UNIVERSAL
842
843base class for ALL classes (blessed references)
844
5f05dabc
PP
845=item User::grent
846
54310121 847by-name interface to Perl's builtin getgr*() functions
5f05dabc
PP
848
849=item User::pwent
850
54310121 851by-name interface to Perl's builtin getpw*() functions
5f05dabc 852
cb1a09d0
AD
853=back
854
855To find out I<all> the modules installed on your system, including
856those without documentation or outside the standard release, do this:
a0d0e21e 857
4633a7c4 858 find `perl -e 'print "@INC"'` -name '*.pm' -print
a0d0e21e 859
4633a7c4
LW
860They should all have their own documentation installed and accessible via
861your system man(1) command. If that fails, try the I<perldoc> program.
a0d0e21e 862
4633a7c4 863=head2 Extension Modules
a0d0e21e 864
54310121
PP
865Extension modules are written in C (or a mix of Perl and C) and may be
866statically linked or in general are
4633a7c4
LW
867dynamically loaded into Perl if and when you need them. Supported
868extension modules include the Socket, Fcntl, and POSIX modules.
a0d0e21e 869
cb1a09d0 870Many popular C extension modules do not come bundled (at least, not
5f05dabc 871completely) due to their sizes, volatility, or simply lack of time for
cb1a09d0
AD
872adequate testing and configuration across the multitude of platforms on
873which Perl was beta-tested. You are encouraged to look for them in
874archie(1L), the Perl FAQ or Meta-FAQ, the WWW page, and even with their
875authors before randomly posting asking for their present condition and
876disposition.
a0d0e21e 877
cb1a09d0 878=head1 CPAN
a0d0e21e 879
4633a7c4 880CPAN stands for the Comprehensive Perl Archive Network. This is a globally
5f05dabc 881replicated collection of all known Perl materials, including hundreds
c36e9b62 882of unbundled modules. Here are the major categories of modules:
a0d0e21e 883
4633a7c4 884=over
a0d0e21e 885
4633a7c4 886=item *
5f05dabc 887Language Extensions and Documentation Tools
a0d0e21e 888
4633a7c4
LW
889=item *
890Development Support
a0d0e21e 891
4633a7c4
LW
892=item *
893Operating System Interfaces
a0d0e21e 894
4633a7c4
LW
895=item *
896Networking, Device Control (modems) and InterProcess Communication
a0d0e21e 897
4633a7c4
LW
898=item *
899Data Types and Data Type Utilities
a0d0e21e 900
4633a7c4
LW
901=item *
902Database Interfaces
a0d0e21e 903
4633a7c4
LW
904=item *
905User Interfaces
a0d0e21e 906
4633a7c4
LW
907=item *
908Interfaces to / Emulations of Other Programming Languages
a0d0e21e 909
4633a7c4
LW
910=item *
911File Names, File Systems and File Locking (see also File Handles)
a0d0e21e 912
4633a7c4 913=item *
5f05dabc 914String Processing, Language Text Processing, Parsing, and Searching
a0d0e21e 915
4633a7c4 916=item *
5f05dabc 917Option, Argument, Parameter, and Configuration File Processing
a0d0e21e 918
4633a7c4
LW
919=item *
920Internationalization and Locale
a0d0e21e 921
4633a7c4 922=item *
5f05dabc 923Authentication, Security, and Encryption
a0d0e21e 924
4633a7c4
LW
925=item *
926World Wide Web, HTML, HTTP, CGI, MIME
a0d0e21e 927
4633a7c4
LW
928=item *
929Server and Daemon Utilities
a0d0e21e 930
4633a7c4
LW
931=item *
932Archiving and Compression
a0d0e21e 933
4633a7c4 934=item *
5f05dabc 935Images, Pixmap and Bitmap Manipulation, Drawing, and Graphing
a0d0e21e 936
4633a7c4
LW
937=item *
938Mail and Usenet News
a0d0e21e 939
4633a7c4
LW
940=item *
941Control Flow Utilities (callbacks and exceptions etc)
a0d0e21e 942
4633a7c4
LW
943=item *
944File Handle and Input/Output Stream Utilities
a0d0e21e 945
4633a7c4
LW
946=item *
947Miscellaneous Modules
a0d0e21e 948
4633a7c4 949=back
a0d0e21e 950
d0c42abe 951The registered CPAN sites as of this writing include the following.
4633a7c4 952You should try to choose one close to you:
a0d0e21e 953
4633a7c4 954=over
a0d0e21e 955
4633a7c4 956=item *
9607fc9c 957Africa
a0d0e21e 958
9607fc9c 959 South Africa ftp://ftp.is.co.za/programming/perl/CPAN/
a0d0e21e 960
4633a7c4 961=item *
9607fc9c 962Asia
a0d0e21e 963
9607fc9c
PP
964 Hong Kong ftp://ftp.hkstar.com/pub/CPAN/
965 Japan ftp://ftp.jaist.ac.jp/pub/lang/perl/CPAN/
966 ftp://ftp.lab.kdd.co.jp/lang/perl/CPAN/
967 South Korea ftp://ftp.nuri.net/pub/CPAN/
968 Taiwan ftp://dongpo.math.ncu.edu.tw/perl/CPAN/
969 ftp://ftp.wownet.net/pub2/PERL/
a0d0e21e 970
4633a7c4 971=item *
9607fc9c 972Australasia
a0d0e21e 973
9607fc9c
PP
974 Australia ftp://ftp.netinfo.com.au/pub/perl/CPAN/
975 New Zealand ftp://ftp.tekotago.ac.nz/pub/perl/CPAN/
a0d0e21e 976
4633a7c4 977=item *
9607fc9c
PP
978Europe
979
980 Austria ftp://ftp.tuwien.ac.at/pub/languages/perl/CPAN/
981 Belgium ftp://ftp.kulnet.kuleuven.ac.be/pub/mirror/CPAN/
982 Czech Republic ftp://sunsite.mff.cuni.cz/Languages/Perl/CPAN/
983 Denmark ftp://sunsite.auc.dk/pub/languages/perl/CPAN/
984 Finland ftp://ftp.funet.fi/pub/languages/perl/CPAN/
985 France ftp://ftp.ibp.fr/pub/perl/CPAN/
986 ftp://ftp.pasteur.fr/pub/computing/unix/perl/CPAN/
987 Germany ftp://ftp.gmd.de/packages/CPAN/
988 ftp://ftp.leo.org/pub/comp/programming/languages/perl/CPAN/
989 ftp://ftp.mpi-sb.mpg.de/pub/perl/CPAN/
990 ftp://ftp.rz.ruhr-uni-bochum.de/pub/CPAN/
991 ftp://ftp.uni-erlangen.de/pub/source/Perl/CPAN/
992 ftp://ftp.uni-hamburg.de/pub/soft/lang/perl/CPAN/
993 Greece ftp://ftp.ntua.gr/pub/lang/perl/
994 Hungary ftp://ftp.kfki.hu/pub/packages/perl/CPAN/
995 Italy ftp://cis.utovrm.it/CPAN/
996 the Netherlands ftp://ftp.cs.ruu.nl/pub/PERL/CPAN/
997 ftp://ftp.EU.net/packages/cpan/
998 Norway ftp://ftp.uit.no/pub/languages/perl/cpan/
999 Poland ftp://ftp.pk.edu.pl/pub/lang/perl/CPAN/
1000 ftp://sunsite.icm.edu.pl/pub/CPAN/
1001 Portugal ftp://ftp.ci.uminho.pt/pub/lang/perl/
1002 ftp://ftp.telepac.pt/pub/CPAN/
1003 Russia ftp://ftp.sai.msu.su/pub/lang/perl/CPAN/
1004 Slovenia ftp://ftp.arnes.si/software/perl/CPAN/
1005 Spain ftp://ftp.etse.urv.es/pub/mirror/perl/
1006 ftp://ftp.rediris.es/mirror/CPAN/
1007 Sweden ftp://ftp.sunet.se/pub/lang/perl/CPAN/
9607fc9c
PP
1008 UK ftp://ftp.demon.co.uk/pub/mirrors/perl/CPAN/
1009 ftp://sunsite.doc.ic.ac.uk/packages/CPAN/
1010 ftp://unix.hensa.ac.uk/mirrors/perl-CPAN/
a0d0e21e 1011
4633a7c4 1012=item *
9607fc9c
PP
1013North America
1014
1015 Ontario ftp://ftp.utilis.com/public/CPAN/
1016 ftp://enterprise.ic.gc.ca/pub/perl/CPAN/
1017 Manitoba ftp://theory.uwinnipeg.ca/pub/CPAN/
1018 California ftp://ftp.digital.com/pub/plan/perl/CPAN/
30f5542a 1019 ftp://ftp.cdrom.com/pub/perl/CPAN/
9607fc9c
PP
1020 Colorado ftp://ftp.cs.colorado.edu/pub/perl/CPAN/
1021 Florida ftp://ftp.cis.ufl.edu/pub/perl/CPAN/
1022 Illinois ftp://uiarchive.uiuc.edu/pub/lang/perl/CPAN/
1023 Massachusetts ftp://ftp.iguide.com/pub/mirrors/packages/perl/CPAN/
1024 New York ftp://ftp.rge.com/pub/languages/perl/
1025 North Carolina ftp://ftp.duke.edu/pub/perl/
1026 Oklahoma ftp://ftp.ou.edu/mirrors/CPAN/
30f5542a
LV
1027 Oregon http://www.perl.org/CPAN/
1028 ftp://ftp.orst.edu/pub/packages/CPAN/
9607fc9c
PP
1029 Pennsylvania ftp://ftp.epix.net/pub/languages/perl/
1030 Texas ftp://ftp.sedl.org/pub/mirrors/CPAN/
1031 ftp://ftp.metronet.com/pub/perl/
a0d0e21e 1032
4633a7c4 1033=item *
9607fc9c 1034South America
a0d0e21e 1035
9607fc9c 1036 Chile ftp://sunsite.dcc.uchile.cl/pub/Lang/perl/CPAN/
a0d0e21e
LW
1037
1038=back
4633a7c4 1039
5f05dabc 1040For an up-to-date listing of CPAN sites,
d0c42abe 1041see F<http://www.perl.com/perl/CPAN> or F<ftp://ftp.perl.com/perl/>.
cb1a09d0 1042
5f05dabc 1043=head1 Modules: Creation, Use, and Abuse
cb1a09d0
AD
1044
1045(The following section is borrowed directly from Tim Bunce's modules
1046file, available at your nearest CPAN site.)
1047
5f05dabc 1048Perl implements a class using a package, but the presence of a
cb1a09d0
AD
1049package doesn't imply the presence of a class. A package is just a
1050namespace. A class is a package that provides subroutines that can be
1051used as methods. A method is just a subroutine that expects, as its
1052first argument, either the name of a package (for "static" methods),
1053or a reference to something (for "virtual" methods).
1054
1055A module is a file that (by convention) provides a class of the same
1056name (sans the .pm), plus an import method in that class that can be
1057called to fetch exported symbols. This module may implement some of
1058its methods by loading dynamic C or C++ objects, but that should be
1059totally transparent to the user of the module. Likewise, the module
1060might set up an AUTOLOAD function to slurp in subroutine definitions on
1061demand, but this is also transparent. Only the .pm file is required to
1062exist.
1063
1064=head2 Guidelines for Module Creation
1065
1066=over 4
1067
1068=item Do similar modules already exist in some form?
1069
1070If so, please try to reuse the existing modules either in whole or
1071by inheriting useful features into a new class. If this is not
1072practical try to get together with the module authors to work on
1073extending or enhancing the functionality of the existing modules.
1074A perfect example is the plethora of packages in perl4 for dealing
1075with command line options.
1076
1077If you are writing a module to expand an already existing set of
1078modules, please coordinate with the author of the package. It
1079helps if you follow the same naming scheme and module interaction
1080scheme as the original author.
1081
1082=item Try to design the new module to be easy to extend and reuse.
1083
1084Use blessed references. Use the two argument form of bless to bless
1085into the class name given as the first parameter of the constructor,
5f05dabc 1086e.g.,:
cb1a09d0 1087
5f05dabc 1088 sub new {
cb1a09d0
AD
1089 my $class = shift;
1090 return bless {}, $class;
1091 }
1092
1093or even this if you'd like it to be used as either a static
1094or a virtual method.
1095
5f05dabc 1096 sub new {
cb1a09d0
AD
1097 my $self = shift;
1098 my $class = ref($self) || $self;
1099 return bless {}, $class;
1100 }
1101
1102Pass arrays as references so more parameters can be added later
1103(it's also faster). Convert functions into methods where
1104appropriate. Split large methods into smaller more flexible ones.
1105Inherit methods from other modules if appropriate.
1106
c36e9b62
PP
1107Avoid class name tests like: C<die "Invalid" unless ref $ref eq 'FOO'>.
1108Generally you can delete the "C<eq 'FOO'>" part with no harm at all.
4a6725af 1109Let the objects look after themselves! Generally, avoid hard-wired
cb1a09d0
AD
1110class names as far as possible.
1111
c36e9b62
PP
1112Avoid C<$r-E<gt>Class::func()> where using C<@ISA=qw(... Class ...)> and
1113C<$r-E<gt>func()> would work (see L<perlbot> for more details).
cb1a09d0
AD
1114
1115Use autosplit so little used or newly added functions won't be a
1116burden to programs which don't use them. Add test functions to
1117the module after __END__ either using AutoSplit or by saying:
1118
1119 eval join('',<main::DATA>) || die $@ unless caller();
1120
30f5542a 1121Does your module pass the 'empty subclass' test? If you say
c36e9b62 1122"C<@SUBCLASS::ISA = qw(YOURCLASS);>" your applications should be able
cb1a09d0 1123to use SUBCLASS in exactly the same way as YOURCLASS. For example,
c36e9b62
PP
1124does your application still work if you change: C<$obj = new YOURCLASS;>
1125into: C<$obj = new SUBCLASS;> ?
cb1a09d0
AD
1126
1127Avoid keeping any state information in your packages. It makes it
1128difficult for multiple other packages to use yours. Keep state
1129information in objects.
1130
c36e9b62 1131Always use B<-w>. Try to C<use strict;> (or C<use strict qw(...);>).
cb1a09d0 1132Remember that you can add C<no strict qw(...);> to individual blocks
c36e9b62 1133of code which need less strictness. Always use B<-w>. Always use B<-w>!
cb1a09d0
AD
1134Follow the guidelines in the perlstyle(1) manual.
1135
1136=item Some simple style guidelines
1137
1138The perlstyle manual supplied with perl has many helpful points.
1139
1140Coding style is a matter of personal taste. Many people evolve their
1141style over several years as they learn what helps them write and
1142maintain good code. Here's one set of assorted suggestions that
1143seem to be widely used by experienced developers:
1144
1145Use underscores to separate words. It is generally easier to read
1146$var_names_like_this than $VarNamesLikeThis, especially for
1147non-native speakers of English. It's also a simple rule that works
1148consistently with VAR_NAMES_LIKE_THIS.
1149
1150Package/Module names are an exception to this rule. Perl informally
1151reserves lowercase module names for 'pragma' modules like integer
1152and strict. Other modules normally begin with a capital letter and
1153use mixed case with no underscores (need to be short and portable).
1154
1155You may find it helpful to use letter case to indicate the scope
1156or nature of a variable. For example:
1157
1158 $ALL_CAPS_HERE constants only (beware clashes with perl vars)
1159 $Some_Caps_Here package-wide global/static
1160 $no_caps_here function scope my() or local() variables
1161
1162Function and method names seem to work best as all lowercase.
5f05dabc 1163e.g.,, C<$obj-E<gt>as_string()>.
cb1a09d0
AD
1164
1165You can use a leading underscore to indicate that a variable or
1166function should not be used outside the package that defined it.
1167
1168=item Select what to export.
1169
1170Do NOT export method names!
1171
1172Do NOT export anything else by default without a good reason!
1173
1174Exports pollute the namespace of the module user. If you must
1175export try to use @EXPORT_OK in preference to @EXPORT and avoid
1176short or common names to reduce the risk of name clashes.
1177
1178Generally anything not exported is still accessible from outside the
c36e9b62 1179module using the ModuleName::item_name (or C<$blessed_ref-E<gt>method>)
cb1a09d0 1180syntax. By convention you can use a leading underscore on names to
5f05dabc 1181indicate informally that they are 'internal' and not for public use.
cb1a09d0
AD
1182
1183(It is actually possible to get private functions by saying:
c36e9b62 1184C<my $subref = sub { ... }; &$subref;>. But there's no way to call that
5f05dabc 1185directly as a method, because a method must have a name in the symbol
cb1a09d0
AD
1186table.)
1187
1188As a general rule, if the module is trying to be object oriented
1189then export nothing. If it's just a collection of functions then
1190@EXPORT_OK anything but use @EXPORT with caution.
1191
1192=item Select a name for the module.
1193
5f05dabc 1194This name should be as descriptive, accurate, and complete as
cb1a09d0
AD
1195possible. Avoid any risk of ambiguity. Always try to use two or
1196more whole words. Generally the name should reflect what is special
1197about what the module does rather than how it does it. Please use
5f05dabc
PP
1198nested module names to group informally or categorize a module.
1199There should be a very good reason for a module not to have a nested name.
cb1a09d0
AD
1200Module names should begin with a capital letter.
1201
1202Having 57 modules all called Sort will not make life easy for anyone
1203(though having 23 called Sort::Quick is only marginally better :-).
1204Imagine someone trying to install your module alongside many others.
1205If in any doubt ask for suggestions in comp.lang.perl.misc.
1206
1207If you are developing a suite of related modules/classes it's good
1208practice to use nested classes with a common prefix as this will
1209avoid namespace clashes. For example: Xyz::Control, Xyz::View,
1210Xyz::Model etc. Use the modules in this list as a naming guide.
1211
1212If adding a new module to a set, follow the original author's
1213standards for naming modules and the interface to methods in
1214those modules.
1215
1216To be portable each component of a module name should be limited to
54310121 121711 characters. If it might be used on MS-DOS then try to ensure each is
cb1a09d0
AD
1218unique in the first 8 characters. Nested modules make this easier.
1219
1220=item Have you got it right?
1221
1222How do you know that you've made the right decisions? Have you
1223picked an interface design that will cause problems later? Have
1224you picked the most appropriate name? Do you have any questions?
1225
1226The best way to know for sure, and pick up many helpful suggestions,
1227is to ask someone who knows. Comp.lang.perl.misc is read by just about
1228all the people who develop modules and it's the best place to ask.
1229
1230All you need to do is post a short summary of the module, its
1231purpose and interfaces. A few lines on each of the main methods is
1232probably enough. (If you post the whole module it might be ignored
1233by busy people - generally the very people you want to read it!)
1234
1235Don't worry about posting if you can't say when the module will be
1236ready - just say so in the message. It might be worth inviting
1237others to help you, they may be able to complete it for you!
1238
1239=item README and other Additional Files.
1240
1241It's well known that software developers usually fully document the
1242software they write. If, however, the world is in urgent need of
1243your software and there is not enough time to write the full
1244documentation please at least provide a README file containing:
1245
1246=over 10
1247
1248=item *
1249A description of the module/package/extension etc.
1250
1251=item *
1252A copyright notice - see below.
1253
1254=item *
1255Prerequisites - what else you may need to have.
1256
1257=item *
1258How to build it - possible changes to Makefile.PL etc.
1259
1260=item *
1261How to install it.
1262
1263=item *
1264Recent changes in this release, especially incompatibilities
1265
1266=item *
1267Changes / enhancements you plan to make in the future.
1268
1269=back
1270
1271If the README file seems to be getting too large you may wish to
1272split out some of the sections into separate files: INSTALL,
1273Copying, ToDo etc.
1274
d0c42abe
PP
1275=over 4
1276
cb1a09d0
AD
1277=item Adding a Copyright Notice.
1278
5f05dabc 1279How you choose to license your work is a personal decision.
cb1a09d0
AD
1280The general mechanism is to assert your Copyright and then make
1281a declaration of how others may copy/use/modify your work.
1282
54310121
PP
1283Perl, for example, is supplied with two types of licence: The GNU
1284GPL and The Artistic Licence (see the files README, Copying, and
cb1a09d0
AD
1285Artistic). Larry has good reasons for NOT just using the GNU GPL.
1286
5f05dabc
PP
1287My personal recommendation, out of respect for Larry, Perl, and the
1288perl community at large is to state something simply like:
cb1a09d0
AD
1289
1290 Copyright (c) 1995 Your Name. All rights reserved.
1291 This program is free software; you can redistribute it and/or
1292 modify it under the same terms as Perl itself.
1293
1294This statement should at least appear in the README file. You may
1295also wish to include it in a Copying file and your source files.
1296Remember to include the other words in addition to the Copyright.
1297
1298=item Give the module a version/issue/release number.
1299
1300To be fully compatible with the Exporter and MakeMaker modules you
1301should store your module's version number in a non-my package
5f05dabc
PP
1302variable called $VERSION. This should be a floating point
1303number with at least two digits after the decimal (i.e., hundredths,
c36e9b62 1304e.g, C<$VERSION = "0.01">). Don't use a "1.3.2" style version.
cb1a09d0
AD
1305See Exporter.pm in Perl5.001m or later for details.
1306
1307It may be handy to add a function or method to retrieve the number.
1308Use the number in announcements and archive file names when
1309releasing the module (ModuleName-1.02.tar.Z).
1310See perldoc ExtUtils::MakeMaker.pm for details.
1311
1312=item How to release and distribute a module.
1313
1314It's good idea to post an announcement of the availability of your
1315module (or the module itself if small) to the comp.lang.perl.announce
1316Usenet newsgroup. This will at least ensure very wide once-off
1317distribution.
1318
1319If possible you should place the module into a major ftp archive and
5f05dabc 1320include details of its location in your announcement.
cb1a09d0
AD
1321
1322Some notes about ftp archives: Please use a long descriptive file
1323name which includes the version number. Most incoming directories
1324will not be readable/listable, i.e., you won't be able to see your
1325file after uploading it. Remember to send your email notification
1326message as soon as possible after uploading else your file may get
1327deleted automatically. Allow time for the file to be processed
1328and/or check the file has been processed before announcing its
1329location.
1330
1331FTP Archives for Perl Modules:
1332
1333Follow the instructions and links on
1334
1335 http://franz.ww.tu-berlin.de/modulelist
1336
5f05dabc 1337or upload to one of these sites:
cb1a09d0
AD
1338
1339 ftp://franz.ww.tu-berlin.de/incoming
5f05dabc 1340 ftp://ftp.cis.ufl.edu/incoming
cb1a09d0 1341
9607fc9c 1342and notify <F<upload@franz.ww.tu-berlin.de>>.
cb1a09d0
AD
1343
1344By using the WWW interface you can ask the Upload Server to mirror
1345your modules from your ftp or WWW site into your own directory on
1346CPAN!
1347
1348Please remember to send me an updated entry for the Module list!
1349
1350=item Take care when changing a released module.
1351
1352Always strive to remain compatible with previous released versions
1353(see 2.2 above) Otherwise try to add a mechanism to revert to the
1354old behaviour if people rely on it. Document incompatible changes.
1355
1356=back
1357
d0c42abe
PP
1358=back
1359
cb1a09d0
AD
1360=head2 Guidelines for Converting Perl 4 Library Scripts into Modules
1361
1362=over 4
1363
1364=item There is no requirement to convert anything.
1365
1366If it ain't broke, don't fix it! Perl 4 library scripts should
1367continue to work with no problems. You may need to make some minor
1368changes (like escaping non-array @'s in double quoted strings) but
1369there is no need to convert a .pl file into a Module for just that.
1370
1371=item Consider the implications.
1372
1373All the perl applications which make use of the script will need to
1374be changed (slightly) if the script is converted into a module. Is
1375it worth it unless you plan to make other changes at the same time?
1376
1377=item Make the most of the opportunity.
1378
1379If you are going to convert the script to a module you can use the
1380opportunity to redesign the interface. The 'Guidelines for Module
1381Creation' above include many of the issues you should consider.
1382
1383=item The pl2pm utility will get you started.
1384
1385This utility will read *.pl files (given as parameters) and write
1386corresponding *.pm files. The pl2pm utilities does the following:
1387
1388=over 10
1389
1390=item *
1391Adds the standard Module prologue lines
1392
1393=item *
1394Converts package specifiers from ' to ::
1395
1396=item *
1397Converts die(...) to croak(...)
1398
1399=item *
1400Several other minor changes
1401
1402=back
1403
1404Being a mechanical process pl2pm is not bullet proof. The converted
1405code will need careful checking, especially any package statements.
1406Don't delete the original .pl file till the new .pm one works!
1407
1408=back
1409
1410=head2 Guidelines for Reusing Application Code
1411
1412=over 4
1413
1414=item Complete applications rarely belong in the Perl Module Library.
1415
1416=item Many applications contain some perl code which could be reused.
1417
1418Help save the world! Share your code in a form that makes it easy
1419to reuse.
1420
1421=item Break-out the reusable code into one or more separate module files.
1422
1423=item Take the opportunity to reconsider and redesign the interfaces.
1424
1425=item In some cases the 'application' can then be reduced to a small
1426
1427fragment of code built on top of the reusable modules. In these cases
1428the application could invoked as:
1429
1430 perl -e 'use Module::Name; method(@ARGV)' ...
5f05dabc 1431or
3fe9a6f1 1432 perl -mModule::Name ... (in perl5.002 or higher)
cb1a09d0
AD
1433
1434=back