CINXE.COM
perlnewmod - preparing a new module for distribution - Perldoc Browser
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>perlnewmod - preparing a new module for distribution - Perldoc Browser</title> <link rel="search" href="/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser"> <link rel="canonical" href="https://perldoc.perl.org/perlnewmod"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" /> <style> body { background: #f4f4f5; color: #020202; } .navbar-dark { background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%); background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%); background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0); background-repeat: repeat-x; } .navbar-dark .navbar-nav .nav-link, .navbar-dark .navbar-nav .nav-link:focus { color: #fff } .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 } #wrapperlicious { margin: 0 auto; font: 0.9em 'Helvetica Neue', Helvetica, sans-serif; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0; } #wrapperlicious h1 { font-size: 1.5em } #wrapperlicious h2 { font-size: 1.3em } #wrapperlicious h3 { font-size: 1.1em } #wrapperlicious h4 { font-size: 0.9em } #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3, #wrapperlicious h4, #wrapperlicious dt { color: #020202; margin-top: 1em; margin-bottom: 1em; position: relative; font-weight: bold; } #wrapperlicious a { color: inherit; text-decoration: underline } #wrapperlicious #toc { text-decoration: none } #wrapperlicious a:hover { color: #2a2a2a } #wrapperlicious a img { border: 0 } #wrapperlicious :not(pre) > code { color: inherit; background-color: rgba(0, 0, 0, 0.04); border-radius: 3px; font: 0.9em Consolas, Menlo, Monaco, monospace; padding: 0.3em; } #wrapperlicious dd { margin: 0; margin-left: 2em; } #wrapperlicious dt { color: #2a2a2a; font-weight: bold; margin-left: 0.9em; } #wrapperlicious p { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious li > p { margin-bottom: 0; margin-top: 0; } #wrapperlicious pre { border: 1px solid #c1c1c1; border-radius: 3px; font: 100% Consolas, Menlo, Monaco, monospace; margin-bottom: 1em; margin-top: 1em; } #wrapperlicious pre > code { display: block; background-color: #f6f6f6; font: 0.9em Consolas, Menlo, Monaco, monospace; line-height: 1.5em; text-align: left; white-space: pre; padding: 1em; } #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious ul { list-style-type: square; } #wrapperlicious ul ul { margin-bottom: 0px; margin-top: 0px; } #footer { font-size: 0.8em; padding-top: 0.5em; text-align: center; } #more { display: inline; font-size: 0.8em; } #perldocdiv { background-color: #fff; border: 1px solid #c1c1c1; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; margin-left: auto; margin-right: auto; padding: 3em; padding-top: 1em; max-width: 960px; } #moduleversion { float: right } #wrapperlicious .leading-notice { font-style: italic; padding-left: 1em; margin-top: 1em; margin-bottom: 1em; } #wrapperlicious .permalink { display: none; left: -0.75em; position: absolute; padding-right: 0.25em; text-decoration: none; } #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink, #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink, #wrapperlicious dt:hover .permalink { display: block; } </style> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-KVNWBNT5FB'); gtag('config', 'UA-50555-3'); </script> </head> <body> <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <a class="navbar-brand" href="/"><img src="/images/perl_camel_30.png" width="30" height="30" class="d-inline-block align-top" alt="Perl Camel Logo"> Perldoc Browser</a> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav mr-auto"> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.8.8</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-stable"> <a class="dropdown-item" href="/perlnewmod">Latest</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1/perlnewmod">5.40.1</a> <a class="dropdown-item" href="/5.40.0/perlnewmod">5.40.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3/perlnewmod">5.38.3</a> <a class="dropdown-item" href="/5.38.2/perlnewmod">5.38.2</a> <a class="dropdown-item" href="/5.38.1/perlnewmod">5.38.1</a> <a class="dropdown-item" href="/5.38.0/perlnewmod">5.38.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.36.3/perlnewmod">5.36.3</a> <a class="dropdown-item" href="/5.36.2/perlnewmod">5.36.2</a> <a class="dropdown-item" href="/5.36.1/perlnewmod">5.36.1</a> <a class="dropdown-item" href="/5.36.0/perlnewmod">5.36.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.34.3/perlnewmod">5.34.3</a> <a class="dropdown-item" href="/5.34.2/perlnewmod">5.34.2</a> <a class="dropdown-item" href="/5.34.1/perlnewmod">5.34.1</a> <a class="dropdown-item" href="/5.34.0/perlnewmod">5.34.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.32.1/perlnewmod">5.32.1</a> <a class="dropdown-item" href="/5.32.0/perlnewmod">5.32.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.30.3/perlnewmod">5.30.3</a> <a class="dropdown-item" href="/5.30.2/perlnewmod">5.30.2</a> <a class="dropdown-item" href="/5.30.1/perlnewmod">5.30.1</a> <a class="dropdown-item" href="/5.30.0/perlnewmod">5.30.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.28.3/perlnewmod">5.28.3</a> <a class="dropdown-item" href="/5.28.2/perlnewmod">5.28.2</a> <a class="dropdown-item" href="/5.28.1/perlnewmod">5.28.1</a> <a class="dropdown-item" href="/5.28.0/perlnewmod">5.28.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.26.3/perlnewmod">5.26.3</a> <a class="dropdown-item" href="/5.26.2/perlnewmod">5.26.2</a> <a class="dropdown-item" href="/5.26.1/perlnewmod">5.26.1</a> <a class="dropdown-item" href="/5.26.0/perlnewmod">5.26.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.24.4/perlnewmod">5.24.4</a> <a class="dropdown-item" href="/5.24.3/perlnewmod">5.24.3</a> <a class="dropdown-item" href="/5.24.2/perlnewmod">5.24.2</a> <a class="dropdown-item" href="/5.24.1/perlnewmod">5.24.1</a> <a class="dropdown-item" href="/5.24.0/perlnewmod">5.24.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.22.4/perlnewmod">5.22.4</a> <a class="dropdown-item" href="/5.22.3/perlnewmod">5.22.3</a> <a class="dropdown-item" href="/5.22.2/perlnewmod">5.22.2</a> <a class="dropdown-item" href="/5.22.1/perlnewmod">5.22.1</a> <a class="dropdown-item" href="/5.22.0/perlnewmod">5.22.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.20.3/perlnewmod">5.20.3</a> <a class="dropdown-item" href="/5.20.2/perlnewmod">5.20.2</a> <a class="dropdown-item" href="/5.20.1/perlnewmod">5.20.1</a> <a class="dropdown-item" href="/5.20.0/perlnewmod">5.20.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.18.4/perlnewmod">5.18.4</a> <a class="dropdown-item" href="/5.18.3/perlnewmod">5.18.3</a> <a class="dropdown-item" href="/5.18.2/perlnewmod">5.18.2</a> <a class="dropdown-item" href="/5.18.1/perlnewmod">5.18.1</a> <a class="dropdown-item" href="/5.18.0/perlnewmod">5.18.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.16.3/perlnewmod">5.16.3</a> <a class="dropdown-item" href="/5.16.2/perlnewmod">5.16.2</a> <a class="dropdown-item" href="/5.16.1/perlnewmod">5.16.1</a> <a class="dropdown-item" href="/5.16.0/perlnewmod">5.16.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.14.4/perlnewmod">5.14.4</a> <a class="dropdown-item" href="/5.14.3/perlnewmod">5.14.3</a> <a class="dropdown-item" href="/5.14.2/perlnewmod">5.14.2</a> <a class="dropdown-item" href="/5.14.1/perlnewmod">5.14.1</a> <a class="dropdown-item" href="/5.14.0/perlnewmod">5.14.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.12.5/perlnewmod">5.12.5</a> <a class="dropdown-item" href="/5.12.4/perlnewmod">5.12.4</a> <a class="dropdown-item" href="/5.12.3/perlnewmod">5.12.3</a> <a class="dropdown-item" href="/5.12.2/perlnewmod">5.12.2</a> <a class="dropdown-item" href="/5.12.1/perlnewmod">5.12.1</a> <a class="dropdown-item" href="/5.12.0/perlnewmod">5.12.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.10.1/perlnewmod">5.10.1</a> <a class="dropdown-item" href="/5.10.0/perlnewmod">5.10.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.9/perlnewmod">5.8.9</a> <a class="dropdown-item active" href="/5.8.8/perlnewmod">5.8.8</a> <a class="dropdown-item" href="/5.8.7/perlnewmod">5.8.7</a> <a class="dropdown-item" href="/5.8.6/perlnewmod">5.8.6</a> <a class="dropdown-item" href="/5.8.5/perlnewmod">5.8.5</a> <a class="dropdown-item" href="/5.8.4/perlnewmod">5.8.4</a> <a class="dropdown-item" href="/5.8.3/perlnewmod">5.8.3</a> <a class="dropdown-item" href="/5.8.2/perlnewmod">5.8.2</a> <a class="dropdown-item" href="/5.8.1/perlnewmod">5.8.1</a> <a class="dropdown-item" href="/5.8.0/perlnewmod">5.8.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.6.2/perlnewmod">5.6.2</a> <a class="dropdown-item" href="/5.6.1/perlnewmod">5.6.1</a> <a class="dropdown-item" href="/5.6.0/perlnewmod">5.6.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.005_04/perlnewmod">5.005_04</a> <a class="dropdown-item" href="/5.005_03/perlnewmod">5.005_03</a> <a class="dropdown-item" href="/5.005_02/perlnewmod">5.005_02</a> <a class="dropdown-item" href="/5.005_01/perlnewmod">5.005_01</a> <a class="dropdown-item" href="/5.005/perlnewmod">5.005</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-dev"> <a class="dropdown-item" href="/blead/perlnewmod">blead</a> <a class="dropdown-item" href="/5.41.10/perlnewmod">5.41.10</a> <a class="dropdown-item" href="/5.41.9/perlnewmod">5.41.9</a> <a class="dropdown-item" href="/5.41.8/perlnewmod">5.41.8</a> <a class="dropdown-item" href="/5.41.7/perlnewmod">5.41.7</a> <a class="dropdown-item" href="/5.41.6/perlnewmod">5.41.6</a> <a class="dropdown-item" href="/5.41.5/perlnewmod">5.41.5</a> <a class="dropdown-item" href="/5.41.4/perlnewmod">5.41.4</a> <a class="dropdown-item" href="/5.41.3/perlnewmod">5.41.3</a> <a class="dropdown-item" href="/5.41.2/perlnewmod">5.41.2</a> <a class="dropdown-item" href="/5.41.1/perlnewmod">5.41.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1-RC1/perlnewmod">5.40.1-RC1</a> <a class="dropdown-item" href="/5.40.0-RC2/perlnewmod">5.40.0-RC2</a> <a class="dropdown-item" href="/5.40.0-RC1/perlnewmod">5.40.0-RC1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.39.10/perlnewmod">5.39.10</a> <a class="dropdown-item" href="/5.39.9/perlnewmod">5.39.9</a> <a class="dropdown-item" href="/5.39.8/perlnewmod">5.39.8</a> <a class="dropdown-item" href="/5.39.7/perlnewmod">5.39.7</a> <a class="dropdown-item" href="/5.39.6/perlnewmod">5.39.6</a> <a class="dropdown-item" href="/5.39.5/perlnewmod">5.39.5</a> <a class="dropdown-item" href="/5.39.4/perlnewmod">5.39.4</a> <a class="dropdown-item" href="/5.39.3/perlnewmod">5.39.3</a> <a class="dropdown-item" href="/5.39.2/perlnewmod">5.39.2</a> <a class="dropdown-item" href="/5.39.1/perlnewmod">5.39.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3-RC1/perlnewmod">5.38.3-RC1</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-nav"> <a class="dropdown-item" href="/5.8.8/perl">Perl</a> <a class="dropdown-item" href="/5.8.8/perlintro">Intro</a> <a class="dropdown-item" href="/5.8.8/perl#Tutorials">Tutorials</a> <a class="dropdown-item" href="/5.8.8/perlfaq">FAQs</a> <a class="dropdown-item" href="/5.8.8/perl#Reference-Manual">Reference</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.8/perlop">Operators</a> <a class="dropdown-item" href="/5.8.8/functions">Functions</a> <a class="dropdown-item" href="/5.8.8/variables">Variables</a> <a class="dropdown-item" href="/5.8.8/modules">Modules</a> <a class="dropdown-item" href="/5.8.8/perlutil">Utilities</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.8/perldelta">Release Notes</a> <a class="dropdown-item" href="/5.8.8/perlcommunity">Community</a> <a class="dropdown-item" href="/5.8.8/perlhist">History</a> </div> </li> </ul> <ul class="navbar-nav"> <script> function set_expand (expand) { var perldocdiv = document.getElementById('perldocdiv'); var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width'); var expanded = (width == '' || width == 'none') ? true : false; if (expand === null) { expand = !expanded; } if ((expand && !expanded) || (!expand && expanded)) { perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px'); var button_classlist = document.getElementById('content-expand-button').classList; if (expand) { button_classlist.add('btn-light'); button_classlist.remove('btn-outline-light'); } else { button_classlist.add('btn-outline-light'); button_classlist.remove('btn-light'); } } return expand; } function toggle_expand () { var expand = set_expand(null); document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC'; } function read_expand () { return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function () { if (read_expand()) { set_expand(true); } }); } else if (read_expand()) { set_expand(true); } </script> <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-4" onclick="toggle_expand()">Expand</button> </ul> <form class="form-inline" method="get" action="/5.8.8/search"> <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search" value=""> </form> </div> </nav> <div id="wrapperlicious" class="container-fluid"> <div id="perldocdiv"> <div id="links"> <a href="/5.8.8/perlnewmod">perlnewmod</a> <div id="more"> (<a href="/5.8.8/perlnewmod.txt">source</a>, <a href="https://metacpan.org/pod/perlnewmod">CPAN</a>) </div> </div> <div class="leading-notice"> You are viewing the version of this documentation from Perl 5.8.8. <a href="/perlnewmod">View the latest version</a> </div> <h1><a id="toc">CONTENTS</a></h1> <ul> <li> <a class="text-decoration-none" href="#NAME">NAME</a> </li> <li> <a class="text-decoration-none" href="#DESCRIPTION">DESCRIPTION</a> <ul> <li> <a class="text-decoration-none" href="#Warning">Warning</a> </li> <li> <a class="text-decoration-none" href="#What-should-I-make-into-a-module?">What should I make into a module?</a> </li> <li> <a class="text-decoration-none" href="#Step-by-step:-Preparing-the-ground">Step-by-step: Preparing the ground</a> </li> <li> <a class="text-decoration-none" href="#Step-by-step:-Making-the-module">Step-by-step: Making the module</a> </li> <li> <a class="text-decoration-none" href="#Step-by-step:-Distributing-your-module">Step-by-step: Distributing your module</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#AUTHOR">AUTHOR</a> </li> <li> <a class="text-decoration-none" href="#SEE-ALSO">SEE ALSO</a> </li> </ul> <h1 id="NAME"><a class="permalink" href="#NAME">#</a>NAME</h1> <p>perlnewmod - preparing a new module for distribution</p> <h1 id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">#</a>DESCRIPTION</h1> <p>This document gives you some suggestions about how to go about writing Perl modules, preparing them for distribution, and making them available via CPAN.</p> <p>One of the things that makes Perl really powerful is the fact that Perl hackers tend to want to share the solutions to problems they've faced, so you and I don't have to battle with the same problem again.</p> <p>The main way they do this is by abstracting the solution into a Perl module. If you don't know what one of these is, the rest of this document isn't going to be much use to you. You're also missing out on an awful lot of useful code; consider having a look at <a href="/5.8.8/perlmod">perlmod</a>, <a href="/5.8.8/perlmodlib">perlmodlib</a> and <a href="/5.8.8/perlmodinstall">perlmodinstall</a> before coming back here.</p> <p>When you've found that there isn't a module available for what you're trying to do, and you've had to write the code yourself, consider packaging up the solution into a module and uploading it to CPAN so that others can benefit.</p> <h2 id="Warning"><a class="permalink" href="#Warning">#</a>Warning</h2> <p>We're going to primarily concentrate on Perl-only modules here, rather than XS modules. XS modules serve a rather different purpose, and you should consider different things before distributing them - the popularity of the library you are gluing, the portability to other operating systems, and so on. However, the notes on preparing the Perl side of the module and packaging and distributing it will apply equally well to an XS module as a pure-Perl one.</p> <h2 id="What-should-I-make-into-a-module?"><a class="permalink" href="#What-should-I-make-into-a-module?">#</a><a id="What"></a><a id="What-should-I-make-into-a-module"></a>What should I make into a module?</h2> <p>You should make a module out of any code that you think is going to be useful to others. Anything that's likely to fill a hole in the communal library and which someone else can slot directly into their program. Any part of your code which you can isolate and extract and plug into something else is a likely candidate.</p> <p>Let's take an example. Suppose you're reading in data from a local format into a hash-of-hashes in Perl, turning that into a tree, walking the tree and then piping each node to an Acme Transmogrifier Server.</p> <p>Now, quite a few people have the Acme Transmogrifier, and you've had to write something to talk the protocol from scratch - you'd almost certainly want to make that into a module. The level at which you pitch it is up to you: you might want protocol-level modules analogous to <a href="/5.8.8/Net::SMTP">Net::SMTP</a> which then talk to higher level modules analogous to <a href="/5.8.8/Mail::Send">Mail::Send</a>. The choice is yours, but you do want to get a module out for that server protocol.</p> <p>Nobody else on the planet is going to talk your local data format, so we can ignore that. But what about the thing in the middle? Building tree structures from Perl variables and then traversing them is a nice, general problem, and if nobody's already written a module that does that, you might want to modularise that code too.</p> <p>So hopefully you've now got a few ideas about what's good to modularise. Let's now see how it's done.</p> <h2 id="Step-by-step:-Preparing-the-ground"><a class="permalink" href="#Step-by-step:-Preparing-the-ground">#</a><a id="Step"></a>Step-by-step: Preparing the ground</h2> <p>Before we even start scraping out the code, there are a few things we'll want to do in advance.</p> <dl> <dt id="Look-around"><a class="permalink" href="#Look-around">#</a><a id="Look"></a>Look around</dt> <dd> <p>Dig into a bunch of modules to see how they're written. I'd suggest starting with <a href="/5.8.8/Text::Tabs">Text::Tabs</a>, since it's in the standard library and is nice and simple, and then looking at something a little more complex like <a href="/5.8.8/File::Copy">File::Copy</a>. For object oriented code, <code>WWW::Mechanize</code> or the <code>Email::*</code> modules provide some good examples.</p> <p>These should give you an overall feel for how modules are laid out and written.</p> </dd> <dt id="Check-it's-new"><a class="permalink" href="#Check-it's-new">#</a><a id="Check"></a><a id="Check-its-new"></a>Check it's new</dt> <dd> <p>There are a lot of modules on CPAN, and it's easy to miss one that's similar to what you're planning on contributing. Have a good plough through the <a href="http://search.cpan.org">http://search.cpan.org</a> and make sure you're not the one reinventing the wheel!</p> </dd> <dt id="Discuss-the-need"><a class="permalink" href="#Discuss-the-need">#</a><a id="Discuss"></a>Discuss the need</dt> <dd> <p>You might love it. You might feel that everyone else needs it. But there might not actually be any real demand for it out there. If you're unsure about the demand your module will have, consider sending out feelers on the <code>comp.lang.perl.modules</code> newsgroup, or as a last resort, ask the modules list at <code>modules@perl.org</code>. Remember that this is a closed list with a very long turn-around time - be prepared to wait a good while for a response from them.</p> </dd> <dt id="Choose-a-name"><a class="permalink" href="#Choose-a-name">#</a><a id="Choose"></a>Choose a name</dt> <dd> <p>Perl modules included on CPAN have a naming hierarchy you should try to fit in with. See <a href="/5.8.8/perlmodlib">perlmodlib</a> for more details on how this works, and browse around CPAN and the modules list to get a feel of it. At the very least, remember this: modules should be title capitalised, (This::Thing) fit in with a category, and explain their purpose succinctly.</p> </dd> <dt id="Check-again"><a class="permalink" href="#Check-again">#</a><a id="Check1"></a>Check again</dt> <dd> <p>While you're doing that, make really sure you haven't missed a module similar to the one you're about to write.</p> <p>When you've got your name sorted out and you're sure that your module is wanted and not currently available, it's time to start coding.</p> </dd> </dl> <h2 id="Step-by-step:-Making-the-module"><a class="permalink" href="#Step-by-step:-Making-the-module">#</a><a id="Step1"></a>Step-by-step: Making the module</h2> <dl> <dt id="Start-with-module-starter-or-h2xs"><a class="permalink" href="#Start-with-module-starter-or-h2xs">#</a><a id="Start"></a>Start with <i>module-starter</i> or <i>h2xs</i></dt> <dd> <p>The <i>module-starter</i> utility is distributed as part of the <a href="/5.8.8/Module::Starter">Module::Starter</a> CPAN package. It creates a directory with stubs of all the necessary files to start a new module, according to recent "best practice" for module development, and is invoked from the command line, thus:</p> <pre><code>module-starter --module=Foo::Bar \ --author="Your Name" --email=yourname@cpan.org</code></pre> <p>If you do not wish to install the <a href="/5.8.8/Module::Starter">Module::Starter</a> package from CPAN, <i>h2xs</i> is an older tool, originally intended for the development of XS modules, which comes packaged with the Perl distribution.</p> <p>A typical invocation of <a href="/5.8.8/h2xs">h2xs</a> for a pure Perl module is:</p> <pre><code class="plaintext">h2xs -AX --skip-exporter --use-new-tests -n Foo::Bar </code></pre> <p>The <code>-A</code> omits the Autoloader code, <code>-X</code> omits XS elements, <code>--skip-exporter</code> omits the Exporter code, <code>--use-new-tests</code> sets up a modern testing environment, and <code>-n</code> specifies the name of the module.</p> </dd> <dt id="Use-strict-and-warnings"><a class="permalink" href="#Use-strict-and-warnings">#</a><a id="Use"></a>Use <a href="/5.8.8/strict">strict</a> and <a href="/5.8.8/warnings">warnings</a></dt> <dd> <p>A module's code has to be warning and strict-clean, since you can't guarantee the conditions that it'll be used under. Besides, you wouldn't want to distribute code that wasn't warning or strict-clean anyway, right?</p> </dd> <dt id="Use-Carp"><a class="permalink" href="#Use-Carp">#</a><a id="Use1"></a>Use <a href="/5.8.8/Carp">Carp</a></dt> <dd> <p>The <a href="/5.8.8/Carp">Carp</a> module allows you to present your error messages from the caller's perspective; this gives you a way to signal a problem with the caller and not your module. For instance, if you say this:</p> <pre><code>warn "No hostname given";</code></pre> <p>the user will see something like this:</p> <pre><code class="plaintext">No hostname given at /usr/local/lib/perl5/site_perl/5.6.0/Net/Acme.pm line 123.</code></pre> <p>which looks like your module is doing something wrong. Instead, you want to put the blame on the user, and say this:</p> <pre><code class="plaintext">No hostname given at bad_code, line 10.</code></pre> <p>You do this by using <a href="/5.8.8/Carp">Carp</a> and replacing your <code>warn</code>s with <code>carp</code>s. If you need to <code>die</code>, say <code>croak</code> instead. However, keep <code>warn</code> and <code>die</code> in place for your sanity checks - where it really is your module at fault.</p> </dd> <dt id="Use-Exporter-wisely!"><a class="permalink" href="#Use-Exporter-wisely!">#</a><a id="Use2"></a><a id="Use-Exporter---wisely"></a>Use <a href="/5.8.8/Exporter">Exporter</a> - wisely!</dt> <dd> <p><a href="/5.8.8/Exporter">Exporter</a> gives you a standard way of exporting symbols and subroutines from your module into the caller's namespace. For instance, saying <code>use Net::Acme qw(&frob)</code> would import the <code>frob</code> subroutine.</p> <p>The package variable <code>@EXPORT</code> will determine which symbols will get exported when the caller simply says <code>use Net::Acme</code> - you will hardly ever want to put anything in there. <code>@EXPORT_OK</code>, on the other hand, specifies which symbols you're willing to export. If you do want to export a bunch of symbols, use the <code>%EXPORT_TAGS</code> and define a standard export set - look at <a href="/5.8.8/Exporter">Exporter</a> for more details.</p> </dd> <dt id="Use-plain-old-documentation"><a class="permalink" href="#Use-plain-old-documentation">#</a><a id="Use3"></a>Use <a href="/5.8.8/perlpod">plain old documentation</a></dt> <dd> <p>The work isn't over until the paperwork is done, and you're going to need to put in some time writing some documentation for your module. <code>module-starter</code> or <code>h2xs</code> will provide a stub for you to fill in; if you're not sure about the format, look at <a href="/5.8.8/perlpod">perlpod</a> for an introduction. Provide a good synopsis of how your module is used in code, a description, and then notes on the syntax and function of the individual subroutines or methods. Use Perl comments for developer notes and POD for end-user notes.</p> </dd> <dt id="Write-tests"><a class="permalink" href="#Write-tests">#</a><a id="Write"></a>Write tests</dt> <dd> <p>You're encouraged to create self-tests for your module to ensure it's working as intended on the myriad platforms Perl supports; if you upload your module to CPAN, a host of testers will build your module and send you the results of the tests. Again, <code>module-starter</code> and <code>h2xs</code> provide a test framework which you can extend - you should do something more than just checking your module will compile. <a href="/5.8.8/Test::Simple">Test::Simple</a> and <a href="/5.8.8/Test::More">Test::More</a> are good places to start when writing a test suite.</p> </dd> <dt id="Write-the-README"><a class="permalink" href="#Write-the-README">#</a><a id="Write1"></a>Write the README</dt> <dd> <p>If you're uploading to CPAN, the automated gremlins will extract the README file and place that in your CPAN directory. It'll also appear in the main <i>by-module</i> and <i>by-category</i> directories if you make it onto the modules list. It's a good idea to put here what the module actually does in detail, and the user-visible changes since the last release.</p> </dd> </dl> <h2 id="Step-by-step:-Distributing-your-module"><a class="permalink" href="#Step-by-step:-Distributing-your-module">#</a><a id="Step2"></a>Step-by-step: Distributing your module</h2> <dl> <dt id="Get-a-CPAN-user-ID"><a class="permalink" href="#Get-a-CPAN-user-ID">#</a><a id="Get"></a>Get a CPAN user ID</dt> <dd> <p>Every developer publishing modules on CPAN needs a CPAN ID. Visit <code>http://pause.perl.org/</code>, select "Request PAUSE Account", and wait for your request to be approved by the PAUSE administrators.</p> </dd> <dt id="perl-Makefile.PL;-make-test;-make-dist"><a class="permalink" href="#perl-Makefile.PL;-make-test;-make-dist">#</a><a id="perl"></a><a id="perl-Makefile.PL-make-test-make-dist"></a><code>perl Makefile.PL; make test; make dist</code></dt> <dd> <p>Once again, <code>module-starter</code> or <code>h2xs</code> has done all the work for you. They produce the standard <code>Makefile.PL</code> you see when you download and install modules, and this produces a Makefile with a <code>dist</code> target.</p> <p>Once you've ensured that your module passes its own tests - always a good thing to make sure - you can <code>make dist</code>, and the Makefile will hopefully produce you a nice tarball of your module, ready for upload.</p> </dd> <dt id="Upload-the-tarball"><a class="permalink" href="#Upload-the-tarball">#</a><a id="Upload"></a>Upload the tarball</dt> <dd> <p>The email you got when you received your CPAN ID will tell you how to log in to PAUSE, the Perl Authors Upload SErver. From the menus there, you can upload your module to CPAN.</p> </dd> <dt id="Announce-to-the-modules-list"><a class="permalink" href="#Announce-to-the-modules-list">#</a><a id="Announce"></a>Announce to the modules list</dt> <dd> <p>Once uploaded, it'll sit unnoticed in your author directory. If you want it connected to the rest of the CPAN, you'll need to go to "Register Namespace" on PAUSE. Once registered, your module will appear in the by-module and by-category listings on CPAN.</p> </dd> <dt id="Announce-to-clpa"><a class="permalink" href="#Announce-to-clpa">#</a><a id="Announce1"></a>Announce to clpa</dt> <dd> <p>If you have a burning desire to tell the world about your release, post an announcement to the moderated <code>comp.lang.perl.announce</code> newsgroup.</p> </dd> <dt id="Fix-bugs!"><a class="permalink" href="#Fix-bugs!">#</a><a id="Fix"></a><a id="Fix-bugs"></a>Fix bugs!</dt> <dd> <p>Once you start accumulating users, they'll send you bug reports. If you're lucky, they'll even send you patches. Welcome to the joys of maintaining a software project...</p> </dd> </dl> <h1 id="AUTHOR"><a class="permalink" href="#AUTHOR">#</a>AUTHOR</h1> <p>Simon Cozens, <code>simon@cpan.org</code></p> <p>Updated by Kirrily "Skud" Robert, <code>skud@cpan.org</code></p> <h1 id="SEE-ALSO"><a class="permalink" href="#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1> <p><a href="/5.8.8/perlmod">perlmod</a>, <a href="/5.8.8/perlmodlib">perlmodlib</a>, <a href="/5.8.8/perlmodinstall">perlmodinstall</a>, <a href="/5.8.8/h2xs">h2xs</a>, <a href="/5.8.8/strict">strict</a>, <a href="/5.8.8/Carp">Carp</a>, <a href="/5.8.8/Exporter">Exporter</a>, <a href="/5.8.8/perlpod">perlpod</a>, <a href="/5.8.8/Test::Simple">Test::Simple</a>, <a href="/5.8.8/Test::More">Test::More</a> <a href="/5.8.8/ExtUtils::MakeMaker">ExtUtils::MakeMaker</a>, <a href="/5.8.8/Module::Build">Module::Build</a>, <a href="/5.8.8/Module::Starter">Module::Starter</a> http://www.cpan.org/ , Ken Williams' tutorial on building your own module at http://mathforum.org/~ken/perl_modules.html</p> </div> <div id="footer"> <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p> <p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p> </div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script> <script src="/js/highlight.pack.js"></script> <script>hljs.highlightAll();</script> </body> </html>