in reply to Writing a Perl Module... problems

A couple improvements to your general writing style:
package Name::Name; use 5.6.0; # Always specify the minimum Perl your code expects to work + with. use strict; # Got this right. use warnings FATAL => 'all'; # If you're 5.6+, this catches a lot of s +illy mistakes. our $VERSION = '0.05'; # If you're 5.6+, this is a nicer way of writin +g that VERSION stuff. # MY CODE HERE 1; __END__ # Always put this here to tell you that there can never be any + code after this.
That happens to be the template for whenever I start a new .pm or .pl file in vim (minus the comments, of course).

Now - why do you want to call the methods Foo->meth() vs. having it be a library of functions? I've always thought that the way File::Spec does this is really freaking annoying. If you're a library of functions, then provide the functions for export. If you're an OO module, then use Moose (or any of the other 1235123123 OO modules on CPAN) to provide the OO stuff, have your users receive an object, and call methods on that. Just because you can do something is a poor reason to actually do it, especially in production. KISS is a good motto.


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^2: Writing a Perl Module... problems
by cosmicperl (Chaplain) on Sep 15, 2007 at 03:39 UTC
    I've added use '5.004'. I Already had __END__ (in my version anyway). I wont use 'our', I used it in the past and hit problems when installing my scripts on machines with older copies of Perl. Now I stick to 'use vars'.

    The module users do receive an object they call methods on.
Re^2: Writing a Perl Module... problems
by stvn (Monsignor) on Nov 12, 2007 at 05:57 UTC
    use 5.6.0;

    Just FYI - This actually breaks in 5.10, it should be 5.006. Here is what the docs say about it.

    v-string in use/require is non-portable
    (W portable) The use of v-strings is non-portable to older, pre-5.6, Perls. If you want your scripts to be backward portable, use the floating point version number: for example, instead of "use 5.6.1" say "use 5.006_001". This of course won't help: the older Perls won't suddenly start understanding newer features, but at least they will show a sensible error message indicating the required minimum version.

    -stvn