Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "PERLNEWMOD 1" | |
132 | .TH PERLNEWMOD 1 "2002-06-08" "perl v5.8.0" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | perlnewmod \- preparing a new module for distribution | |
135 | .SH "DESCRIPTION" | |
136 | .IX Header "DESCRIPTION" | |
137 | This document gives you some suggestions about how to go about writing | |
138 | Perl modules, preparing them for distribution, and making them available | |
139 | via \s-1CPAN\s0. | |
140 | .PP | |
141 | One of the things that makes Perl really powerful is the fact that Perl | |
142 | hackers tend to want to share the solutions to problems they've faced, | |
143 | so you and I don't have to battle with the same problem again. | |
144 | .PP | |
145 | The main way they do this is by abstracting the solution into a Perl | |
146 | module. If you don't know what one of these is, the rest of this | |
147 | document isn't going to be much use to you. You're also missing out on | |
148 | an awful lot of useful code; consider having a look at perlmod, | |
149 | perlmodlib and perlmodinstall before coming back here. | |
150 | .PP | |
151 | When you've found that there isn't a module available for what you're | |
152 | trying to do, and you've had to write the code yourself, consider | |
153 | packaging up the solution into a module and uploading it to \s-1CPAN\s0 so that | |
154 | others can benefit. | |
155 | .Sh "Warning" | |
156 | .IX Subsection "Warning" | |
157 | We're going to primarily concentrate on Perl-only modules here, rather | |
158 | than \s-1XS\s0 modules. \s-1XS\s0 modules serve a rather different purpose, and | |
159 | you should consider different things before distributing them \- the | |
160 | popularity of the library you are gluing, the portability to other | |
161 | operating systems, and so on. However, the notes on preparing the Perl | |
162 | side of the module and packaging and distributing it will apply equally | |
163 | well to an \s-1XS\s0 module as a pure-Perl one. | |
164 | .Sh "What should I make into a module?" | |
165 | .IX Subsection "What should I make into a module?" | |
166 | You should make a module out of any code that you think is going to be | |
167 | useful to others. Anything that's likely to fill a hole in the communal | |
168 | library and which someone else can slot directly into their program. Any | |
169 | part of your code which you can isolate and extract and plug into | |
170 | something else is a likely candidate. | |
171 | .PP | |
172 | Let's take an example. Suppose you're reading in data from a local | |
173 | format into a hash-of-hashes in Perl, turning that into a tree, walking | |
174 | the tree and then piping each node to an Acme Transmogrifier Server. | |
175 | .PP | |
176 | Now, quite a few people have the Acme Transmogrifier, and you've had to | |
177 | write something to talk the protocol from scratch \- you'd almost | |
178 | certainly want to make that into a module. The level at which you pitch | |
179 | it is up to you: you might want protocol-level modules analogous to | |
180 | Net::SMTP which then talk to higher level modules analogous | |
181 | to Mail::Send. The choice is yours, but you do want to get | |
182 | a module out for that server protocol. | |
183 | .PP | |
184 | Nobody else on the planet is going to talk your local data format, so we | |
185 | can ignore that. But what about the thing in the middle? Building tree | |
186 | structures from Perl variables and then traversing them is a nice, | |
187 | general problem, and if nobody's already written a module that does | |
188 | that, you might want to modularise that code too. | |
189 | .PP | |
190 | So hopefully you've now got a few ideas about what's good to modularise. | |
191 | Let's now see how it's done. | |
192 | .Sh "Step\-by\-step: Preparing the ground" | |
193 | .IX Subsection "Step-by-step: Preparing the ground" | |
194 | Before we even start scraping out the code, there are a few things we'll | |
195 | want to do in advance. | |
196 | .IP "Look around" 3 | |
197 | .IX Item "Look around" | |
198 | Dig into a bunch of modules to see how they're written. I'd suggest | |
199 | starting with Text::Tabs, since it's in the standard | |
200 | library and is nice and simple, and then looking at something like | |
201 | Time::Zone, File::Copy and then some of the | |
202 | \&\f(CW\*(C`Mail::*\*(C'\fR modules if you're planning on writing object oriented code. | |
203 | .Sp | |
204 | These should give you an overall feel for how modules are laid out and | |
205 | written. | |
206 | .IP "Check it's new" 3 | |
207 | .IX Item "Check it's new" | |
208 | There are a lot of modules on \s-1CPAN\s0, and it's easy to miss one that's | |
209 | similar to what you're planning on contributing. Have a good plough | |
210 | through the modules list and the \fIby-module\fR directories, and make sure | |
211 | you're not the one reinventing the wheel! | |
212 | .IP "Discuss the need" 3 | |
213 | .IX Item "Discuss the need" | |
214 | You might love it. You might feel that everyone else needs it. But there | |
215 | might not actually be any real demand for it out there. If you're unsure | |
216 | about the demand you're module will have, consider sending out feelers | |
217 | on the \f(CW\*(C`comp.lang.perl.modules\*(C'\fR newsgroup, or as a last resort, ask the | |
218 | modules list at \f(CW\*(C`modules@perl.org\*(C'\fR. Remember that this is a closed list | |
219 | with a very long turn-around time \- be prepared to wait a good while for | |
220 | a response from them. | |
221 | .IP "Choose a name" 3 | |
222 | .IX Item "Choose a name" | |
223 | Perl modules included on \s-1CPAN\s0 have a naming hierarchy you should try to | |
224 | fit in with. See perlmodlib for more details on how this works, and | |
225 | browse around \s-1CPAN\s0 and the modules list to get a feel of it. At the very | |
226 | least, remember this: modules should be title capitalised, (This::Thing) | |
227 | fit in with a category, and explain their purpose succinctly. | |
228 | .IP "Check again" 3 | |
229 | .IX Item "Check again" | |
230 | While you're doing that, make really sure you haven't missed a module | |
231 | similar to the one you're about to write. | |
232 | .Sp | |
233 | When you've got your name sorted out and you're sure that your module is | |
234 | wanted and not currently available, it's time to start coding. | |
235 | .Sh "Step\-by\-step: Making the module" | |
236 | .IX Subsection "Step-by-step: Making the module" | |
237 | .IP "Start with \fIh2xs\fR" 3 | |
238 | .IX Item "Start with h2xs" | |
239 | Originally a utility to convert C header files into \s-1XS\s0 modules, | |
240 | h2xs has become a useful utility for churning out skeletons for | |
241 | Perl-only modules as well. If you don't want to use the | |
242 | Autoloader which splits up big modules into smaller | |
243 | subroutine-sized chunks, you'll say something like this: | |
244 | .Sp | |
245 | .Vb 1 | |
246 | \& h2xs -AX -n Net::Acme | |
247 | .Ve | |
248 | .Sp | |
249 | The \f(CW\*(C`\-A\*(C'\fR omits the Autoloader code, \f(CW\*(C`\-X\*(C'\fR omits \s-1XS\s0 elements, and \f(CW\*(C`\-n\*(C'\fR | |
250 | specifies the name of the module. | |
251 | .IP "Use strict and warnings" 3 | |
252 | .IX Item "Use strict and warnings" | |
253 | A module's code has to be warning and strict\-clean, since you can't | |
254 | guarantee the conditions that it'll be used under. Besides, you wouldn't | |
255 | want to distribute code that wasn't warning or strict-clean anyway, | |
256 | right? | |
257 | .IP "Use Carp" 3 | |
258 | .IX Item "Use Carp" | |
259 | The Carp module allows you to present your error messages from | |
260 | the caller's perspective; this gives you a way to signal a problem with | |
261 | the caller and not your module. For instance, if you say this: | |
262 | .Sp | |
263 | .Vb 1 | |
264 | \& warn "No hostname given"; | |
265 | .Ve | |
266 | .Sp | |
267 | the user will see something like this: | |
268 | .Sp | |
269 | .Vb 2 | |
270 | \& No hostname given at /usr/local/lib/perl5/site_perl/5.6.0/Net/Acme.pm | |
271 | \& line 123. | |
272 | .Ve | |
273 | .Sp | |
274 | which looks like your module is doing something wrong. Instead, you want | |
275 | to put the blame on the user, and say this: | |
276 | .Sp | |
277 | .Vb 1 | |
278 | \& No hostname given at bad_code, line 10. | |
279 | .Ve | |
280 | .Sp | |
281 | You do this by using Carp and replacing your \f(CW\*(C`warn\*(C'\fRs with | |
282 | \&\f(CW\*(C`carp\*(C'\fRs. If you need to \f(CW\*(C`die\*(C'\fR, say \f(CW\*(C`croak\*(C'\fR instead. However, keep | |
283 | \&\f(CW\*(C`warn\*(C'\fR and \f(CW\*(C`die\*(C'\fR in place for your sanity checks \- where it really is | |
284 | your module at fault. | |
285 | .IP "Use Exporter \- wisely!" 3 | |
286 | .IX Item "Use Exporter - wisely!" | |
287 | \&\f(CW\*(C`h2xs\*(C'\fR provides stubs for Exporter, which gives you a | |
288 | standard way of exporting symbols and subroutines from your module into | |
289 | the caller's namespace. For instance, saying \f(CW\*(C`use Net::Acme qw(&frob)\*(C'\fR | |
290 | would import the \f(CW\*(C`frob\*(C'\fR subroutine. | |
291 | .Sp | |
292 | The package variable \f(CW@EXPORT\fR will determine which symbols will get | |
293 | exported when the caller simply says \f(CW\*(C`use Net::Acme\*(C'\fR \- you will hardly | |
294 | ever want to put anything in there. \f(CW@EXPORT_OK\fR, on the other hand, | |
295 | specifies which symbols you're willing to export. If you do want to | |
296 | export a bunch of symbols, use the \f(CW%EXPORT_TAGS\fR and define a standard | |
297 | export set \- look at Exporter for more details. | |
298 | .IP "Use plain old documentation" 3 | |
299 | .IX Item "Use plain old documentation" | |
300 | The work isn't over until the paperwork is done, and you're going to | |
301 | need to put in some time writing some documentation for your module. | |
302 | \&\f(CW\*(C`h2xs\*(C'\fR will provide a stub for you to fill in; if you're not sure about | |
303 | the format, look at perlpod for an introduction. Provide a good | |
304 | synopsis of how your module is used in code, a description, and then | |
305 | notes on the syntax and function of the individual subroutines or | |
306 | methods. Use Perl comments for developer notes and \s-1POD\s0 for end-user | |
307 | notes. | |
308 | .IP "Write tests" 3 | |
309 | .IX Item "Write tests" | |
310 | You're encouraged to create self-tests for your module to ensure it's | |
311 | working as intended on the myriad platforms Perl supports; if you upload | |
312 | your module to \s-1CPAN\s0, a host of testers will build your module and send | |
313 | you the results of the tests. Again, \f(CW\*(C`h2xs\*(C'\fR provides a test framework | |
314 | which you can extend \- you should do something more than just checking | |
315 | your module will compile. | |
316 | .IP "Write the \s-1README\s0" 3 | |
317 | .IX Item "Write the README" | |
318 | If you're uploading to \s-1CPAN\s0, the automated gremlins will extract the | |
319 | \&\s-1README\s0 file and place that in your \s-1CPAN\s0 directory. It'll also appear in | |
320 | the main \fIby-module\fR and \fIby-category\fR directories if you make it onto | |
321 | the modules list. It's a good idea to put here what the module actually | |
322 | does in detail, and the user-visible changes since the last release. | |
323 | .Sh "Step\-by\-step: Distributing your module" | |
324 | .IX Subsection "Step-by-step: Distributing your module" | |
325 | .IP "Get a \s-1CPAN\s0 user \s-1ID\s0" 3 | |
326 | .IX Item "Get a CPAN user ID" | |
327 | Every developer publishing modules on \s-1CPAN\s0 needs a \s-1CPAN\s0 \s-1ID\s0. See the | |
328 | instructions at \f(CW\*(C`http://www.cpan.org/modules/04pause.html\*(C'\fR (or | |
329 | equivalent on your nearest mirror) to find out how to do this. | |
330 | .ie n .IP """perl Makefile.PL; make test; make dist""" 3 | |
331 | .el .IP "\f(CWperl Makefile.PL; make test; make dist\fR" 3 | |
332 | .IX Item "perl Makefile.PL; make test; make dist" | |
333 | Once again, \f(CW\*(C`h2xs\*(C'\fR has done all the work for you. It produces the | |
334 | standard \f(CW\*(C`Makefile.PL\*(C'\fR you'll have seen when you downloaded and | |
335 | installs modules, and this produces a Makefile with a \f(CW\*(C`dist\*(C'\fR target. | |
336 | .Sp | |
337 | Once you've ensured that your module passes its own tests \- always a | |
338 | good thing to make sure \- you can \f(CW\*(C`make dist\*(C'\fR, and the Makefile will | |
339 | hopefully produce you a nice tarball of your module, ready for upload. | |
340 | .IP "Upload the tarball" 3 | |
341 | .IX Item "Upload the tarball" | |
342 | The email you got when you received your \s-1CPAN\s0 \s-1ID\s0 will tell you how to | |
343 | log in to \s-1PAUSE\s0, the Perl Authors Upload SErver. From the menus there, | |
344 | you can upload your module to \s-1CPAN\s0. | |
345 | .IP "Announce to the modules list" 3 | |
346 | .IX Item "Announce to the modules list" | |
347 | Once uploaded, it'll sit unnoticed in your author directory. If you want | |
348 | it connected to the rest of the \s-1CPAN\s0, you'll need to tell the modules | |
349 | list about it. The best way to do this is to email them a line in the | |
350 | style of the modules list, like this: | |
351 | .Sp | |
352 | .Vb 15 | |
353 | \& Net::Acme bdpOP Interface to Acme Frobnicator servers FOOBAR | |
354 | \& ^ ^^^^^ ^ ^ | |
355 | \& | ||||| Module description Your ID | |
356 | \& | ||||| | |
357 | \& | ||||\e-Public Licence: (p)standard Perl, (g)GPL, (b)BSD, | |
358 | \& | |||| (l)LGPL, (a)rtistic, (o)ther | |
359 | \& | |||| | |
360 | \& | |||\e- Interface: (O)OP, (r)eferences, (h)ybrid, (f)unctions | |
361 | \& | ||| | |
362 | \& | ||\e-- Language: (p)ure Perl, C(+)+, (h)ybrid, (C), (o)ther | |
363 | \& | || | |
364 | \& Module |\e--- Support: (d)eveloper, (m)ailing list, (u)senet, (n)one | |
365 | \& Name | | |
366 | \& \e---- Development: (i)dea, (c)onstructions, (a)lpha, (b)eta, | |
367 | \& (R)eleased, (M)ature, (S)tandard | |
368 | .Ve | |
369 | .Sp | |
370 | plus a description of the module and why you think it should be | |
371 | included. If you hear nothing back, that means your module will | |
372 | probably appear on the modules list at the next update. Don't try | |
373 | subscribing to \f(CW\*(C`modules@perl.org\*(C'\fR; it's not another mailing list. Just | |
374 | have patience. | |
375 | .IP "Announce to clpa" 3 | |
376 | .IX Item "Announce to clpa" | |
377 | If you have a burning desire to tell the world about your release, post | |
378 | an announcement to the moderated \f(CW\*(C`comp.lang.perl.announce\*(C'\fR newsgroup. | |
379 | .IP "Fix bugs!" 3 | |
380 | .IX Item "Fix bugs!" | |
381 | Once you start accumulating users, they'll send you bug reports. If | |
382 | you're lucky, they'll even send you patches. Welcome to the joys of | |
383 | maintaining a software project... | |
384 | .SH "AUTHOR" | |
385 | .IX Header "AUTHOR" | |
386 | Simon Cozens, \f(CW\*(C`simon@cpan.org\*(C'\fR | |
387 | .SH "SEE ALSO" | |
388 | .IX Header "SEE ALSO" | |
389 | perlmod, perlmodlib, perlmodinstall, h2xs, strict, | |
390 | Carp, Exporter, perlpod, Test, ExtUtils::MakeMaker, | |
391 | http://www.cpan.org/ , Ken Williams' tutorial on building your own | |
392 | module at http://mathforum.org/~ken/perl_modules.html |