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