{
    "mode": "man",
    "parameter": "perlmodstyle",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/perlmodstyle/1/json",
    "generated": "2026-10-06T10:50:35Z",
    "sections": {
        "NAME": {
            "content": "perlmodstyle - Perl module style guide\n",
            "subsections": []
        },
        "INTRODUCTION": {
            "content": "This document attempts to describe the Perl Community's \"best practice\" for writing Perl\nmodules.  It extends the recommendations found in perlstyle , which should be considered\nrequired reading before reading this document.\n\nWhile this document is intended to be useful to all module authors, it is particularly aimed\nat authors who wish to publish their modules on CPAN.\n\nThe focus is on elements of style which are visible to the users of a module, rather than\nthose parts which are only seen by the module's developers.  However, many of the guidelines\npresented in this document can be extrapolated and applied successfully to a module's\ninternals.\n\nThis document differs from perlnewmod in that it is a style guide rather than a tutorial on\ncreating CPAN modules.  It provides a checklist against which modules can be compared to\ndetermine whether they conform to best practice, without necessarily describing in detail how\nto achieve this.\n\nAll the advice contained in this document has been gleaned from extensive conversations with\nexperienced CPAN authors and users.  Every piece of advice given here is the result of\nprevious mistakes.  This information is here to help you avoid the same mistakes and the\nextra work that would inevitably be required to fix them.\n\nThe first section of this document provides an itemized checklist; subsequent sections\nprovide a more detailed discussion of the items on the list.  The final section, \"Common\nPitfalls\", describes some of the most popular mistakes made by CPAN authors.\n",
            "subsections": []
        },
        "QUICK CHECKLIST": {
            "content": "For more detail on each item in this checklist, see below.\n",
            "subsections": [
                {
                    "name": "Before you start",
                    "content": "•   Don't re-invent the wheel\n\n•   Patch, extend or subclass an existing module where possible\n\n•   Do one thing and do it well\n\n•   Choose an appropriate name\n\n•   Get feedback before publishing\n"
                },
                {
                    "name": "The API",
                    "content": "•   API should be understandable by the average programmer\n\n•   Simple methods for simple tasks\n\n•   Separate functionality from output\n\n•   Consistent naming of subroutines or methods\n\n•   Use named parameters (a hash or hashref) when there are more than two parameters\n"
                },
                {
                    "name": "Stability",
                    "content": "•   Ensure your module works under \"use strict\" and \"-w\"\n\n•   Stable modules should maintain backwards compatibility\n"
                },
                {
                    "name": "Documentation",
                    "content": "•   Write documentation in POD\n\n•   Document purpose, scope and target applications\n\n•   Document  each  publicly  accessible  method  or  subroutine, including params and return\nvalues\n\n•   Give examples of use in your documentation\n\n•   Provide a README file and perhaps also release notes, changelog, etc\n\n•   Provide links to further information (URL, email)\n"
                },
                {
                    "name": "Release considerations",
                    "content": "•   Specify pre-requisites in Makefile.PL or Build.PL\n\n•   Specify Perl version requirements with \"use\"\n\n•   Include tests with your module\n\n•   Choose a sensible and consistent version numbering scheme (X.YY is the common Perl module\nnumbering scheme)\n\n•   Increment the version number for every change, no matter how small\n\n•   Package the module using \"make dist\"\n\n•   Choose an appropriate license (GPL/Artistic is a good default)\n"
                }
            ]
        },
        "BEFORE YOU START WRITING A MODULE": {
            "content": "Try not to launch headlong into developing your module without spending  some  time  thinking\nfirst.  A little forethought may save you a vast amount of effort later on.\n",
            "subsections": [
                {
                    "name": "Has it been done before?",
                    "content": "You may not even need to write the module.  Check whether it's already been done in Perl, and\navoid re-inventing the wheel unless you have a good reason.\n\nGood  places  to  look  for  pre-existing modules include MetaCPAN <https://metacpan.org> and\nasking on \"module-authors@perl.org\" (<https://lists.perl.org/list/module-authors.html>).\n\nIf an existing module almost does  what  you  want,  consider  writing  a  patch,  writing  a\nsubclass, or otherwise extending the existing module rather than rewriting it.\n"
                },
                {
                    "name": "Do one thing and do it well",
                    "content": "At  the  risk  of  stating the obvious, modules are intended to be modular.  A Perl developer\nshould be able to use modules to put together  the  building  blocks  of  their  application.\nHowever, it's important that the blocks are the right shape, and that the developer shouldn't\nhave to use a big block when all they need is a small one.\n\nYour  module  should  have a clearly defined scope which is no longer than a single sentence.\nCan your module be broken down into a family of related modules?\n\nBad example:\n\n\"FooBar.pm provides an implementation of the FOO protocol and the related BAR standard.\"\n\nGood example:\n\n\"Foo.pm provides an implementation of the FOO protocol.  Bar.pm implements  the  related  BAR\nprotocol.\"\n\nThis  means  that if a developer only needs a module for the BAR standard, they should not be\nforced to install libraries for FOO as well.\n"
                },
                {
                    "name": "What's in a name?",
                    "content": "Make sure you choose an appropriate name for your module early on.   This  will  help  people\nfind and remember your module, and make programming with your module more intuitive.\n\nWhen naming your module, consider the following:\n\n•   Be descriptive (i.e. accurately describes the purpose of the module).\n\n•   Be consistent with existing modules.\n\n•   Reflect the functionality of the module, not the implementation.\n\n•   Avoid  starting  a  new  top-level  hierarchy, especially if a suitable hierarchy already\nexists under which you could place your module.\n"
                },
                {
                    "name": "Get feedback before publishing",
                    "content": "If you have never uploaded a module to CPAN before (and even if you have), you  are  strongly\nencouraged to get feedback from people who are already familiar with the module's application\ndomain  and  the  CPAN  naming  system.   Authors of similar modules, or modules with similar\nnames,  may  be  a  good  place  to  start,  as  are  community   sites   like   Perl   Monks\n<https://www.perlmonks.org>.\n"
                }
            ]
        },
        "DESIGNING AND WRITING YOUR MODULE": {
            "content": "Considerations for module design and coding:\n",
            "subsections": [
                {
                    "name": "To OO or not to OO?",
                    "content": "Your  module  may  be  object  oriented  (OO) or not, or it may have both kinds of interfaces\navailable.  There are pros and cons of each technique, which should be  considered  when  you\ndesign your API.\n\nIn  Perl  Best  Practices  (copyright 2004, Published by O'Reilly Media, Inc.), Damian Conway\nprovides a list of criteria to use when deciding if OO is the right fit for your problem:\n\n•   The system being designed is large, or is likely to become large.\n\n•   The data can be aggregated into obvious structures, especially if there's a large  amount\nof data in each aggregate.\n\n•   The  various types of data aggregate form a natural hierarchy that facilitates the use of\ninheritance and polymorphism.\n\n•   You have a piece of data on which many different operations are applied.\n\n•   You need to perform the same general operations on related types of data, but with slight\nvariations depending on the specific type of data the operations are applied to.\n\n•   It's likely you'll have to add new data types later.\n\n•   The typical interactions between pieces of data are best represented by operators.\n\n•   The implementation of individual components of the system is likely to change over time.\n\n•   The system design is already object-oriented.\n\n•   Large numbers of other programmers will be using your code modules.\n\nThink carefully  about  whether  OO  is  appropriate  for  your  module.   Gratuitous  object\norientation  results  in  complex  APIs  which  are  difficult for the average module user to\nunderstand or use.\n"
                },
                {
                    "name": "Designing your API",
                    "content": "Your interfaces should be understandable  by  an  average  Perl  programmer.   The  following\nguidelines may help you judge whether your API is sufficiently straightforward:\n\nWrite simple routines to do simple things.\nIt's better to have numerous simple routines than a few monolithic ones.  If your routine\nchanges  its  behaviour significantly based on its arguments, it's a sign that you should\nhave two (or more) separate routines.\n\nSeparate functionality from output.\nReturn your results in the most generic form possible and allow the user to choose how to\nuse them.  The most generic form possible is usually a Perl data structure which can then\nbe used to generate a text report, HTML, XML, a database query,  or  whatever  else  your\nusers require.\n\nIf  your  routine iterates through some kind of list (such as a list of files, or records\nin a database) you may consider providing a callback so that users  can  manipulate  each\nelement  of  the  list  in  turn.   File::Find  provides  an  example  of  this  with its\n\"find(\\&wanted, $dir)\" syntax.\n\nProvide sensible shortcuts and defaults.\nDon't require every module user to jump through  the  same  hoops  to  achieve  a  simple\nresult.   You can always include optional parameters or routines for more complex or non-\nstandard behaviour.  If most of your users have to type a few almost identical  lines  of\ncode  when  they  start  using  your  module,  it's a sign that you should have made that\nbehaviour a default.  Another good indicator that you should use defaults is if  most  of\nyour users call your routines with the same arguments.\n\nNaming conventions\nYour naming should be consistent.  For instance, it's better to have:\n\ndisplayday();\ndisplayweek();\ndisplayyear();\n\nthan\n\ndisplayday();\nweekdisplay();\nshowyear();\n\nThis applies equally to method names, parameter names, and anything else which is visible\nto the user (and most things that aren't!)\n\nParameter passing\nUse named parameters.  It's easier to use a hash like this:\n\n$obj->dosomething(\nname => \"wibble\",\ntype => \"text\",\nsize => 1024,\n);\n\n... than to have a long list of unnamed parameters like this:\n\n$obj->dosomething(\"wibble\", \"text\", 1024);\n\nWhile  the  list  of  arguments might work fine for one, two or even three arguments, any\nmore arguments become hard for the module user to  remember,  and  hard  for  the  module\nauthor  to manage.  If you want to add a new parameter you will have to add it to the end\nof the list for backward compatibility, and this  will  probably  make  your  list  order\nunintuitive.   Also,  if  many  elements  may  be  undefined  you  may  see the following\nunattractive method calls:\n\n$obj->dosomething(undef, undef, undef, undef, undef, 1024);\n\nProvide sensible defaults for parameters which have them.  Don't make your users  specify\nparameters which will almost always be the same.\n\nThe  issue of whether to pass the arguments in a hash or a hashref is largely a matter of\npersonal style.\n\nThe use of hash keys starting with a hyphen (\"-name\") or entirely in upper case  (\"NAME\")\nis  a  relic  of  older  versions  of  Perl in which ordinary lower case strings were not\nhandled correctly  by  the  \"=>\"  operator.   While  some  modules  retain  uppercase  or\nhyphenated  argument  keys  for historical reasons or as a matter of personal style, most\nnew modules should use simple lower case keys.  Whatever you choose, be consistent!\n"
                },
                {
                    "name": "Strictness and warnings",
                    "content": "Your module should run successfully under the strict pragma and should run without generating\nany warnings.  Your module should also handle taint-checking where appropriate,  though  this\ncan cause difficulties in many cases.\n"
                },
                {
                    "name": "Backwards compatibility",
                    "content": "Modules  which  are \"stable\" should not break backwards compatibility without at least a long\ntransition phase and a major change in version number.\n"
                },
                {
                    "name": "Error handling and messages",
                    "content": "When your module encounters an error it should do one or more of:\n\n•   Return an undefined value.\n\n•   set $Module::errstr or similar (\"errstr\" is a common name used by DBI and  other  popular\nmodules; if you choose something else, be sure to document it clearly).\n\n•   warn() or carp() a message to STDERR.\n\n•   croak()  only  when  your  module absolutely cannot figure out what to do.  (croak() is a\nbetter version of die() for use  within  modules,  which  reports  its  errors  from  the\nperspective  of  the  caller.   See  Carp for details of croak(), carp() and other useful\nroutines.)\n\n•   As an alternative to the above, you may  prefer  to  throw  exceptions  using  the  Error\nmodule.\n\nConfigurable  error handling can be very useful to your users.  Consider offering a choice of\nlevels for warning and debug messages, an option to send messages to a separate file,  a  way\nto  specify  an error-handling routine, or other such features.  Be sure to default all these\noptions to the commonest use.\n"
                }
            ]
        },
        "DOCUMENTING YOUR MODULE": {
            "content": "POD\nYour module should include documentation aimed at Perl developers.   You  should  use  Perl's\n\"plain old documentation\" (POD) for your general technical documentation, though you may wish\nto  write  additional documentation (white papers, tutorials, etc) in some other format.  You\nneed to cover the following subjects:\n\n•   A synopsis of the common uses of the module\n\n•   The purpose, scope and target applications of your module\n\n•   Use of each publicly accessible method or subroutine,  including  parameters  and  return\nvalues\n\n•   Examples of use\n\n•   Sources of further information\n\n•   A contact email address for the author/maintainer\n\nThe  level  of  detail in Perl module documentation generally goes from less detailed to more\ndetailed.  Your SYNOPSIS section should contain a minimal example of use (perhaps  as  little\nas  one  line  of code; skip the unusual use cases or anything not needed by most users); the\nDESCRIPTION should describe your module in broad terms, generally in just a  few  paragraphs;\nmore  detail  of  the  module's routines or methods, lengthy code examples, or other in-depth\nmaterial should be given in subsequent sections.\n\nIdeally, someone who's slightly familiar with your module should be  able  to  refresh  their\nmemory  without  hitting  \"page  down\".   As your reader continues through the document, they\nshould receive a progressively greater amount of knowledge.\n\nThe recommended order of sections in Perl module documentation is:\n\n•   NAME\n\n•   SYNOPSIS\n\n•   DESCRIPTION\n\n•   One or more sections or subsections  giving  greater  detail  of  available  methods  and\nroutines and any other relevant information.\n\n•   BUGS/CAVEATS/etc\n\n•   AUTHOR\n\n•   SEE ALSO\n\n•   COPYRIGHT and LICENSE\n\nKeep your documentation near the code it documents (\"inline\" documentation).  Include POD for\na  given  method  right  above  that  method's  subroutine.  This makes it easier to keep the\ndocumentation up to date, and avoids having to document each piece of code twice (once in POD\nand once in comments).\n",
            "subsections": [
                {
                    "name": "README, INSTALL, release notes, changelogs",
                    "content": "Your module should also include a README file describing the module and  giving  pointers  to\nfurther information (website, author email).\n\nAn  INSTALL  file  should  be  included, and should contain simple installation instructions.\nWhen using ExtUtils::MakeMaker this will usually be:\n\nperl Makefile.PL\nmake\nmake test\nmake install\n\nWhen using Module::Build, this will usually be:\n\nperl Build.PL\nperl Build\nperl Build test\nperl Build install\n\nRelease notes or changelogs should be produced for each release of your  software  describing\nuser-visible changes to your module, in terms relevant to the user.\n\nUnless  you  have good reasons for using some other format (for example, a format used within\nyour company), the convention is to name your changelog file \"Changes\",  and  to  follow  the\nsimple format described in CPAN::Changes::Spec.\n"
                }
            ]
        },
        "RELEASE CONSIDERATIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "Version numbering",
                    "content": "Version  numbers  should  indicate  at least major and minor releases, and possibly sub-minor\nreleases.  A major release is one in which most of the functionality has changed, or in which\nmajor new functionality is added.  A minor  release  is  one  in  which  a  small  amount  of\nfunctionality  has  been  added  or  changed.  Sub-minor version numbers are usually used for\nchanges which do not affect functionality, such as documentation patches.\n\nThe most common CPAN version numbering scheme looks like this:\n\n1.00, 1.10, 1.11, 1.20, 1.30, 1.31, 1.32\n\nA correct CPAN version number is a floating point number with at least  2  digits  after  the\ndecimal.  You can test whether it conforms to CPAN by using\n\nperl -MExtUtils::MakeMaker -le 'print MM->parseversion(shift)' \\\n'Foo.pm'\n\nIf you want to release a 'beta' or 'alpha' version of a module but don't want CPAN.pm to list\nit  as most recent use an '' after the regular version number followed by at least 2 digits,\neg. 1.2001.  If you do this, the following idiom is recommended:\n\nour $VERSION = \"1.1201\"; # so CPAN distribution will have\n# right filename\nour $XSVERSION = $VERSION; # only needed if you have XS code\n$VERSION = eval $VERSION; # so \"use Module 0.002\" won't warn on\n# underscore\n\nWith that trick MakeMaker will only read the first line and thus read the  underscore,  while\nthe  perl interpreter will evaluate the $VERSION and convert the string into a number.  Later\noperations that treat $VERSION as a number will then be able to do  so  without  provoking  a\nwarning about $VERSION not being a number.\n\nNever release anything (even a one-word documentation patch) without incrementing the number.\nEven  a  one-word  documentation  patch should result in a change in version at the sub-minor\nlevel.\n\nOnce picked, it is important to stick to your version scheme, without reducing the number  of\ndigits.   This is because \"downstream\" packagers, such as the FreeBSD ports system, interpret\nthe version numbers in various ways.  If you change the number  of  digits  in  your  version\nscheme,  you  can confuse these systems so they get the versions of your module out of order,\nwhich is obviously bad.\n"
                },
                {
                    "name": "Pre-requisites",
                    "content": "Module authors should carefully consider whether to rely on other modules, and which  modules\nto rely on.\n\nMost importantly, choose modules which are as stable as possible.  In order of preference:\n\n•   Core Perl modules\n\n•   Stable CPAN modules\n\n•   Unstable CPAN modules\n\n•   Modules not available from CPAN\n\nSpecify version requirements for other Perl modules in the pre-requisites in your Makefile.PL\nor Build.PL.\n\nBe  sure  to  specify  Perl  version  requirements  both  in Makefile.PL or Build.PL and with\n\"require 5.6.1\" or similar.  See the documentation on \"use VERSION\" for details.\n"
                },
                {
                    "name": "Testing",
                    "content": "All modules should be tested before distribution  (using  \"make  disttest\"),  and  the  tests\nshould  also  be  available  to  people  installing  the  modules  (using  \"make test\").  For\nModule::Build you would use the \"make test\" equivalent \"perl Build test\".\n\nThe importance of these tests is proportional to the alleged stability of a module.  A module\nwhich purports to be stable or which hopes to achieve wide use should adhere to as  strict  a\ntesting regime as possible.\n\nUseful  modules  to  help you write tests (with minimum impact on your development process or\nyour time) include Test::Simple, Carp::Assert and Test::Inline.  For more sophisticated  test\nsuites there are Test::More and Test::MockObject.\n"
                },
                {
                    "name": "Packaging",
                    "content": "Modules should be packaged using one of the standard packaging tools.  Currently you have the\nchoice  between ExtUtils::MakeMaker and the more platform independent Module::Build, allowing\nmodules to be installed in a consistent manner.  When using ExtUtils::MakeMaker, you can  use\n\"make  dist\"  to  create  your  package.   Tools  exist to help you to build your module in a\nMakeMaker-friendly  style.   These  include  ExtUtils::ModuleMaker  and   h2xs.    See   also\nperlnewmod.\n"
                },
                {
                    "name": "Licensing",
                    "content": "Make  sure  that  your  module has a license, and that the full text of it is included in the\ndistribution (unless it's a common one and the terms of the  license  don't  require  you  to\ninclude it).\n\nIf  you  don't  know  what license to use, dual licensing under the GPL and Artistic licenses\n(the same as Perl itself) is a good idea.  See perlgpl and perlartistic.\n"
                }
            ]
        },
        "COMMON PITFALLS": {
            "content": "",
            "subsections": [
                {
                    "name": "Reinventing the wheel",
                    "content": "There are certain application spaces which are already very, very well served by  CPAN.   One\nexample  is  templating  systems,  another is date and time modules, and there are many more.\nWhile it is a rite of passage to write your own version  of  these  things,  please  consider\ncarefully whether the Perl world really needs you to publish it.\n"
                },
                {
                    "name": "Trying to do too much",
                    "content": "Your  module  will be part of a developer's toolkit.  It will not, in itself, form the entire\ntoolkit.  It's tempting to add extra features until your code is a monolithic  system  rather\nthan a set of modular building blocks.\n"
                },
                {
                    "name": "Inappropriate documentation",
                    "content": "Don't  fall  into  the  trap  of  writing for the wrong audience.  Your primary audience is a\nreasonably experienced developer with at least a  moderate  understanding  of  your  module's\napplication  domain, who's just downloaded your module and wants to start using it as quickly\nas possible.\n\nTutorials, end-user documentation, research  papers,  FAQs  etc  are  not  appropriate  in  a\nmodule's  main  documentation.   If  you  really  want  to  write these, include them as sub-\ndocuments such as \"My::Module::Tutorial\" or \"My::Module::FAQ\" and provide a link in  the  SEE\nALSO section of the main documentation.\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "perlstyle\nGeneral Perl style guide\n\nperlnewmod\nHow to create a new module\n\nperlpod\nPOD documentation\n\npodchecker\nVerifies your POD's correctness\n\nPackaging Tools\nExtUtils::MakeMaker, Module::Build\n\nTesting tools\nTest::Simple, Test::Inline, Carp::Assert, Test::More, Test::MockObject\n\n<https://pause.perl.org/>\nPerl Authors Upload Server.  Contains links to information for module authors.\n\nAny good book on software engineering\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Kirrily \"Skud\" Robert <skud@cpan.org>\n\nperl v5.38.2                                 2026-08-18                              PERLMODSTYLE(1)",
            "subsections": []
        }
    },
    "summary": "perlmodstyle - Perl module style guide",
    "flags": [],
    "examples": [],
    "see_also": []
}