| perlnewmod Dokumentation zu Perl 5.8.0 | Download als POD | Wie kann ich hier etwas ändern? |
Dig into a bunch of modules to see how they're written. I'd suggest starting with Text::Tabs?, since it's in the standard library and is nice and simple, and then looking at something like Time::Zone?, File::Copy? and then some of the Mail::* modules if you're planning on writing object oriented code.
These should give you an overall feel for how modules are laid out and written.
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 modules list and the by-module directories, and make sure you're not the one reinventing the wheel!
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 you're module will have, consider sending out feelers on the comp.lang.perl.modules newsgroup, or as a last resort, ask the modules list at modules@perl.org . 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.
Perl modules included on CPAN have a naming hierarchy you should try to fit in with. See perlmodlib 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.
While you're doing that, make really sure you haven't missed a module similar to the one you're about to write.
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.
h2xs Originally a utility to convert C header files into XS modules, h2xs? has become a useful utility for churning out skeletons for Perl-only modules as well. If you don't want to use the Autoloader? which splits up big modules into smaller subroutine-sized chunks, you'll say something like this:
h2xs -AX -n Net::Acme
The -A omits the Autoloader code, -X omits XS elements, and -n specifies the name of the module.
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?
The Carp 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:
warn "No hostname given";
the user will see something like this:
No hostname given at /usr/local/lib/perl5/site_perl/5.6.0/Net/Acme.pm
line 123.
which looks like your module is doing something wrong. Instead, you want to put the blame on the user, and say this:
No hostname given at bad_code, line 10.
You do this by using Carp and replacing your warn s with carp s. If you need to die , say croak instead. However, keep warn and die in place for your sanity checks - where it really is your module at fault.
h2xs provides stubs for Exporter, which gives you a standard way of exporting symbols and subroutines from your module into the caller's namespace. For instance, saying use Net::Acme qw(&frob) would import the frob subroutine.
The package variable @EXPORT will determine which symbols will get exported when the caller simply says use Net::Acme - you will hardly ever want to put anything in there. @EXPORT_OK , on the other hand, specifies which symbols you're willing to export. If you do want to export a bunch of symbols, use the %EXPORT_TAGS and define a standard export set - look at Exporter for more details.
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. h2xs will provide a stub for you to fill in; if you're not sure about the format, look at perlpod 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.
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, h2xs provides a test framework which you can extend - you should do something more than just checking your module will compile.
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 by-module and by-category 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.
Every developer publishing modules on CPAN needs a CPAN ID. See the instructions at http://www.cpan.org/modules/04pause.html (or equivalent on your nearest mirror) to find out how to do this.
perl Makefile.PL; make test; make dist Once again, h2xs has done all the work for you. It produces the standard Makefile.PL you'll have seen when you downloaded and installs modules, and this produces a Makefile with a dist target.
Once you've ensured that your module passes its own tests - always a good thing to make sure - you can make dist , and the Makefile will hopefully produce you a nice tarball of your module, ready for upload.
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.
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 tell the modules list about it. The best way to do this is to email them a line in the style of the modules list, like this:
Net::Acme bdpOP Interface to Acme Frobnicator servers FOOBAR
^ ^^^^^ ^ ^
| ||||| Module description Your ID
| |||||
| ||||\-Public Licence: (p)standard Perl, (g)GPL, (b)BSD,
| |||| (l)LGPL, (a)rtistic, (o)ther
| ||||
| |||\- Interface: (O)OP, (r)eferences, (h)ybrid, (f)unctions
| |||
| ||\-- Language: (p)ure Perl, C(+)+, (h)ybrid, (C), (o)ther
| ||
Module |\--- Support: (d)eveloper, (m)ailing list, (u)senet, (n)one
Name |
\---- Development: (i)dea, (c)onstructions, (a)lpha, (b)eta,
(R)eleased, (M)ature, (S)tandard
plus a description of the module and why you think it should be included. If you hear nothing back, that means your module will probably appear on the modules list at the next update. Don't try subscribing to modules@perl.org ; it's not another mailing list. Just have patience.
If you have a burning desire to tell the world about your release, post an announcement to the moderated comp.lang.perl.announce newsgroup.
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...
simon@cpan.org