This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add @_ in signatured sub being experimental to perldelta.pod
[perl5.git] / pod / perlmodlib.PL
CommitLineData
2e1d04bc
JH
1#!../miniperl
2
5b504182
NC
3use strict;
4use warnings;
5
bdba2fe9 6local $ENV{LC_ALL} = 'C';
1fa7ca25 7
f556af6c
NC
8my $Quiet;
9@ARGV = grep { not($_ eq '-q' and $Quiet = 1) } @ARGV;
291c64f4 10
f556af6c
NC
11if (@ARGV) {
12 my $workdir = shift;
13 chdir $workdir
14 or die "Couldn't chdir to '$workdir': $!";
15}
3d7c117d 16require './regen/regen_lib.pl';
4d671226 17
291c64f4
NC
18# MANIFEST itself is Unix style filenames, so we have to assume that Unix style
19# filenames will work.
20
f556af6c
NC
21open MANIFEST, '<', 'MANIFEST'
22 or die "Can't open MANIFEST: $!";
0f6ab019
TI
23my @files =
24 grep !m#/perl.*\.pod#,
25 grep m#(?:\.pm|\.pod|_pm\.PL)#,
26 map {s/\s.*//s; $_}
4bbd41f5 27 grep { m#^(lib|ext|dist|cpan)/# && !m#/(?:t|demo|corpus)/# }
0f6ab019 28 <MANIFEST>;
f556af6c
NC
29close MANIFEST
30 or die "$0: failed to close MANIFEST: $!";
31
32my $out = open_new('pod/perlmodlib.pod', undef,
33 {by => "$0 extracting documentation",
34 from => 'the Perl source files'}, 1);
cf9cbb1f
NC
35
36my %exceptions = (
37 'abbrev' => 'Text::Abbrev',
38 'carp' => 'Carp',
39 'getopt' => 'Getopt::Std',
cf9cbb1f
NC
40 'Encode::MIME::NAME' => 'Encode::MIME::Name',
41 'libnetFAQ' => 'Net::libnetFAQ',
4e42dfb1
JB
42);
43
f556af6c
NC
44my (@pragma, @mod);
45
cf9cbb1f 46for my $filename (@files) {
f556af6c
NC
47 unless (open MOD, '<', $filename) {
48 warn "Couldn't open $filename: $!";
e8041d9b 49 next;
4e42dfb1 50 }
4e860d0a 51
5b504182
NC
52 my ($name, $thing);
53 my $foundit = 0;
54 {
55 local $/ = "";
56 while (<MOD>) {
57 next unless /^=head1 NAME/;
58 $foundit++;
59 last;
60 }
61 }
62 unless ($foundit) {
4bbd41f5
AC
63 next if pod_for_module_has_head1_NAME($filename);
64 die "p5p-controlled module $filename missing =head1 NAME\n"
65 if $filename !~ m{^(dist/|cpan/)}n # under our direct control
66 && $filename !~ m{/_[^/]+\z} # not private
67 && $filename ne 'lib/meta_notation.pm' # no pod
68 && $filename ne 'lib/overload/numbers.pm'; # no pod
69 warn "$filename missing =head1 NAME\n" unless $Quiet;
5b504182
NC
70 next;
71 }
72 my $title = <MOD>;
73 chomp $title;
f556af6c
NC
74 close MOD
75 or die "Error closing $filename: $!";
1fa7ca25 76
2085092c 77 ($name, $thing) = split /\s+--?\s+/, $title, 2;
4e42dfb1 78
5b504182
NC
79 unless ($name and $thing) {
80 warn "$filename missing name\n" unless $name;
81 warn "$filename missing thing\n" unless $thing or $Quiet;
82 next;
83 }
84
85 $name =~ s/[^A-Za-z0-9_:\$<>].*//;
86 $name = $exceptions{$name} || $name;
87 $thing =~ s/^perl pragma to //i;
88 $thing = ucfirst $thing;
89 $title = "=item $name\n\n$thing\n\n";
90
91 if ($name =~ /[A-Z]/) {
92 push @mod, $title;
93 } else {
94 push @pragma, $title;
95 }
2e1d04bc
JH
96}
97
4bbd41f5
AC
98sub pod_for_module_has_head1_NAME {
99 my ($filename) = @_;
100 (my $pod_file = $filename) =~ s/\.pm\z/.pod/ or return 0;
101 return 0 if !-e $pod_file;
102 open my $fh, '<', $pod_file
103 or die "Can't open $pod_file for reading: $!\n";
104 local $/ = '';
105 while (my $para = <$fh>) {
106 return 1 if $para =~ /\A=head1 NAME$/m;
107 }
108 return 0;
109}
110
cf9cbb1f
NC
111# Much easier to special case it like this than special case the depending on
112# and parsing lib/Config.pod, or special case opening configpm and finding its
113# =head1 (which is not found with the $/="" above)
d72ea276 114push @mod, "=item Config\n\nAccess Perl configuration information\n\n";
cf9cbb1f 115
cf9cbb1f 116
d72ea276
NC
117# The intent of using =cut as the heredoc terminator is to make the whole file
118# parse as (reasonably) sane Pod as-is to anything that attempts to
119# brute-force treat it as such. The content is already useful - this just
120# makes it tidier, by stopping anything doing this mistaking the rest of the
c23f766f 121# Perl code for Pod. eg https://metacpan.org/pod/perlmodlib
cf9cbb1f 122
f556af6c 123print $out <<'=cut';
2e1d04bc
JH
124=head1 NAME
125
126perlmodlib - constructing new Perl modules and finding existing ones
127
2e1d04bc
JH
128=head1 THE PERL MODULE LIBRARY
129
7ef5744c 130Many modules are included in the Perl distribution. These are described
2e1d04bc 131below, and all end in F<.pm>. You may discover compiled library
7ef5744c 132files (usually ending in F<.so>) or small pieces of modules to be
2e1d04bc
JH
133autoloaded (ending in F<.al>); these were automatically generated
134by the installation process. You may also discover files in the
135library directory that end in either F<.pl> or F<.ph>. These are
136old libraries supplied so that old programs that use them still
137run. The F<.pl> files will all eventually be converted into standard
138modules, and the F<.ph> files made by B<h2ph> will probably end up
139as extension modules made by B<h2xs>. (Some F<.ph> values may
140already be available through the POSIX, Errno, or Fcntl modules.)
141The B<pl2pm> file in the distribution may help in your conversion,
142but it's just a mechanical process and therefore far from bulletproof.
143
144=head2 Pragmatic Modules
145
146They work somewhat like compiler directives (pragmata) in that they
147tend to affect the compilation of your program, and thus will usually
148work well only when used within a C<use>, or C<no>. Most of these
149are lexically scoped, so an inner BLOCK may countermand them
150by saying:
151
152 no integer;
153 no strict 'refs';
154 no warnings;
155
156which lasts until the end of that BLOCK.
157
158Some pragmas are lexically scoped--typically those that affect the
159C<$^H> hints variable. Others affect the current package instead,
160like C<use vars> and C<use subs>, which allow you to predeclare a
161variables or subroutines within a particular I<file> rather than
162just a block. Such declarations are effective for the entire file
163for which they were declared. You cannot rescind them with C<no
164vars> or C<no subs>.
165
166The following pragmas are defined (and have their own documentation).
167
168=over 12
169
d72ea276 170=cut
2e1d04bc 171
f556af6c 172print $out $_ for sort @pragma;
2e1d04bc 173
f556af6c 174print $out <<'=cut';
d72ea276 175
2e1d04bc
JH
176=back
177
178=head2 Standard Modules
179
180Standard, bundled modules are all expected to behave in a well-defined
181manner with respect to namespace pollution because they use the
182Exporter module. See their own documentation for details.
183
7ef5744c
RGS
184It's possible that not all modules listed below are installed on your
185system. For example, the GDBM_File module will not be installed if you
186don't have the gdbm library.
187
2e1d04bc
JH
188=over 12
189
d72ea276 190=cut
2e1d04bc 191
f556af6c 192print $out $_ for sort @mod;
2e1d04bc 193
f556af6c 194print $out <<'=cut', "=cut\n";
d72ea276 195
2e1d04bc
JH
196=back
197
198To find out I<all> modules installed on your system, including
199those without documentation or outside the standard release,
a4373870
CW
200just use the following command (under the default win32 shell,
201double quotes should be used instead of single quotes).
2e1d04bc 202
a4373870
CW
203 % perl -MFile::Find=find -MFile::Spec::Functions -Tlwe \
204 'find { wanted => sub { print canonpath $_ if /\.pm\z/ },
205 no_chdir => 1 }, @INC'
2e1d04bc 206
8518420c 207(The -T is here to prevent '.' from being listed in @INC.)
2e1d04bc
JH
208They should all have their own documentation installed and accessible
209via your system man(1) command. If you do not have a B<find>
210program, you can use the Perl B<find2perl> program instead, which
211generates Perl code as output you can run through perl. If you
212have a B<man> program but it doesn't find your modules, you'll have
213to fix your manpath. See L<perl> for details. If you have no
214system B<man> command, you might try the B<perldoc> program.
215
8518420c
RGS
216Note also that the command C<perldoc perllocal> gives you a (possibly
217incomplete) list of the modules that have been further installed on
218your system. (The perllocal.pod file is updated by the standard MakeMaker
219install process.)
220
2e1d04bc
JH
221=head2 Extension Modules
222
223Extension modules are written in C (or a mix of Perl and C). They
224are usually dynamically loaded into Perl if and when you need them,
da75cd15 225but may also be linked in statically. Supported extension modules
2e1d04bc
JH
226include Socket, Fcntl, and POSIX.
227
228Many popular C extension modules do not come bundled (at least, not
229completely) due to their sizes, volatility, or simply lack of time
230for adequate testing and configuration across the multitude of
231platforms on which Perl was beta-tested. You are encouraged to
232look for them on CPAN (described below), or using web search engines
42aeee0b 233like Google or DuckDuckGo.
2e1d04bc
JH
234
235=head1 CPAN
236
237CPAN stands for Comprehensive Perl Archive Network; it's a globally
238replicated trove of Perl materials, including documentation, style
239guides, tricks and traps, alternate ports to non-Unix systems and
240occasional binary distributions for these. Search engines for
71c89d21 241CPAN can be found at https://www.cpan.org/
2e1d04bc
JH
242
243Most importantly, CPAN includes around a thousand unbundled modules,
244some of which require a C compiler to build. Major categories of
245modules are:
246
247=over
248
249=item *
ac634a9a 250
2e1d04bc
JH
251Language Extensions and Documentation Tools
252
253=item *
ac634a9a 254
2e1d04bc
JH
255Development Support
256
257=item *
ac634a9a 258
2e1d04bc
JH
259Operating System Interfaces
260
261=item *
ac634a9a 262
2e1d04bc
JH
263Networking, Device Control (modems) and InterProcess Communication
264
265=item *
ac634a9a 266
2e1d04bc
JH
267Data Types and Data Type Utilities
268
269=item *
ac634a9a 270
2e1d04bc
JH
271Database Interfaces
272
273=item *
ac634a9a 274
2e1d04bc
JH
275User Interfaces
276
277=item *
ac634a9a 278
2e1d04bc
JH
279Interfaces to / Emulations of Other Programming Languages
280
281=item *
ac634a9a 282
2e1d04bc
JH
283File Names, File Systems and File Locking (see also File Handles)
284
285=item *
ac634a9a 286
2e1d04bc
JH
287String Processing, Language Text Processing, Parsing, and Searching
288
289=item *
ac634a9a 290
2e1d04bc
JH
291Option, Argument, Parameter, and Configuration File Processing
292
293=item *
ac634a9a 294
2e1d04bc
JH
295Internationalization and Locale
296
297=item *
ac634a9a 298
2e1d04bc
JH
299Authentication, Security, and Encryption
300
301=item *
ac634a9a 302
2e1d04bc
JH
303World Wide Web, HTML, HTTP, CGI, MIME
304
305=item *
ac634a9a 306
2e1d04bc
JH
307Server and Daemon Utilities
308
309=item *
ac634a9a 310
2e1d04bc
JH
311Archiving and Compression
312
313=item *
ac634a9a 314
2e1d04bc
JH
315Images, Pixmap and Bitmap Manipulation, Drawing, and Graphing
316
317=item *
ac634a9a 318
2e1d04bc
JH
319Mail and Usenet News
320
321=item *
ac634a9a 322
2e1d04bc
JH
323Control Flow Utilities (callbacks and exceptions etc)
324
325=item *
ac634a9a 326
2e1d04bc
JH
327File Handle and Input/Output Stream Utilities
328
329=item *
ac634a9a 330
2e1d04bc
JH
331Miscellaneous Modules
332
333=back
334
60ab4d25 335You can find the CPAN online at L<https://www.cpan.org/>
2e1d04bc
JH
336
337=head1 Modules: Creation, Use, and Abuse
338
339(The following section is borrowed directly from Tim Bunce's modules
340file, available at your nearest CPAN site.)
341
342Perl implements a class using a package, but the presence of a
343package doesn't imply the presence of a class. A package is just a
344namespace. A class is a package that provides subroutines that can be
345used as methods. A method is just a subroutine that expects, as its
346first argument, either the name of a package (for "static" methods),
347or a reference to something (for "virtual" methods).
348
349A module is a file that (by convention) provides a class of the same
350name (sans the .pm), plus an import method in that class that can be
351called to fetch exported symbols. This module may implement some of
352its methods by loading dynamic C or C++ objects, but that should be
353totally transparent to the user of the module. Likewise, the module
354might set up an AUTOLOAD function to slurp in subroutine definitions on
355demand, but this is also transparent. Only the F<.pm> file is required to
82e1c0d9 356exist. See L<perlsub>, L<perlobj>, and L<AutoLoader> for details about
2e1d04bc
JH
357the AUTOLOAD mechanism.
358
359=head2 Guidelines for Module Creation
360
361=over 4
362
ac634a9a
JH
363=item *
364
365Do similar modules already exist in some form?
2e1d04bc
JH
366
367If so, please try to reuse the existing modules either in whole or
368by inheriting useful features into a new class. If this is not
369practical try to get together with the module authors to work on
370extending or enhancing the functionality of the existing modules.
371A perfect example is the plethora of packages in perl4 for dealing
372with command line options.
373
374If you are writing a module to expand an already existing set of
375modules, please coordinate with the author of the package. It
376helps if you follow the same naming scheme and module interaction
377scheme as the original author.
378
ac634a9a
JH
379=item *
380
381Try to design the new module to be easy to extend and reuse.
2e1d04bc
JH
382
383Try to C<use warnings;> (or C<use warnings qw(...);>).
384Remember that you can add C<no warnings qw(...);> to individual blocks
385of code that need less warnings.
386
387Use blessed references. Use the two argument form of bless to bless
388into the class name given as the first parameter of the constructor,
389e.g.,:
390
391 sub new {
392 my $class = shift;
393 return bless {}, $class;
394 }
395
396or even this if you'd like it to be used as either a static
397or a virtual method.
398
399 sub new {
400 my $self = shift;
401 my $class = ref($self) || $self;
402 return bless {}, $class;
403 }
404
405Pass arrays as references so more parameters can be added later
406(it's also faster). Convert functions into methods where
407appropriate. Split large methods into smaller more flexible ones.
408Inherit methods from other modules if appropriate.
409
410Avoid class name tests like: C<die "Invalid" unless ref $ref eq 'FOO'>.
411Generally you can delete the C<eq 'FOO'> part with no harm at all.
412Let the objects look after themselves! Generally, avoid hard-wired
413class names as far as possible.
414
415Avoid C<< $r->Class::func() >> where using C<@ISA=qw(... Class ...)> and
82e1c0d9 416C<< $r->func() >> would work.
2e1d04bc
JH
417
418Use autosplit so little used or newly added functions won't be a
419burden to programs that don't use them. Add test functions to
420the module after __END__ either using AutoSplit or by saying:
421
422 eval join('',<main::DATA>) || die $@ unless caller();
423
424Does your module pass the 'empty subclass' test? If you say
425C<@SUBCLASS::ISA = qw(YOURCLASS);> your applications should be able
426to use SUBCLASS in exactly the same way as YOURCLASS. For example,
63acfd00 427does your application still work if you change: C<< $obj = YOURCLASS->new(); >>
428into: C<< $obj = SUBCLASS->new(); >> ?
2e1d04bc
JH
429
430Avoid keeping any state information in your packages. It makes it
431difficult for multiple other packages to use yours. Keep state
432information in objects.
433
434Always use B<-w>.
435
436Try to C<use strict;> (or C<use strict qw(...);>).
437Remember that you can add C<no strict qw(...);> to individual blocks
438of code that need less strictness.
439
440Always use B<-w>.
441
ba555bf5 442Follow the guidelines in L<perlstyle>.
2e1d04bc
JH
443
444Always use B<-w>.
445
ac634a9a
JH
446=item *
447
448Some simple style guidelines
2e1d04bc
JH
449
450The perlstyle manual supplied with Perl has many helpful points.
451
452Coding style is a matter of personal taste. Many people evolve their
453style over several years as they learn what helps them write and
454maintain good code. Here's one set of assorted suggestions that
455seem to be widely used by experienced developers:
456
457Use underscores to separate words. It is generally easier to read
458$var_names_like_this than $VarNamesLikeThis, especially for
459non-native speakers of English. It's also a simple rule that works
460consistently with VAR_NAMES_LIKE_THIS.
461
462Package/Module names are an exception to this rule. Perl informally
463reserves lowercase module names for 'pragma' modules like integer
464and strict. Other modules normally begin with a capital letter and
465use mixed case with no underscores (need to be short and portable).
466
467You may find it helpful to use letter case to indicate the scope
468or nature of a variable. For example:
469
470 $ALL_CAPS_HERE constants only (beware clashes with Perl vars)
471 $Some_Caps_Here package-wide global/static
472 $no_caps_here function scope my() or local() variables
473
474Function and method names seem to work best as all lowercase.
475e.g., C<< $obj->as_string() >>.
476
477You can use a leading underscore to indicate that a variable or
478function should not be used outside the package that defined it.
479
ac634a9a
JH
480=item *
481
482Select what to export.
2e1d04bc
JH
483
484Do NOT export method names!
485
486Do NOT export anything else by default without a good reason!
487
488Exports pollute the namespace of the module user. If you must
489export try to use @EXPORT_OK in preference to @EXPORT and avoid
490short or common names to reduce the risk of name clashes.
491
492Generally anything not exported is still accessible from outside the
493module using the ModuleName::item_name (or C<< $blessed_ref->method >>)
494syntax. By convention you can use a leading underscore on names to
495indicate informally that they are 'internal' and not for public use.
496
497(It is actually possible to get private functions by saying:
498C<my $subref = sub { ... }; &$subref;>. But there's no way to call that
499directly as a method, because a method must have a name in the symbol
500table.)
501
502As a general rule, if the module is trying to be object oriented
503then export nothing. If it's just a collection of functions then
504@EXPORT_OK anything but use @EXPORT with caution.
505
ac634a9a
JH
506=item *
507
508Select a name for the module.
2e1d04bc
JH
509
510This name should be as descriptive, accurate, and complete as
511possible. Avoid any risk of ambiguity. Always try to use two or
512more whole words. Generally the name should reflect what is special
513about what the module does rather than how it does it. Please use
514nested module names to group informally or categorize a module.
515There should be a very good reason for a module not to have a nested name.
516Module names should begin with a capital letter.
517
518Having 57 modules all called Sort will not make life easy for anyone
519(though having 23 called Sort::Quick is only marginally better :-).
520Imagine someone trying to install your module alongside many others.
2e1d04bc
JH
521
522If you are developing a suite of related modules/classes it's good
523practice to use nested classes with a common prefix as this will
524avoid namespace clashes. For example: Xyz::Control, Xyz::View,
525Xyz::Model etc. Use the modules in this list as a naming guide.
526
527If adding a new module to a set, follow the original author's
528standards for naming modules and the interface to methods in
529those modules.
530
4844a3be
SP
531If developing modules for private internal or project specific use,
532that will never be released to the public, then you should ensure
533that their names will not clash with any future public module. You
534can do this either by using the reserved Local::* category or by
535using a category name that includes an underscore like Foo_Corp::*.
536
2e1d04bc
JH
537To be portable each component of a module name should be limited to
53811 characters. If it might be used on MS-DOS then try to ensure each is
539unique in the first 8 characters. Nested modules make this easier.
540
f94c6c53
JK
541For additional guidance on the naming of modules, please consult:
542
71c89d21 543 https://pause.perl.org/pause/query?ACTION=pause_namingmodules
f94c6c53
JK
544
545or send mail to the <module-authors@perl.org> mailing list.
546
ac634a9a
JH
547=item *
548
549Have you got it right?
2e1d04bc
JH
550
551How do you know that you've made the right decisions? Have you
552picked an interface design that will cause problems later? Have
553you picked the most appropriate name? Do you have any questions?
554
555The best way to know for sure, and pick up many helpful suggestions,
f94c6c53
JK
556is to ask someone who knows. The <module-authors@perl.org> mailing list
557is useful for this purpose; it's also accessible via news interface as
558perl.module-authors at nntp.perl.org.
2e1d04bc
JH
559
560All you need to do is post a short summary of the module, its
561purpose and interfaces. A few lines on each of the main methods is
562probably enough. (If you post the whole module it might be ignored
563by busy people - generally the very people you want to read it!)
564
565Don't worry about posting if you can't say when the module will be
566ready - just say so in the message. It might be worth inviting
567others to help you, they may be able to complete it for you!
568
ac634a9a
JH
569=item *
570
571README and other Additional Files.
2e1d04bc
JH
572
573It's well known that software developers usually fully document the
574software they write. If, however, the world is in urgent need of
575your software and there is not enough time to write the full
576documentation please at least provide a README file containing:
577
578=over 10
579
580=item *
ac634a9a 581
2e1d04bc
JH
582A description of the module/package/extension etc.
583
584=item *
ac634a9a 585
2e1d04bc
JH
586A copyright notice - see below.
587
588=item *
ac634a9a 589
2e1d04bc
JH
590Prerequisites - what else you may need to have.
591
592=item *
ac634a9a 593
2e1d04bc
JH
594How to build it - possible changes to Makefile.PL etc.
595
596=item *
ac634a9a 597
2e1d04bc
JH
598How to install it.
599
600=item *
ac634a9a 601
2e1d04bc
JH
602Recent changes in this release, especially incompatibilities
603
604=item *
ac634a9a 605
2e1d04bc
JH
606Changes / enhancements you plan to make in the future.
607
608=back
609
610If the README file seems to be getting too large you may wish to
611split out some of the sections into separate files: INSTALL,
612Copying, ToDo etc.
613
614=over 4
615
c165c82a 616=item *
2e1d04bc 617
c165c82a 618Adding a Copyright Notice.
ac634a9a 619
2e1d04bc
JH
620How you choose to license your work is a personal decision.
621The general mechanism is to assert your Copyright and then make
622a declaration of how others may copy/use/modify your work.
623
2a551100
JH
624Perl, for example, is supplied with two types of licence: The GNU GPL
625and The Artistic Licence (see the files README, Copying, and Artistic,
626or L<perlgpl> and L<perlartistic>). Larry has good reasons for NOT
627just using the GNU GPL.
2e1d04bc
JH
628
629My personal recommendation, out of respect for Larry, Perl, and the
630Perl community at large is to state something simply like:
631
632 Copyright (c) 1995 Your Name. All rights reserved.
633 This program is free software; you can redistribute it and/or
634 modify it under the same terms as Perl itself.
635
636This statement should at least appear in the README file. You may
637also wish to include it in a Copying file and your source files.
638Remember to include the other words in addition to the Copyright.
639
ac634a9a
JH
640=item *
641
642Give the module a version/issue/release number.
2e1d04bc
JH
643
644To be fully compatible with the Exporter and MakeMaker modules you
645should store your module's version number in a non-my package
f39335f9 646variable called $VERSION. This should be a positive floating point
2e1d04bc
JH
647number with at least two digits after the decimal (i.e., hundredths,
648e.g, C<$VERSION = "0.01">). Don't use a "1.3.2" style version.
649See L<Exporter> for details.
650
651It may be handy to add a function or method to retrieve the number.
652Use the number in announcements and archive file names when
653releasing the module (ModuleName-1.02.tar.Z).
654See perldoc ExtUtils::MakeMaker.pm for details.
655
ac634a9a
JH
656=item *
657
658How to release and distribute a module.
2e1d04bc 659
32356571
DC
660If possible, register the module with CPAN. Follow the instructions
661and links on:
2e1d04bc 662
71c89d21 663 https://www.cpan.org/modules/04pause.html
2e1d04bc 664
32356571 665and upload to:
2e1d04bc 666
71c89d21 667 https://pause.perl.org/
2e1d04bc 668
32356571
DC
669and notify <modules@perl.org>. This will allow anyone to install
670your module using the C<cpan> tool distributed with Perl.
2e1d04bc
JH
671
672By using the WWW interface you can ask the Upload Server to mirror
673your modules from your ftp or WWW site into your own directory on
674CPAN!
675
ac634a9a
JH
676=item *
677
678Take care when changing a released module.
2e1d04bc
JH
679
680Always strive to remain compatible with previous released versions.
681Otherwise try to add a mechanism to revert to the
682old behavior if people rely on it. Document incompatible changes.
683
684=back
685
abf06cc1
MS
686=back
687
2e1d04bc
JH
688=head2 Guidelines for Converting Perl 4 Library Scripts into Modules
689
690=over 4
691
ac634a9a
JH
692=item *
693
694There is no requirement to convert anything.
2e1d04bc
JH
695
696If it ain't broke, don't fix it! Perl 4 library scripts should
697continue to work with no problems. You may need to make some minor
698changes (like escaping non-array @'s in double quoted strings) but
699there is no need to convert a .pl file into a Module for just that.
700
ac634a9a
JH
701=item *
702
703Consider the implications.
2e1d04bc
JH
704
705All Perl applications that make use of the script will need to
706be changed (slightly) if the script is converted into a module. Is
707it worth it unless you plan to make other changes at the same time?
708
ac634a9a
JH
709=item *
710
711Make the most of the opportunity.
2e1d04bc
JH
712
713If you are going to convert the script to a module you can use the
714opportunity to redesign the interface. The guidelines for module
715creation above include many of the issues you should consider.
716
ac634a9a
JH
717=item *
718
719The pl2pm utility will get you started.
2e1d04bc
JH
720
721This utility will read *.pl files (given as parameters) and write
722corresponding *.pm files. The pl2pm utilities does the following:
723
724=over 10
725
726=item *
ac634a9a 727
2e1d04bc
JH
728Adds the standard Module prologue lines
729
730=item *
ac634a9a 731
2e1d04bc
JH
732Converts package specifiers from ' to ::
733
734=item *
ac634a9a 735
2e1d04bc
JH
736Converts die(...) to croak(...)
737
738=item *
ac634a9a 739
2e1d04bc
JH
740Several other minor changes
741
742=back
743
744Being a mechanical process pl2pm is not bullet proof. The converted
745code will need careful checking, especially any package statements.
746Don't delete the original .pl file till the new .pm one works!
747
748=back
749
750=head2 Guidelines for Reusing Application Code
751
752=over 4
753
ac634a9a
JH
754=item *
755
756Complete applications rarely belong in the Perl Module Library.
757
758=item *
2e1d04bc 759
ac634a9a 760Many applications contain some Perl code that could be reused.
2e1d04bc
JH
761
762Help save the world! Share your code in a form that makes it easy
763to reuse.
764
ac634a9a
JH
765=item *
766
767Break-out the reusable code into one or more separate module files.
768
769=item *
770
771Take the opportunity to reconsider and redesign the interfaces.
2e1d04bc 772
ac634a9a 773=item *
2e1d04bc 774
ac634a9a 775In some cases the 'application' can then be reduced to a small
2e1d04bc
JH
776
777fragment of code built on top of the reusable modules. In these cases
778the application could invoked as:
779
780 % perl -e 'use Module::Name; method(@ARGV)' ...
781or
782 % perl -mModule::Name ... (in perl5.002 or higher)
783
784=back
785
786=head1 NOTE
787
788Perl does not enforce private and public parts of its modules as you may
789have been used to in other languages like C++, Ada, or Modula-17. Perl
790doesn't have an infatuation with enforced privacy. It would prefer
791that you stayed out of its living room because you weren't invited, not
792because it has a shotgun.
793
794The module and its user have a contract, part of which is common law,
795and part of which is "written". Part of the common law contract is
796that a module doesn't pollute any namespace it wasn't asked to. The
797written contract for the module (A.K.A. documentation) may make other
798provisions. But then you know when you C<use RedefineTheWorld> that
799you're redefining the world and willing to take the consequences.
d72ea276
NC
800
801=cut
2e1d04bc 802
f556af6c 803read_only_bottom_close_and_rename($out);