Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man1 / perlnewmod.1
CommitLineData
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"
134perlnewmod \- preparing a new module for distribution
135.SH "DESCRIPTION"
136.IX Header "DESCRIPTION"
137This document gives you some suggestions about how to go about writing
138Perl modules, preparing them for distribution, and making them available
139via \s-1CPAN\s0.
140.PP
141One of the things that makes Perl really powerful is the fact that Perl
142hackers tend to want to share the solutions to problems they've faced,
143so you and I don't have to battle with the same problem again.
144.PP
145The main way they do this is by abstracting the solution into a Perl
146module. If you don't know what one of these is, the rest of this
147document isn't going to be much use to you. You're also missing out on
148an awful lot of useful code; consider having a look at perlmod,
149perlmodlib and perlmodinstall before coming back here.
150.PP
151When you've found that there isn't a module available for what you're
152trying to do, and you've had to write the code yourself, consider
153packaging up the solution into a module and uploading it to \s-1CPAN\s0 so that
154others can benefit.
155.Sh "Warning"
156.IX Subsection "Warning"
157We're going to primarily concentrate on Perl-only modules here, rather
158than \s-1XS\s0 modules. \s-1XS\s0 modules serve a rather different purpose, and
159you should consider different things before distributing them \- the
160popularity of the library you are gluing, the portability to other
161operating systems, and so on. However, the notes on preparing the Perl
162side of the module and packaging and distributing it will apply equally
163well 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?"
166You should make a module out of any code that you think is going to be
167useful to others. Anything that's likely to fill a hole in the communal
168library and which someone else can slot directly into their program. Any
169part of your code which you can isolate and extract and plug into
170something else is a likely candidate.
171.PP
172Let's take an example. Suppose you're reading in data from a local
173format into a hash-of-hashes in Perl, turning that into a tree, walking
174the tree and then piping each node to an Acme Transmogrifier Server.
175.PP
176Now, quite a few people have the Acme Transmogrifier, and you've had to
177write something to talk the protocol from scratch \- you'd almost
178certainly want to make that into a module. The level at which you pitch
179it is up to you: you might want protocol-level modules analogous to
180Net::SMTP which then talk to higher level modules analogous
181to Mail::Send. The choice is yours, but you do want to get
182a module out for that server protocol.
183.PP
184Nobody else on the planet is going to talk your local data format, so we
185can ignore that. But what about the thing in the middle? Building tree
186structures from Perl variables and then traversing them is a nice,
187general problem, and if nobody's already written a module that does
188that, you might want to modularise that code too.
189.PP
190So hopefully you've now got a few ideas about what's good to modularise.
191Let's now see how it's done.
192.Sh "Step\-by\-step: Preparing the ground"
193.IX Subsection "Step-by-step: Preparing the ground"
194Before we even start scraping out the code, there are a few things we'll
195want to do in advance.
196.IP "Look around" 3
197.IX Item "Look around"
198Dig into a bunch of modules to see how they're written. I'd suggest
199starting with Text::Tabs, since it's in the standard
200library and is nice and simple, and then looking at something like
201Time::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
204These should give you an overall feel for how modules are laid out and
205written.
206.IP "Check it's new" 3
207.IX Item "Check it's new"
208There are a lot of modules on \s-1CPAN\s0, and it's easy to miss one that's
209similar to what you're planning on contributing. Have a good plough
210through the modules list and the \fIby-module\fR directories, and make sure
211you're not the one reinventing the wheel!
212.IP "Discuss the need" 3
213.IX Item "Discuss the need"
214You might love it. You might feel that everyone else needs it. But there
215might not actually be any real demand for it out there. If you're unsure
216about the demand you're module will have, consider sending out feelers
217on the \f(CW\*(C`comp.lang.perl.modules\*(C'\fR newsgroup, or as a last resort, ask the
218modules list at \f(CW\*(C`modules@perl.org\*(C'\fR. Remember that this is a closed list
219with a very long turn-around time \- be prepared to wait a good while for
220a response from them.
221.IP "Choose a name" 3
222.IX Item "Choose a name"
223Perl modules included on \s-1CPAN\s0 have a naming hierarchy you should try to
224fit in with. See perlmodlib for more details on how this works, and
225browse around \s-1CPAN\s0 and the modules list to get a feel of it. At the very
226least, remember this: modules should be title capitalised, (This::Thing)
227fit in with a category, and explain their purpose succinctly.
228.IP "Check again" 3
229.IX Item "Check again"
230While you're doing that, make really sure you haven't missed a module
231similar to the one you're about to write.
232.Sp
233When you've got your name sorted out and you're sure that your module is
234wanted 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"
239Originally a utility to convert C header files into \s-1XS\s0 modules,
240h2xs has become a useful utility for churning out skeletons for
241Perl-only modules as well. If you don't want to use the
242Autoloader which splits up big modules into smaller
243subroutine-sized chunks, you'll say something like this:
244.Sp
245.Vb 1
246\& h2xs -AX -n Net::Acme
247.Ve
248.Sp
249The \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
250specifies the name of the module.
251.IP "Use strict and warnings" 3
252.IX Item "Use strict and warnings"
253A module's code has to be warning and strict\-clean, since you can't
254guarantee the conditions that it'll be used under. Besides, you wouldn't
255want to distribute code that wasn't warning or strict-clean anyway,
256right?
257.IP "Use Carp" 3
258.IX Item "Use Carp"
259The Carp module allows you to present your error messages from
260the caller's perspective; this gives you a way to signal a problem with
261the 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
267the 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
274which looks like your module is doing something wrong. Instead, you want
275to 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
281You 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
284your 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
288standard way of exporting symbols and subroutines from your module into
289the caller's namespace. For instance, saying \f(CW\*(C`use Net::Acme qw(&frob)\*(C'\fR
290would import the \f(CW\*(C`frob\*(C'\fR subroutine.
291.Sp
292The package variable \f(CW@EXPORT\fR will determine which symbols will get
293exported when the caller simply says \f(CW\*(C`use Net::Acme\*(C'\fR \- you will hardly
294ever want to put anything in there. \f(CW@EXPORT_OK\fR, on the other hand,
295specifies which symbols you're willing to export. If you do want to
296export a bunch of symbols, use the \f(CW%EXPORT_TAGS\fR and define a standard
297export set \- look at Exporter for more details.
298.IP "Use plain old documentation" 3
299.IX Item "Use plain old documentation"
300The work isn't over until the paperwork is done, and you're going to
301need 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
303the format, look at perlpod for an introduction. Provide a good
304synopsis of how your module is used in code, a description, and then
305notes on the syntax and function of the individual subroutines or
306methods. Use Perl comments for developer notes and \s-1POD\s0 for end-user
307notes.
308.IP "Write tests" 3
309.IX Item "Write tests"
310You're encouraged to create self-tests for your module to ensure it's
311working as intended on the myriad platforms Perl supports; if you upload
312your module to \s-1CPAN\s0, a host of testers will build your module and send
313you the results of the tests. Again, \f(CW\*(C`h2xs\*(C'\fR provides a test framework
314which you can extend \- you should do something more than just checking
315your module will compile.
316.IP "Write the \s-1README\s0" 3
317.IX Item "Write the README"
318If 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
320the main \fIby-module\fR and \fIby-category\fR directories if you make it onto
321the modules list. It's a good idea to put here what the module actually
322does 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"
327Every developer publishing modules on \s-1CPAN\s0 needs a \s-1CPAN\s0 \s-1ID\s0. See the
328instructions at \f(CW\*(C`http://www.cpan.org/modules/04pause.html\*(C'\fR (or
329equivalent 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"
333Once again, \f(CW\*(C`h2xs\*(C'\fR has done all the work for you. It produces the
334standard \f(CW\*(C`Makefile.PL\*(C'\fR you'll have seen when you downloaded and
335installs modules, and this produces a Makefile with a \f(CW\*(C`dist\*(C'\fR target.
336.Sp
337Once you've ensured that your module passes its own tests \- always a
338good thing to make sure \- you can \f(CW\*(C`make dist\*(C'\fR, and the Makefile will
339hopefully produce you a nice tarball of your module, ready for upload.
340.IP "Upload the tarball" 3
341.IX Item "Upload the tarball"
342The email you got when you received your \s-1CPAN\s0 \s-1ID\s0 will tell you how to
343log in to \s-1PAUSE\s0, the Perl Authors Upload SErver. From the menus there,
344you can upload your module to \s-1CPAN\s0.
345.IP "Announce to the modules list" 3
346.IX Item "Announce to the modules list"
347Once uploaded, it'll sit unnoticed in your author directory. If you want
348it connected to the rest of the \s-1CPAN\s0, you'll need to tell the modules
349list about it. The best way to do this is to email them a line in the
350style 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
370plus a description of the module and why you think it should be
371included. If you hear nothing back, that means your module will
372probably appear on the modules list at the next update. Don't try
373subscribing to \f(CW\*(C`modules@perl.org\*(C'\fR; it's not another mailing list. Just
374have patience.
375.IP "Announce to clpa" 3
376.IX Item "Announce to clpa"
377If you have a burning desire to tell the world about your release, post
378an announcement to the moderated \f(CW\*(C`comp.lang.perl.announce\*(C'\fR newsgroup.
379.IP "Fix bugs!" 3
380.IX Item "Fix bugs!"
381Once you start accumulating users, they'll send you bug reports. If
382you're lucky, they'll even send you patches. Welcome to the joys of
383maintaining a software project...
384.SH "AUTHOR"
385.IX Header "AUTHOR"
386Simon Cozens, \f(CW\*(C`simon@cpan.org\*(C'\fR
387.SH "SEE ALSO"
388.IX Header "SEE ALSO"
389perlmod, perlmodlib, perlmodinstall, h2xs, strict,
390Carp, Exporter, perlpod, Test, ExtUtils::MakeMaker,
391http://www.cpan.org/ , Ken Williams' tutorial on building your own
392module at http://mathforum.org/~ken/perl_modules.html