| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "ExtUtils::MakeMaker::Tutorial 3perl" |
| 58 |
.TH ExtUtils::MakeMaker::Tutorial 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
ExtUtils::MakeMaker::Tutorial \- Writing a module with MakeMaker |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 1 |
| 68 |
\& use ExtUtils::MakeMaker; |
| 69 |
\& |
| 70 |
\& WriteMakefile( |
| 71 |
\& NAME => \*(AqYour::Module\*(Aq, |
| 72 |
\& VERSION_FROM => \*(Aqlib/Your/Module.pm\*(Aq |
| 73 |
\& ); |
| 74 |
.Ve |
| 75 |
.SH DESCRIPTION |
| 76 |
.IX Header "DESCRIPTION" |
| 77 |
This is a short tutorial on writing a simple module with MakeMaker. |
| 78 |
It's really not that hard. |
| 79 |
.SS "The Mantra" |
| 80 |
.IX Subsection "The Mantra" |
| 81 |
MakeMaker modules are installed using this simple mantra |
| 82 |
.PP |
| 83 |
.Vb 4 |
| 84 |
\& perl Makefile.PL |
| 85 |
\& make |
| 86 |
\& make test |
| 87 |
\& make install |
| 88 |
.Ve |
| 89 |
.PP |
| 90 |
There are lots more commands and options, but the above will do it. |
| 91 |
.SS "The Layout" |
| 92 |
.IX Subsection "The Layout" |
| 93 |
The basic files in a module look something like this. |
| 94 |
.PP |
| 95 |
.Vb 3 |
| 96 |
\& Makefile.PL |
| 97 |
\& MANIFEST |
| 98 |
\& lib/Your/Module.pm |
| 99 |
.Ve |
| 100 |
.PP |
| 101 |
That's all that's strictly necessary. There's additional files you might |
| 102 |
want: |
| 103 |
.PP |
| 104 |
.Vb 8 |
| 105 |
\& lib/Your/Other/Module.pm |
| 106 |
\& t/some_test.t |
| 107 |
\& t/some_other_test.t |
| 108 |
\& Changes |
| 109 |
\& README |
| 110 |
\& INSTALL |
| 111 |
\& MANIFEST.SKIP |
| 112 |
\& bin/some_program |
| 113 |
.Ve |
| 114 |
.IP Makefile.PL 4 |
| 115 |
.IX Item "Makefile.PL" |
| 116 |
When you run Makefile.PL, it makes a Makefile. That's the whole point of |
| 117 |
MakeMaker. The Makefile.PL is a simple program which loads |
| 118 |
ExtUtils::MakeMaker and runs the \fBWriteMakefile()\fR function to generate a |
| 119 |
Makefile. |
| 120 |
.Sp |
| 121 |
Here's an example of what you need for a simple module: |
| 122 |
.Sp |
| 123 |
.Vb 1 |
| 124 |
\& use ExtUtils::MakeMaker; |
| 125 |
\& |
| 126 |
\& WriteMakefile( |
| 127 |
\& NAME => \*(AqYour::Module\*(Aq, |
| 128 |
\& VERSION_FROM => \*(Aqlib/Your/Module.pm\*(Aq |
| 129 |
\& ); |
| 130 |
.Ve |
| 131 |
.Sp |
| 132 |
NAME is the top-level namespace of your module. VERSION_FROM is the file |
| 133 |
which contains the \f(CW$VERSION\fR variable for the entire distribution. Typically |
| 134 |
this is the same as your top-level module. |
| 135 |
.IP MANIFEST 4 |
| 136 |
.IX Item "MANIFEST" |
| 137 |
A simple listing of all the files in your distribution. |
| 138 |
.Sp |
| 139 |
.Vb 3 |
| 140 |
\& Makefile.PL |
| 141 |
\& MANIFEST |
| 142 |
\& lib/Your/Module.pm |
| 143 |
.Ve |
| 144 |
.Sp |
| 145 |
File paths in a MANIFEST always use Unix conventions (ie. /) even if you're |
| 146 |
not on Unix. |
| 147 |
.Sp |
| 148 |
You can write this by hand or generate it with 'make manifest'. |
| 149 |
.Sp |
| 150 |
See ExtUtils::Manifest for more details. |
| 151 |
.IP lib/ 4 |
| 152 |
.IX Item "lib/" |
| 153 |
This is the directory where the .pm and .pod files you wish to have |
| 154 |
installed go. They are laid out according to namespace. So Foo::Bar |
| 155 |
is \fIlib/Foo/Bar.pm\fR. |
| 156 |
.IP t/ 4 |
| 157 |
.IX Item "t/" |
| 158 |
Tests for your modules go here. Each test filename ends with a .t. |
| 159 |
So \fIt/foo.t\fR 'make test' will run these tests. |
| 160 |
.Sp |
| 161 |
Typically, the \fIt/\fR test directory is flat, with all test files located |
| 162 |
directly within it. However, you can nest tests within subdirectories, for |
| 163 |
example: |
| 164 |
.Sp |
| 165 |
.Vb 1 |
| 166 |
\& t/foo/subdir_test.t |
| 167 |
.Ve |
| 168 |
.Sp |
| 169 |
To do this, you need to inform \f(CWWriteMakefile()\fR in your \fIMakefile.PL\fR file |
| 170 |
in the following fashion: |
| 171 |
.Sp |
| 172 |
.Vb 1 |
| 173 |
\& test => {TESTS => \*(Aqt/*.t t/*/*.t\*(Aq} |
| 174 |
.Ve |
| 175 |
.Sp |
| 176 |
That will run all tests in \fIt/\fR, as well as all tests in all subdirectories |
| 177 |
that reside under \fIt/\fR. You can nest as deeply as makes sense for your project. |
| 178 |
Simply add another entry in the test location string. For example, to test: |
| 179 |
.Sp |
| 180 |
.Vb 1 |
| 181 |
\& t/foo/bar/subdir_test.t |
| 182 |
.Ve |
| 183 |
.Sp |
| 184 |
You would use the following \f(CW\*(C`test\*(C'\fR directive: |
| 185 |
.Sp |
| 186 |
.Vb 1 |
| 187 |
\& test => {TESTS => \*(Aqt/*.t t/*/*/*.t\*(Aq} |
| 188 |
.Ve |
| 189 |
.Sp |
| 190 |
Note that in the above example, tests in the first subdirectory will not be |
| 191 |
run. To run all tests in the intermediary subdirectory preceding the one |
| 192 |
the test files are in, you need to explicitly note it: |
| 193 |
.Sp |
| 194 |
.Vb 1 |
| 195 |
\& test => {TESTS => \*(Aqt/*.t t/*/*.t t/*/*/*.t\*(Aq} |
| 196 |
.Ve |
| 197 |
.Sp |
| 198 |
You don't need to specify wildcards if you only want to test within specific |
| 199 |
subdirectories. The following example will only run tests in \fIt/foo\fR: |
| 200 |
.Sp |
| 201 |
.Vb 1 |
| 202 |
\& test => {TESTS => \*(Aqt/foo/*.t\*(Aq} |
| 203 |
.Ve |
| 204 |
.Sp |
| 205 |
Tests are run from the top level of your distribution. So inside a test |
| 206 |
you would refer to ./lib to enter the lib directory, for example. |
| 207 |
.IP Changes 4 |
| 208 |
.IX Item "Changes" |
| 209 |
A log of changes you've made to this module. The layout is free-form. |
| 210 |
Here's an example: |
| 211 |
.Sp |
| 212 |
.Vb 3 |
| 213 |
\& 1.01 Fri Apr 11 00:21:25 PDT 2003 |
| 214 |
\& \- thing() does some stuff now |
| 215 |
\& \- fixed the wiggy bug in withit() |
| 216 |
\& |
| 217 |
\& 1.00 Mon Apr 7 00:57:15 PDT 2003 |
| 218 |
\& \- "Rain of Frogs" now supported |
| 219 |
.Ve |
| 220 |
.IP README 4 |
| 221 |
.IX Item "README" |
| 222 |
A short description of your module, what it does, why someone would use it |
| 223 |
and its limitations. CPAN automatically pulls your README file out of |
| 224 |
the archive and makes it available to CPAN users, it is the first thing |
| 225 |
they will read to decide if your module is right for them. |
| 226 |
.IP INSTALL 4 |
| 227 |
.IX Item "INSTALL" |
| 228 |
Instructions on how to install your module along with any dependencies. |
| 229 |
Suggested information to include here: |
| 230 |
.Sp |
| 231 |
.Vb 3 |
| 232 |
\& any extra modules required for use |
| 233 |
\& the minimum version of Perl required |
| 234 |
\& if only works on certain operating systems |
| 235 |
.Ve |
| 236 |
.IP MANIFEST.SKIP 4 |
| 237 |
.IX Item "MANIFEST.SKIP" |
| 238 |
A file full of regular expressions to exclude when using 'make |
| 239 |
manifest' to generate the MANIFEST. These regular expressions |
| 240 |
are checked against each file path found in the distribution (so |
| 241 |
you're matching against "t/foo.t" not "foo.t"). |
| 242 |
.Sp |
| 243 |
Here's a sample: |
| 244 |
.Sp |
| 245 |
.Vb 3 |
| 246 |
\& ~$ # ignore emacs and vim backup files |
| 247 |
\& .bak$ # ignore manual backups |
| 248 |
\& \e# # ignore CVS old revision files and emacs temp files |
| 249 |
.Ve |
| 250 |
.Sp |
| 251 |
Since # can be used for comments, # must be escaped. |
| 252 |
.Sp |
| 253 |
MakeMaker comes with a default MANIFEST.SKIP to avoid things like |
| 254 |
version control directories and backup files. Specifying your own |
| 255 |
will override this default. |
| 256 |
.IP bin/ 4 |
| 257 |
.IX Item "bin/" |
| 258 |
.SH "SEE ALSO" |
| 259 |
.IX Header "SEE ALSO" |
| 260 |
perlmodstyle gives stylistic help writing a module. |
| 261 |
.PP |
| 262 |
perlnewmod gives more information about how to write a module. |
| 263 |
.PP |
| 264 |
There are modules to help you through the process of writing a module: |
| 265 |
ExtUtils::ModuleMaker, Module::Starter, Minilla::Tutorial, |
| 266 |
Dist::Milla::Tutorial, Dist::Zilla::Starter |