This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Sort MANIFEST.
[perl5.git] / pod / perlmodlib.PL
CommitLineData
2e1d04bc
JH
1#!../miniperl
2
3open (OUT, ">perlmodlib.tmp") or die $!;
4my (@pragma, @mod);
5open (MANIFEST, "../MANIFEST") or die $!;
6
7while (<MANIFEST>) {
8 my $filename;
9 next unless s|^lib/|| or m|^ext/|;
10 ($filename) = /(\S+)/;
11 $filename =~ s|^[^/]+/|| if $filename =~ s|^ext/||;
12 next unless $filename =~ /\.pm$/;
13 next unless open (MOD, "../lib/$filename");
14 my ($name, $thing);
15 my $foundit=0;
16 {local $/="";
17 while (<MOD>) {
18 next unless /^=head1 NAME/;
19 $foundit++;
20 last;
21 }
22 }
23 next unless $foundit;
24 my $title = <MOD>;
25 chomp($title);
26 close MOD;
27
28 my $perlname = $filename;
29 $perlname =~ s|\.pm$||;
30 $perlname =~ s|/|::|g;
31
32 ($name, $thing) = split / - /, $title,2;
33 next unless $name and $thing;
34 $thing=~s/^perl pragma to //i;
35 $thing=ucfirst($thing);
36 $title = "=item $perlname\n\n$thing\n\n";
37
38 if ($filename=~/[A-Z]/) {
39 push @mod, $title;
40 } else {
41 push @pragma, $title;
42 }
43}
44
45print OUT <<'EOF';
843dbe26
MS
46# Generated by perlmodlib.PL DO NOT EDIT!
47
2e1d04bc
JH
48=head1 NAME
49
50perlmodlib - constructing new Perl modules and finding existing ones
51
52=head1 DESCRIPTION
53
54=head1 THE PERL MODULE LIBRARY
55
56Many modules are included the Perl distribution. These are described
57below, and all end in F<.pm>. You may discover compiled library
58file (usually ending in F<.so>) or small pieces of modules to be
59autoloaded (ending in F<.al>); these were automatically generated
60by the installation process. You may also discover files in the
61library directory that end in either F<.pl> or F<.ph>. These are
62old libraries supplied so that old programs that use them still
63run. The F<.pl> files will all eventually be converted into standard
64modules, and the F<.ph> files made by B<h2ph> will probably end up
65as extension modules made by B<h2xs>. (Some F<.ph> values may
66already be available through the POSIX, Errno, or Fcntl modules.)
67The B<pl2pm> file in the distribution may help in your conversion,
68but it's just a mechanical process and therefore far from bulletproof.
69
70=head2 Pragmatic Modules
71
72They work somewhat like compiler directives (pragmata) in that they
73tend to affect the compilation of your program, and thus will usually
74work well only when used within a C<use>, or C<no>. Most of these
75are lexically scoped, so an inner BLOCK may countermand them
76by saying:
77
78 no integer;
79 no strict 'refs';
80 no warnings;
81
82which lasts until the end of that BLOCK.
83
84Some pragmas are lexically scoped--typically those that affect the
85C<$^H> hints variable. Others affect the current package instead,
86like C<use vars> and C<use subs>, which allow you to predeclare a
87variables or subroutines within a particular I<file> rather than
88just a block. Such declarations are effective for the entire file
89for which they were declared. You cannot rescind them with C<no
90vars> or C<no subs>.
91
92The following pragmas are defined (and have their own documentation).
93
94=over 12
95
96EOF
97
98print OUT $_ for (sort @pragma);
99
100print OUT <<EOF;
101=back
102
103=head2 Standard Modules
104
105Standard, bundled modules are all expected to behave in a well-defined
106manner with respect to namespace pollution because they use the
107Exporter module. See their own documentation for details.
108
109=over 12
110
111EOF
112
113print OUT $_ for (sort @mod);
114
115print OUT <<'EOF';
116=back
117
118To find out I<all> modules installed on your system, including
119those without documentation or outside the standard release,
309a139e 120just do this:
2e1d04bc
JH
121
122 % find `perl -e 'print "@INC"'` -name '*.pm' -print
123
124They should all have their own documentation installed and accessible
125via your system man(1) command. If you do not have a B<find>
126program, you can use the Perl B<find2perl> program instead, which
127generates Perl code as output you can run through perl. If you
128have a B<man> program but it doesn't find your modules, you'll have
129to fix your manpath. See L<perl> for details. If you have no
130system B<man> command, you might try the B<perldoc> program.
131
132=head2 Extension Modules
133
134Extension modules are written in C (or a mix of Perl and C). They
135are usually dynamically loaded into Perl if and when you need them,
136but may also be be linked in statically. Supported extension modules
137include Socket, Fcntl, and POSIX.
138
139Many popular C extension modules do not come bundled (at least, not
140completely) due to their sizes, volatility, or simply lack of time
141for adequate testing and configuration across the multitude of
142platforms on which Perl was beta-tested. You are encouraged to
143look for them on CPAN (described below), or using web search engines
144like Alta Vista or Deja News.
145
146=head1 CPAN
147
148CPAN stands for Comprehensive Perl Archive Network; it's a globally
149replicated trove of Perl materials, including documentation, style
150guides, tricks and traps, alternate ports to non-Unix systems and
151occasional binary distributions for these. Search engines for
152CPAN can be found at http://cpan.perl.com/ and at
153http://theory.uwinnipeg.ca/mod_perl/cpan-search.pl .
154
155Most importantly, CPAN includes around a thousand unbundled modules,
156some of which require a C compiler to build. Major categories of
157modules are:
158
159=over
160
161=item *
ac634a9a 162
2e1d04bc
JH
163Language Extensions and Documentation Tools
164
165=item *
ac634a9a 166
2e1d04bc
JH
167Development Support
168
169=item *
ac634a9a 170
2e1d04bc
JH
171Operating System Interfaces
172
173=item *
ac634a9a 174
2e1d04bc
JH
175Networking, Device Control (modems) and InterProcess Communication
176
177=item *
ac634a9a 178
2e1d04bc
JH
179Data Types and Data Type Utilities
180
181=item *
ac634a9a 182
2e1d04bc
JH
183Database Interfaces
184
185=item *
ac634a9a 186
2e1d04bc
JH
187User Interfaces
188
189=item *
ac634a9a 190
2e1d04bc
JH
191Interfaces to / Emulations of Other Programming Languages
192
193=item *
ac634a9a 194
2e1d04bc
JH
195File Names, File Systems and File Locking (see also File Handles)
196
197=item *
ac634a9a 198
2e1d04bc
JH
199String Processing, Language Text Processing, Parsing, and Searching
200
201=item *
ac634a9a 202
2e1d04bc
JH
203Option, Argument, Parameter, and Configuration File Processing
204
205=item *
ac634a9a 206
2e1d04bc
JH
207Internationalization and Locale
208
209=item *
ac634a9a 210
2e1d04bc
JH
211Authentication, Security, and Encryption
212
213=item *
ac634a9a 214
2e1d04bc
JH
215World Wide Web, HTML, HTTP, CGI, MIME
216
217=item *
ac634a9a 218
2e1d04bc
JH
219Server and Daemon Utilities
220
221=item *
ac634a9a 222
2e1d04bc
JH
223Archiving and Compression
224
225=item *
ac634a9a 226
2e1d04bc
JH
227Images, Pixmap and Bitmap Manipulation, Drawing, and Graphing
228
229=item *
ac634a9a 230
2e1d04bc
JH
231Mail and Usenet News
232
233=item *
ac634a9a 234
2e1d04bc
JH
235Control Flow Utilities (callbacks and exceptions etc)
236
237=item *
ac634a9a 238
2e1d04bc
JH
239File Handle and Input/Output Stream Utilities
240
241=item *
ac634a9a 242
2e1d04bc
JH
243Miscellaneous Modules
244
245=back
246
247Registered CPAN sites as of this writing include the following.
248You should try to choose one close to you:
249
250=over
251
252=item Africa
253
843dbe26
MS
254 South Africa ftp://ftp.is.co.za/programming/perl/CPAN/
255 ftp://ftp.saix.net/pub/CPAN/
256 ftp://ftpza.co.za/pub/mirrors/cpan/
257 ftp://ftp.sun.ac.za/CPAN/
2e1d04bc
JH
258
259=item Asia
260
843dbe26
MS
261 China ftp://freesoft.cei.gov.cn/pub/languages/perl/CPAN/
262 http://www2.linuxforum.net/mirror/CPAN/
263 Hong Kong http://CPAN.pacific.net.hk/
264 ftp://ftp.pacific.net.hk/pub/mirror/CPAN/
265 Indonesia http://piksi.itb.ac.id/CPAN/
266 ftp://mirrors.piksi.itb.ac.id/CPAN/
267 http://CPAN.mweb.co.id/
268 ftp://ftp.mweb.co.id/pub/languages/perl/CPAN/
269 Israel http://www.iglu.org.il:/pub/CPAN/
270 ftp://ftp.iglu.org.il/pub/CPAN/
271 http://bioinfo.weizmann.ac.il/pub/software/perl/CPAN/
272 ftp://bioinfo.weizmann.ac.il/pub/software/perl/CPAN/
273 Japan ftp://ftp.u-aizu.ac.jp/pub/lang/perl/CPAN/
274 ftp://ftp.kddlabs.co.jp/CPAN/
275 http://mirror.nucba.ac.jp/mirror/Perl/
276 ftp://mirror.nucba.ac.jp/mirror/Perl/
277 ftp://ftp.meisei-u.ac.jp/pub/CPAN/
278 ftp://ftp.jaist.ac.jp/pub/lang/perl/CPAN/
279 ftp://ftp.dti.ad.jp/pub/lang/CPAN/
280 ftp://ftp.ring.gr.jp/pub/lang/perl/CPAN/
281 Saudi Arabia ftp://ftp.isu.net.sa/pub/CPAN/
282 Singapore http://ftp.nus.edu.sg/unix/perl/CPAN/
283 ftp://ftp.nus.edu.sg/pub/unix/perl/CPAN/
284 South Korea http://CPAN.bora.net/
285 ftp://ftp.bora.net/pub/CPAN/
286 http://ftp.kornet.net/CPAN/
287 ftp://ftp.kornet.net/pub/CPAN/
288 ftp://ftp.nuri.net/pub/CPAN/
289 Taiwan ftp://coda.nctu.edu.tw/computer-languages/perl/CPAN/
290 ftp://ftp.ee.ncku.edu.tw/pub/perl/CPAN/
291 ftp://ftp1.sinica.edu.tw/pub1/perl/CPAN/
292 Thailand http://download.nectec.or.th/CPAN/
293 ftp://ftp.nectec.or.th/pub/languages/CPAN/
294 ftp://ftp.cs.riubon.ac.th/pub/mirrors/CPAN/
2e1d04bc
JH
295
296=item Central America
297
843dbe26
MS
298 Costa Rica ftp://ftp.linux.co.cr/mirrors/CPAN/
299 http://ftp.ucr.ac.cr/Unix/CPAN/
300 ftp://ftp.ucr.ac.cr/pub/Unix/CPAN/
2e1d04bc
JH
301
302=item Europe
303
843dbe26
MS
304 Austria ftp://ftp.tuwien.ac.at/pub/languages/perl/CPAN/
305 Belgium http://ftp.easynet.be/CPAN/
306 ftp://ftp.easynet.be/CPAN/
307 ftp://ftp.kulnet.kuleuven.ac.be/pub/mirror/CPAN/
308 Bulgaria ftp://ftp.ntrl.net/pub/mirrors/CPAN/
309 Croatia ftp://ftp.linux.hr/pub/CPAN/
310 Czech Republic http://www.fi.muni.cz/pub/perl/
311 ftp://ftp.fi.muni.cz/pub/perl/
312 ftp://sunsite.mff.cuni.cz/MIRRORS/ftp.funet.fi/pub/languages/perl/CPAN/
313 Denmark ftp://sunsite.auc.dk/pub/languages/perl/CPAN/
314 http://www.cpan.dk/CPAN/
315 England http://www.mirror.ac.uk/sites/ftp.funet.fi/pub/languages/perl/CPAN
316 ftp://ftp.mirror.ac.uk/sites/ftp.funet.fi/pub/languages/perl/CPAN/
317 ftp://ftp.demon.co.uk/pub/mirrors/perl/CPAN/
318 ftp://ftp.flirble.org/pub/languages/perl/CPAN/
319 ftp://ftp.plig.org/pub/CPAN/
320 ftp://sunsite.doc.ic.ac.uk/packages/CPAN/
321 http://mirror.uklinux.net/CPAN/
322 ftp://mirror.uklinux.net/pub/CPAN/
323 ftp://usit.shef.ac.uk/pub/packages/CPAN/
324 Estonia ftp://ftp.ut.ee/pub/languages/perl/CPAN/
325 Finland ftp://ftp.funet.fi/pub/languages/perl/CPAN/
326 France ftp://cpan.ftp.worldonline.fr/pub/CPAN/
327 ftp://ftp.club-internet.fr/pub/perl/CPAN/
328 ftp://ftp.lip6.fr/pub/perl/CPAN/
329 ftp://ftp.oleane.net/pub/mirrors/CPAN/
330 ftp://ftp.pasteur.fr/pub/computing/CPAN/
331 ftp://cpan.cict.fr/pub/CPAN/
332 ftp://ftp.uvsq.fr/pub/perl/CPAN/
333 Germany ftp://ftp.rz.ruhr-uni-bochum.de/pub/CPAN/
334 ftp://ftp.freenet.de/pub/ftp.cpan.org/pub/CPAN/
335 ftp://ftp.uni-erlangen.de/pub/source/CPAN/
336 ftp://ftp-stud.fht-esslingen.de/pub/Mirrors/CPAN
337 ftp://ftp.gigabell.net/pub/CPAN/
338 http://ftp.gwdg.de/pub/languages/perl/CPAN/
339 ftp://ftp.gwdg.de/pub/languages/perl/CPAN/
340 ftp://ftp.uni-hamburg.de/pub/soft/lang/perl/CPAN/
341 ftp://ftp.leo.org/pub/comp/general/programming/languages/script/perl/CPAN/
342 ftp://ftp.mpi-sb.mpg.de/pub/perl/CPAN/
343 ftp://ftp.gmd.de/packages/CPAN/
344 Greece ftp://ftp.ntua.gr/pub/lang/perl/
345 Hungary http://cpan.artifact.hu/
346 ftp://cpan.artifact.hu/CPAN/
347 ftp://ftp.kfki.hu/pub/packages/perl/CPAN/
348 Iceland http://cpan.gm.is/
349 ftp://ftp.gm.is/pub/CPAN/
350 Ireland http://cpan.indigo.ie/
351 ftp://cpan.indigo.ie/pub/CPAN/
352 http://sunsite.compapp.dcu.ie/pub/perl/
353 ftp://sunsite.compapp.dcu.ie/pub/perl/
354 Italy http://cpan.nettuno.it/
355 http://softcity.iol.it/cpan
356 ftp://softcity.iol.it/pub/cpan
357 ftp://ftp.unina.it/pub/Other/CPAN/
358 ftp://ftp.unipi.it/pub/mirror/perl/CPAN/
359 ftp://cis.uniRoma2.it/CPAN/
360 ftp://ftp.edisontel.it/pub/CPAN_Mirror/
361 ftp://ftp.flashnet.it/pub/CPAN/
362 Latvia http://kvin.lv/pub/CPAN/
363 Netherlands ftp://download.xs4all.nl/pub/mirror/CPAN/
364 ftp://ftp.nl.uu.net/pub/CPAN/
365 ftp://ftp.cpan.nl/pub/CPAN/
366 ftp://ftp.nluug.nl/pub/languages/perl/CPAN/
367 http://www.cs.uu.nl/mirror/CPAN/
368 ftp://ftp.cs.uu.nl/mirror/CPAN/
369 Norway ftp://sunsite.uio.no/pub/languages/perl/CPAN/
370 ftp://ftp.uit.no/pub/languages/perl/cpan/
371 Poland ftp://ftp.pk.edu.pl/pub/lang/perl/CPAN/
372 ftp://ftp.mega.net.pl/pub/mirrors/ftp.perl.com/
373 ftp://ftp.man.torun.pl/pub/doc/CPAN/
374 ftp://sunsite.icm.edu.pl/pub/CPAN/
375 Portugal ftp://ftp.ua.pt/pub/CPAN/
376 ftp://perl.di.uminho.pt/pub/CPAN/
377 ftp://ftp.ist.utl.pt/pub/CPAN/
378 ftp://ftp.netc.pt/pub/CPAN/
379 Romania ftp://archive.logicnet.ro/mirrors/ftp.cpan.org/CPAN/
380 ftp://ftp.kappa.ro/pub/mirrors/ftp.perl.org/pub/CPAN/
381 ftp://ftp.dntis.ro/pub/cpan/
382 ftp://ftp.opsynet.com/cpan/
383 ftp://ftp.dnttm.ro/pub/CPAN/
384 Russia ftp://ftp.chg.ru/pub/lang/perl/CPAN/
385 http://cpan.rinet.ru/
386 ftp://cpan.rinet.ru/pub/mirror/CPAN/
387 ftp://ftp.aha.ru/pub/CPAN/
388 ftp://ftp.sai.msu.su/pub/lang/perl/CPAN/
389 Slovakia ftp://ftp.entry.sk/pub/languages/perl/CPAN/
390 Slovenia ftp://ftp.arnes.si/software/perl/CPAN/
391 Spain ftp://ftp.rediris.es/mirror/CPAN/
392 ftp://ftp.etse.urv.es/pub/perl/
393 Sweden http://ftp.du.se/CPAN/
394 ftp://ftp.du.se/pub/CPAN/
395 ftp://ftp.sunet.se/pub/lang/perl/CPAN/
396 Switzerland ftp://ftp.danyk.ch/CPAN/
397 ftp://sunsite.cnlab-switch.ch/mirror/CPAN/
398 Turkey ftp://sunsite.bilkent.edu.tr/pub/languages/CPAN/
2e1d04bc
JH
399
400=item North America
401
843dbe26
MS
402 Alberta http://sunsite.ualberta.ca/pub/Mirror/CPAN/
403 ftp://sunsite.ualberta.ca/pub/Mirror/CPAN/
404 Alabama http://mirror.hiwaay.net/CPAN/
405 ftp://mirror.hiwaay.net/CPAN/
406 California http://www.cpan.org/
407 ftp://ftp.cpan.org/CPAN/
408 ftp://cpan.nas.nasa.gov/pub/perl/CPAN/
409 ftp://ftp.digital.com/pub/plan/perl/CPAN/
410 http://www.kernel.org/pub/mirrors/cpan/
411 ftp://ftp.kernel.org/pub/mirrors/cpan/
412 http://www.perl.com/CPAN/
413 http://download.sourceforge.net/mirrors/CPAN/
414 Colorado ftp://ftp.cs.colorado.edu/pub/perl/CPAN/
415 Florida ftp://ftp.cise.ufl.edu/pub/perl/CPAN/
416 Georgia ftp://ftp.twoguys.org/CPAN/
417 Illinois http://www.neurogames.com/mirrors/CPAN
418 Indiana ftp://ftp.uwsg.indiana.edu/pub/perl/CPAN/
419 http://cpan.nitco.com/
420 ftp://cpan.nitco.com/pub/CPAN/
421 ftp://cpan.in-span.net/
422 http://csociety-ftp.ecn.purdue.edu/pub/CPAN
423 ftp://csociety-ftp.ecn.purdue.edu/pub/CPAN
424 Manitoba http://theoryx5.uwinnipeg.ca/pub/CPAN/
425 ftp://theoryx5.uwinnipeg.ca/pub/CPAN/
426 Massachusetts ftp://ftp.ccs.neu.edu/net/mirrors/ftp.funet.fi/pub/languages/perl/CPAN/
427 ftp://ftp.iguide.com/pub/mirrors/packages/perl/CPAN/
428 Mexico http://www.msg.com.mx/CPAN/
429 ftp://ftp.msg.com.mx/pub/CPAN/
430 New Jersey ftp://ftp.cpanel.net/pub/CPAN/
431 New York ftp://ftp.freesoftware.com/pub/perl/CPAN/
432 http://www.deao.net/mirrors/CPAN/
433 ftp://ftp.deao.net/pub/CPAN/
434 ftp://ftp.stealth.net/pub/mirrors/ftp.cpan.org/pub/CPAN/
435 http://mirror.nyc.anidea.com/CPAN/
436 ftp://mirror.nyc.anidea.com/pub/CPAN/
437 http://www.rge.com/pub/languages/perl/
438 ftp://ftp.rge.com/pub/languages/perl/
439 ftp://mirrors.cloud9.net/pub/mirrors/CPAN/
440 North Carolina ftp://ftp.duke.edu/pub/perl/
441 Nova Scotia ftp://cpan.chebucto.ns.ca/pub/CPAN/
442 Ohio ftp://ftp.loaded.net/pub/CPAN/
443 Oklahoma ftp://ftp.ou.edu/mirrors/CPAN/
444 Ontario ftp://ftp.crc.ca/pub/packages/lang/perl/CPAN/
445 Oregon ftp://ftp.orst.edu/pub/packages/CPAN/
446 Pennsylvania http://ftp.epix.net/CPAN/
447 ftp://ftp.epix.net/pub/languages/perl/
448 ftp://carroll.cac.psu.edu/pub/CPAN/
449 Tennessee ftp://ftp.sunsite.utk.edu/pub/CPAN/
450 Texas http://ftp.sedl.org/pub/mirrors/CPAN/
451 http://jhcloos.com/pub/mirror/CPAN/
452 ftp://jhcloos.com/pub/mirror/CPAN/
453 Utah ftp://mirror.xmission.com/CPAN/
454 Virginia http://mirrors.rcn.net/pub/lang/CPAN/
455 ftp://mirrors.rcn.net/pub/lang/CPAN/
456 ftp://ruff.cs.jmu.edu/pub/CPAN/
457 Washington http://cpan.llarian.net/
458 ftp://cpan.llarian.net/pub/CPAN/
459 ftp://ftp-mirror.internap.com/pub/CPAN/
460 ftp://ftp.spu.edu/pub/CPAN/
461
462=item Oceania
463
464 Australia http://ftp.planetmirror.com/pub/CPAN/
465 ftp://ftp.planetmirror.com/pub/CPAN/
466 ftp://mirror.aarnet.edu.au/pub/perl/CPAN/
467 ftp://cpan.topend.com.au/pub/CPAN/
468 New Zealand ftp://ftp.auckland.ac.nz/pub/perl/CPAN/
2e1d04bc
JH
469
470=item South America
471
843dbe26
MS
472 Argentina ftp://mirrors.bannerlandia.com.ar/mirrors/CPAN/
473 Brazil ftp://cpan.pop-mg.com.br/pub/CPAN/
474 ftp://ftp.matrix.com.br/pub/perl/
475 ftp://cpan.if.usp.br/pub/mirror/CPAN/
476 Chile ftp://ftp.psinet.cl/pub/programming/perl/CPAN/
477 ftp://sunsite.dcc.uchile.cl/pub/lang/perl/
2e1d04bc
JH
478
479=back
480
481For an up-to-date listing of CPAN sites,
482see http://www.perl.com/perl/CPAN/SITES or ftp://www.perl.com/CPAN/SITES .
483
484=head1 Modules: Creation, Use, and Abuse
485
486(The following section is borrowed directly from Tim Bunce's modules
487file, available at your nearest CPAN site.)
488
489Perl implements a class using a package, but the presence of a
490package doesn't imply the presence of a class. A package is just a
491namespace. A class is a package that provides subroutines that can be
492used as methods. A method is just a subroutine that expects, as its
493first argument, either the name of a package (for "static" methods),
494or a reference to something (for "virtual" methods).
495
496A module is a file that (by convention) provides a class of the same
497name (sans the .pm), plus an import method in that class that can be
498called to fetch exported symbols. This module may implement some of
499its methods by loading dynamic C or C++ objects, but that should be
500totally transparent to the user of the module. Likewise, the module
501might set up an AUTOLOAD function to slurp in subroutine definitions on
502demand, but this is also transparent. Only the F<.pm> file is required to
503exist. See L<perlsub>, L<perltoot>, and L<AutoLoader> for details about
504the AUTOLOAD mechanism.
505
506=head2 Guidelines for Module Creation
507
508=over 4
509
ac634a9a
JH
510=item *
511
512Do similar modules already exist in some form?
2e1d04bc
JH
513
514If so, please try to reuse the existing modules either in whole or
515by inheriting useful features into a new class. If this is not
516practical try to get together with the module authors to work on
517extending or enhancing the functionality of the existing modules.
518A perfect example is the plethora of packages in perl4 for dealing
519with command line options.
520
521If you are writing a module to expand an already existing set of
522modules, please coordinate with the author of the package. It
523helps if you follow the same naming scheme and module interaction
524scheme as the original author.
525
ac634a9a
JH
526=item *
527
528Try to design the new module to be easy to extend and reuse.
2e1d04bc
JH
529
530Try to C<use warnings;> (or C<use warnings qw(...);>).
531Remember that you can add C<no warnings qw(...);> to individual blocks
532of code that need less warnings.
533
534Use blessed references. Use the two argument form of bless to bless
535into the class name given as the first parameter of the constructor,
536e.g.,:
537
538 sub new {
539 my $class = shift;
540 return bless {}, $class;
541 }
542
543or even this if you'd like it to be used as either a static
544or a virtual method.
545
546 sub new {
547 my $self = shift;
548 my $class = ref($self) || $self;
549 return bless {}, $class;
550 }
551
552Pass arrays as references so more parameters can be added later
553(it's also faster). Convert functions into methods where
554appropriate. Split large methods into smaller more flexible ones.
555Inherit methods from other modules if appropriate.
556
557Avoid class name tests like: C<die "Invalid" unless ref $ref eq 'FOO'>.
558Generally you can delete the C<eq 'FOO'> part with no harm at all.
559Let the objects look after themselves! Generally, avoid hard-wired
560class names as far as possible.
561
562Avoid C<< $r->Class::func() >> where using C<@ISA=qw(... Class ...)> and
563C<< $r->func() >> would work (see L<perlbot> for more details).
564
565Use autosplit so little used or newly added functions won't be a
566burden to programs that don't use them. Add test functions to
567the module after __END__ either using AutoSplit or by saying:
568
569 eval join('',<main::DATA>) || die $@ unless caller();
570
571Does your module pass the 'empty subclass' test? If you say
572C<@SUBCLASS::ISA = qw(YOURCLASS);> your applications should be able
573to use SUBCLASS in exactly the same way as YOURCLASS. For example,
574does your application still work if you change: C<$obj = new YOURCLASS;>
575into: C<$obj = new SUBCLASS;> ?
576
577Avoid keeping any state information in your packages. It makes it
578difficult for multiple other packages to use yours. Keep state
579information in objects.
580
581Always use B<-w>.
582
583Try to C<use strict;> (or C<use strict qw(...);>).
584Remember that you can add C<no strict qw(...);> to individual blocks
585of code that need less strictness.
586
587Always use B<-w>.
588
589Follow the guidelines in the perlstyle(1) manual.
590
591Always use B<-w>.
592
ac634a9a
JH
593=item *
594
595Some simple style guidelines
2e1d04bc
JH
596
597The perlstyle manual supplied with Perl has many helpful points.
598
599Coding style is a matter of personal taste. Many people evolve their
600style over several years as they learn what helps them write and
601maintain good code. Here's one set of assorted suggestions that
602seem to be widely used by experienced developers:
603
604Use underscores to separate words. It is generally easier to read
605$var_names_like_this than $VarNamesLikeThis, especially for
606non-native speakers of English. It's also a simple rule that works
607consistently with VAR_NAMES_LIKE_THIS.
608
609Package/Module names are an exception to this rule. Perl informally
610reserves lowercase module names for 'pragma' modules like integer
611and strict. Other modules normally begin with a capital letter and
612use mixed case with no underscores (need to be short and portable).
613
614You may find it helpful to use letter case to indicate the scope
615or nature of a variable. For example:
616
617 $ALL_CAPS_HERE constants only (beware clashes with Perl vars)
618 $Some_Caps_Here package-wide global/static
619 $no_caps_here function scope my() or local() variables
620
621Function and method names seem to work best as all lowercase.
622e.g., C<< $obj->as_string() >>.
623
624You can use a leading underscore to indicate that a variable or
625function should not be used outside the package that defined it.
626
ac634a9a
JH
627=item *
628
629Select what to export.
2e1d04bc
JH
630
631Do NOT export method names!
632
633Do NOT export anything else by default without a good reason!
634
635Exports pollute the namespace of the module user. If you must
636export try to use @EXPORT_OK in preference to @EXPORT and avoid
637short or common names to reduce the risk of name clashes.
638
639Generally anything not exported is still accessible from outside the
640module using the ModuleName::item_name (or C<< $blessed_ref->method >>)
641syntax. By convention you can use a leading underscore on names to
642indicate informally that they are 'internal' and not for public use.
643
644(It is actually possible to get private functions by saying:
645C<my $subref = sub { ... }; &$subref;>. But there's no way to call that
646directly as a method, because a method must have a name in the symbol
647table.)
648
649As a general rule, if the module is trying to be object oriented
650then export nothing. If it's just a collection of functions then
651@EXPORT_OK anything but use @EXPORT with caution.
652
ac634a9a
JH
653=item *
654
655Select a name for the module.
2e1d04bc
JH
656
657This name should be as descriptive, accurate, and complete as
658possible. Avoid any risk of ambiguity. Always try to use two or
659more whole words. Generally the name should reflect what is special
660about what the module does rather than how it does it. Please use
661nested module names to group informally or categorize a module.
662There should be a very good reason for a module not to have a nested name.
663Module names should begin with a capital letter.
664
665Having 57 modules all called Sort will not make life easy for anyone
666(though having 23 called Sort::Quick is only marginally better :-).
667Imagine someone trying to install your module alongside many others.
668If in any doubt ask for suggestions in comp.lang.perl.misc.
669
670If you are developing a suite of related modules/classes it's good
671practice to use nested classes with a common prefix as this will
672avoid namespace clashes. For example: Xyz::Control, Xyz::View,
673Xyz::Model etc. Use the modules in this list as a naming guide.
674
675If adding a new module to a set, follow the original author's
676standards for naming modules and the interface to methods in
677those modules.
678
4844a3be
SP
679If developing modules for private internal or project specific use,
680that will never be released to the public, then you should ensure
681that their names will not clash with any future public module. You
682can do this either by using the reserved Local::* category or by
683using a category name that includes an underscore like Foo_Corp::*.
684
2e1d04bc
JH
685To be portable each component of a module name should be limited to
68611 characters. If it might be used on MS-DOS then try to ensure each is
687unique in the first 8 characters. Nested modules make this easier.
688
ac634a9a
JH
689=item *
690
691Have you got it right?
2e1d04bc
JH
692
693How do you know that you've made the right decisions? Have you
694picked an interface design that will cause problems later? Have
695you picked the most appropriate name? Do you have any questions?
696
697The best way to know for sure, and pick up many helpful suggestions,
698is to ask someone who knows. Comp.lang.perl.misc is read by just about
699all the people who develop modules and it's the best place to ask.
700
701All you need to do is post a short summary of the module, its
702purpose and interfaces. A few lines on each of the main methods is
703probably enough. (If you post the whole module it might be ignored
704by busy people - generally the very people you want to read it!)
705
706Don't worry about posting if you can't say when the module will be
707ready - just say so in the message. It might be worth inviting
708others to help you, they may be able to complete it for you!
709
ac634a9a
JH
710=item *
711
712README and other Additional Files.
2e1d04bc
JH
713
714It's well known that software developers usually fully document the
715software they write. If, however, the world is in urgent need of
716your software and there is not enough time to write the full
717documentation please at least provide a README file containing:
718
719=over 10
720
721=item *
ac634a9a 722
2e1d04bc
JH
723A description of the module/package/extension etc.
724
725=item *
ac634a9a 726
2e1d04bc
JH
727A copyright notice - see below.
728
729=item *
ac634a9a 730
2e1d04bc
JH
731Prerequisites - what else you may need to have.
732
733=item *
ac634a9a 734
2e1d04bc
JH
735How to build it - possible changes to Makefile.PL etc.
736
737=item *
ac634a9a 738
2e1d04bc
JH
739How to install it.
740
741=item *
ac634a9a 742
2e1d04bc
JH
743Recent changes in this release, especially incompatibilities
744
745=item *
ac634a9a 746
2e1d04bc
JH
747Changes / enhancements you plan to make in the future.
748
749=back
750
751If the README file seems to be getting too large you may wish to
752split out some of the sections into separate files: INSTALL,
753Copying, ToDo etc.
754
755=over 4
756
757=item Adding a Copyright Notice.
758
ac634a9a 759
2e1d04bc
JH
760How you choose to license your work is a personal decision.
761The general mechanism is to assert your Copyright and then make
762a declaration of how others may copy/use/modify your work.
763
764Perl, for example, is supplied with two types of licence: The GNU
765GPL and The Artistic Licence (see the files README, Copying, and
766Artistic). Larry has good reasons for NOT just using the GNU GPL.
767
768My personal recommendation, out of respect for Larry, Perl, and the
769Perl community at large is to state something simply like:
770
771 Copyright (c) 1995 Your Name. All rights reserved.
772 This program is free software; you can redistribute it and/or
773 modify it under the same terms as Perl itself.
774
775This statement should at least appear in the README file. You may
776also wish to include it in a Copying file and your source files.
777Remember to include the other words in addition to the Copyright.
778
ac634a9a
JH
779=item *
780
781Give the module a version/issue/release number.
2e1d04bc
JH
782
783To be fully compatible with the Exporter and MakeMaker modules you
784should store your module's version number in a non-my package
785variable called $VERSION. This should be a floating point
786number with at least two digits after the decimal (i.e., hundredths,
787e.g, C<$VERSION = "0.01">). Don't use a "1.3.2" style version.
788See L<Exporter> for details.
789
790It may be handy to add a function or method to retrieve the number.
791Use the number in announcements and archive file names when
792releasing the module (ModuleName-1.02.tar.Z).
793See perldoc ExtUtils::MakeMaker.pm for details.
794
ac634a9a
JH
795=item *
796
797How to release and distribute a module.
2e1d04bc
JH
798
799It's good idea to post an announcement of the availability of your
800module (or the module itself if small) to the comp.lang.perl.announce
801Usenet newsgroup. This will at least ensure very wide once-off
802distribution.
803
804If possible, register the module with CPAN. You should
805include details of its location in your announcement.
806
807Some notes about ftp archives: Please use a long descriptive file
808name that includes the version number. Most incoming directories
809will not be readable/listable, i.e., you won't be able to see your
810file after uploading it. Remember to send your email notification
811message as soon as possible after uploading else your file may get
812deleted automatically. Allow time for the file to be processed
813and/or check the file has been processed before announcing its
814location.
815
816FTP Archives for Perl Modules:
817
818Follow the instructions and links on:
819
820 http://www.perl.com/CPAN/modules/00modlist.long.html
821 http://www.perl.com/CPAN/modules/04pause.html
822
823or upload to one of these sites:
824
825 https://pause.kbx.de/pause/
826 http://pause.perl.org/pause/
827
828and notify <modules@perl.org>.
829
830By using the WWW interface you can ask the Upload Server to mirror
831your modules from your ftp or WWW site into your own directory on
832CPAN!
833
834Please remember to send me an updated entry for the Module list!
835
ac634a9a
JH
836=item *
837
838Take care when changing a released module.
2e1d04bc
JH
839
840Always strive to remain compatible with previous released versions.
841Otherwise try to add a mechanism to revert to the
842old behavior if people rely on it. Document incompatible changes.
843
844=back
845
846=back
847
848=head2 Guidelines for Converting Perl 4 Library Scripts into Modules
849
850=over 4
851
ac634a9a
JH
852=item *
853
854There is no requirement to convert anything.
2e1d04bc
JH
855
856If it ain't broke, don't fix it! Perl 4 library scripts should
857continue to work with no problems. You may need to make some minor
858changes (like escaping non-array @'s in double quoted strings) but
859there is no need to convert a .pl file into a Module for just that.
860
ac634a9a
JH
861=item *
862
863Consider the implications.
2e1d04bc
JH
864
865All Perl applications that make use of the script will need to
866be changed (slightly) if the script is converted into a module. Is
867it worth it unless you plan to make other changes at the same time?
868
ac634a9a
JH
869=item *
870
871Make the most of the opportunity.
2e1d04bc
JH
872
873If you are going to convert the script to a module you can use the
874opportunity to redesign the interface. The guidelines for module
875creation above include many of the issues you should consider.
876
ac634a9a
JH
877=item *
878
879The pl2pm utility will get you started.
2e1d04bc
JH
880
881This utility will read *.pl files (given as parameters) and write
882corresponding *.pm files. The pl2pm utilities does the following:
883
884=over 10
885
886=item *
ac634a9a 887
2e1d04bc
JH
888Adds the standard Module prologue lines
889
890=item *
ac634a9a 891
2e1d04bc
JH
892Converts package specifiers from ' to ::
893
894=item *
ac634a9a 895
2e1d04bc
JH
896Converts die(...) to croak(...)
897
898=item *
ac634a9a 899
2e1d04bc
JH
900Several other minor changes
901
902=back
903
904Being a mechanical process pl2pm is not bullet proof. The converted
905code will need careful checking, especially any package statements.
906Don't delete the original .pl file till the new .pm one works!
907
908=back
909
910=head2 Guidelines for Reusing Application Code
911
912=over 4
913
ac634a9a
JH
914=item *
915
916Complete applications rarely belong in the Perl Module Library.
917
918=item *
2e1d04bc 919
ac634a9a 920Many applications contain some Perl code that could be reused.
2e1d04bc
JH
921
922Help save the world! Share your code in a form that makes it easy
923to reuse.
924
ac634a9a
JH
925=item *
926
927Break-out the reusable code into one or more separate module files.
928
929=item *
930
931Take the opportunity to reconsider and redesign the interfaces.
2e1d04bc 932
ac634a9a 933=item *
2e1d04bc 934
ac634a9a 935In some cases the 'application' can then be reduced to a small
2e1d04bc
JH
936
937fragment of code built on top of the reusable modules. In these cases
938the application could invoked as:
939
940 % perl -e 'use Module::Name; method(@ARGV)' ...
941or
942 % perl -mModule::Name ... (in perl5.002 or higher)
943
944=back
945
946=head1 NOTE
947
948Perl does not enforce private and public parts of its modules as you may
949have been used to in other languages like C++, Ada, or Modula-17. Perl
950doesn't have an infatuation with enforced privacy. It would prefer
951that you stayed out of its living room because you weren't invited, not
952because it has a shotgun.
953
954The module and its user have a contract, part of which is common law,
955and part of which is "written". Part of the common law contract is
956that a module doesn't pollute any namespace it wasn't asked to. The
957written contract for the module (A.K.A. documentation) may make other
958provisions. But then you know when you C<use RedefineTheWorld> that
959you're redefining the world and willing to take the consequences.
960EOF
961
962close MANIFEST or warn "$0: failed to close MANIFEST (../MANIFEST): $!";
963close OUT or warn "$0: failed to close OUT (perlmodlib.tmp): $!";
964