perlmodstyle.pod

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· POD 代码 · 共 781 行 · 第 1/2 页

POD
781
字号
Provide sensible defaults for parameters which have them.  Don't makeyour users specify parameters which will almost always be the same.The issue of whether to pass the arguments in a hash or a hashref islargely a matter of personal style. The use of hash keys starting with a hyphen (C<-name>) or entirely in upper case (C<NAME>) is a relic of older versions of Perl in whichordinary lower case strings were not handled correctly by the C<=E<gt>>operator.  While some modules retain uppercase or hyphenated argumentkeys for historical reasons or as a matter of personal style, most newmodules should use simple lower case keys.  Whatever you choose, beconsistent!=back=head2 Strictness and warningsYour module should run successfully under the strict pragma and shouldrun without generating any warnings.  Your module should also handle taint-checking where appropriate, though this can cause difficulties inmany cases.=head2 Backwards compatibilityModules which are "stable" should not break backwards compatibilitywithout at least a long transition phase and a major change in versionnumber.=head2 Error handling and messagesWhen your module encounters an error it should do one or more of:=over 4=item *Return an undefined value.=item *set C<$Module::errstr> or similar (C<errstr> is a common name used byDBI and other popular modules; if you choose something else, be sure todocument it clearly).=item *C<warn()> or C<carp()> a message to STDERR.  =item *C<croak()> only when your module absolutely cannot figure out what todo.  (C<croak()> is a better version of C<die()> for use within modules, which reports its errors from the perspective of the caller.  See L<Carp> for details of C<croak()>, C<carp()> and other usefulroutines.)=item *As an alternative to the above, you may prefer to throw exceptions using the Error module.=backConfigurable error handling can be very useful to your users.  Consideroffering a choice of levels for warning and debug messages, an option tosend messages to a separate file, a way to specify an error-handlingroutine, or other such features.  Be sure to default all these optionsto the commonest use.=head1 DOCUMENTING YOUR MODULE=head2 PODYour module should include documentation aimed at Perl developers.You should use Perl's "plain old documentation" (POD) for your general technical documentation, though you may wish to write additionaldocumentation (white papers, tutorials, etc) in some other format.  You need to cover the following subjects:=over 4=item *A synopsis of the common uses of the module=item *The purpose, scope and target applications of your module=item *Use of each publically accessible method or subroutine, includingparameters and return values=item *Examples of use=item *Sources of further information=item *A contact email address for the author/maintainer=backThe level of detail in Perl module documentation generally goes fromless detailed to more detailed.  Your SYNOPSIS section should contain aminimal example of use (perhaps as little as one line of code; skip theunusual use cases or anything not needed by most users); theDESCRIPTION should describe your module in broad terms, generally injust a few paragraphs; more detail of the module's routines or methods,lengthy code examples, or other in-depth material should be given in subsequent sections.Ideally, someone who's slightly familiar with your module should be ableto refresh their memory without hitting "page down".  As your readercontinues through the document, they should receive a progressivelygreater amount of knowledge.The recommended order of sections in Perl module documentation is:=over 4=item * NAME=item *SYNOPSIS=item *DESCRIPTION=item *One or more sections or subsections giving greater detail of available methods and routines and any other relevant information.=item *BUGS/CAVEATS/etc=item *AUTHOR=item *SEE ALSO=item *COPYRIGHT and LICENSE=backKeep your documentation near the code it documents ("inline"documentation).  Include POD for a given method right above that method's subroutine.  This makes it easier to keep the documentation upto date, and avoids having to document each piece of code twice (once inPOD and once in comments).=head2 README, INSTALL, release notes, changelogsYour module should also include a README file describing the module andgiving pointers to further information (website, author email).  An INSTALL file should be included, and should contain simple installation instructions. When using ExtUtils::MakeMaker this will usually be:=over 4=item perl Makefile.PL=item make=item make test=item make install=backWhen using Module::Build, this will usually be:=over 4=item perl Build.PL=item perl Build=item perl Build test=item perl Build install=backRelease notes or changelogs should be produced for each release of yoursoftware describing user-visible changes to your module, in termsrelevant to the user.=head1 RELEASE CONSIDERATIONS=head2 Version numberingVersion numbers should indicate at least major and minor releases, andpossibly sub-minor releases.  A major release is one in which most ofthe functionality has changed, or in which major new functionality isadded.  A minor release is one in which a small amount of functionalityhas been added or changed.  Sub-minor version numbers are usually usedfor changes which do not affect functionality, such as documentationpatches.The most common CPAN version numbering scheme looks like this:    1.00, 1.10, 1.11, 1.20, 1.30, 1.31, 1.32A correct CPAN version number is a floating point number with at least 2 digits after the decimal. You can test whether it conforms to CPAN by using    perl -MExtUtils::MakeMaker -le 'print MM->parse_version(shift)' 'Foo.pm'If you want to release a 'beta' or 'alpha' version of a module butdon't want CPAN.pm to list it as most recent use an '_' after theregular version number followed by at least 2 digits, eg. 1.20_01. Ifyou do this, the following idiom is recommended:  $VERSION = "1.12_01";  $XS_VERSION = $VERSION; # only needed if you have XS code  $VERSION = eval $VERSION;With that trick MakeMaker will only read the first line and thus readthe underscore, while the perl interpreter will evaluate the $VERSIONand convert the string into a number. Later operations that treat$VERSION as a number will then be able to do so without provoking awarning about $VERSION not being a number.Never release anything (even a one-word documentation patch) withoutincrementing the number.  Even a one-word documentation patch shouldresult in a change in version at the sub-minor level.=head2 Pre-requisitesModule authors should carefully consider whether to rely on othermodules, and which modules to rely on.Most importantly, choose modules which are as stable as possible.  Inorder of preference: =over 4=item *Core Perl modules=item *Stable CPAN modules=item *Unstable CPAN modules=item *Modules not available from CPAN=backSpecify version requirements for other Perl modules in thepre-requisites in your Makefile.PL or Build.PL.Be sure to specify Perl version requirements both in Makefile.PL orBuild.PL and with C<require 5.6.1> or similar. See the section onC<use VERSION> of L<perlfunc/require> for details.=head2 TestingAll modules should be tested before distribution (using "make disttest"),and the tests should also be available to people installing the modules (using "make test").  For Module::Build you would use the C<make test> equivalent C<perl Build test>.The importance of these tests is proportional to the alleged stability of a module -- a module which purports to be stable or which hopes to achieve wide use should adhere to as strict a testing regime as possible.Useful modules to help you write tests (with minimum impact on your development process or your time) include Test::Simple, Carp::Assert and Test::Inline.For more sophisticated test suites there are Test::More and Test::MockObject.=head2 PackagingModules should be packaged using one of the standard packaging tools.Currently you have the choice between ExtUtils::MakeMaker and themore platform independent Module::Build, allowing modules to be installed in aconsistent manner.When using ExtUtils::MakeMaker, you can use "make dist" to create yourpackage. Tools exist to help you to build your module in a MakeMaker-friendlystyle. These include ExtUtils::ModuleMaker and h2xs.  See also L<perlnewmod>.=head2 LicensingMake sure that your module has a license, and that the full text of itis included in the distribution (unless it's a common one and the termsof the license don't require you to include it).If you don't know what license to use, dual licensing under the GPLand Artistic licenses (the same as Perl itself) is a good idea.See L<perlgpl> and L<perlartistic>.=head1 COMMON PITFALLS=head2 Reinventing the wheelThere are certain application spaces which are already very, very wellserved by CPAN.  One example is templating systems, another is date andtime modules, and there are many more.  While it is a rite of passage towrite your own version of these things, please consider carefullywhether the Perl world really needs you to publish it.=head2 Trying to do too muchYour module will be part of a developer's toolkit.  It will not, initself, form the B<entire> toolkit.  It's tempting to add extra featuresuntil your code is a monolithic system rather than a set of modularbuilding blocks.=head2 Inappropriate documentationDon't fall into the trap of writing for the wrong audience.  Yourprimary audience is a reasonably experienced developer with at least a moderate understanding of your module's application domain, who's just downloaded your module and wants to start using it as quickly as possible.Tutorials, end-user documentation, research papers, FAQs etc are not appropriate in a module's main documentation.  If you really want to write these, include them as sub-documents such as C<My::Module::Tutorial> orC<My::Module::FAQ> and provide a link in the SEE ALSO section of themain documentation.  =head1 SEE ALSO=over 4=item L<perlstyle>General Perl style guide=item L<perlnewmod>How to create a new module=item L<perlpod>POD documentation=item L<podchecker>Verifies your POD's correctness=item Packaging ToolsL<ExtUtils::MakeMaker>, L<Module::Build>=item Testing toolsL<Test::Simple>, L<Test::Inline>, L<Carp::Assert>, L<Test::More>, L<Test::MockObject>=item http://pause.perl.org/Perl Authors Upload Server.  Contains links to information for moduleauthors.=item Any good book on software engineering=back=head1 AUTHORKirrily "Skud" Robert <skud@cpan.org>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?