Module review updates

I've just updated the review of modules for defining constants:


  • Christian Walde (MITHALDU) pointed out I'd missed enum, which is used to define sets of constants with values in sequence, akin to C's enum type.

  • As a result, I found enum::fields, which similarly is used to define sequences of constants. But it's aimed at defining names for accessing fields in class which uses an array ref under the hood, and supports extending the sequence of constants in a subclass.

  • I mailed p5p with some questions that came out of the review, and Zefram pointed out his modules Lexical::Import and Lexical::Var, both of which can be used to define compile-time immutable variable style constants, which can be used in the constant folding conditional compilation idiom. I always learn things about Perl when I do a review.


The first review I wrote covered modules for generating passwords. I've moved it out of blogs.perl.org and added two more modules. Both Crypt::PW44 and Crypt::XkcdPassword were inspired by the same xkcd cartoon!

I've taken over maintenance of Geo::Coder::HostIP, which is covered in the review of modules for locating an IP address. I've adopted modules from four of the five reviews I've done so far, usually to fix bugs and extend documentation.

The other two reviews, parsing User-Agent strings, and spelling out numbers in English are now published as static HTML as well, rather than in blogs.perl.org.

6 Comments

You missed the most important bit from Zefram :)

He detected that even SVf_READONLY protected constants are sometimes writable with ithreaded perls, so he wrote Scalar::Construct ::constant
which fixes that.

Hi Neil

I've been wondering if there is some module I (or we) could write which would help in our module-shoot-off work.

For anyone lucky! enough to have missed it, here's mine Countries and SubCountries.

Perhaps it would offer features such as:
o Accept a list of modules
o Check the latest version & date on metacpan
o Whatever

Any thoughts?

Great document, thanks!

In the case of use constant, keep in mind that defined constants are resolved at compile time only when they are not followed by "()".

You give the example $color_hash{BACKGROUND()} but it should be $color_hash{(BACKGROUND)} or $color_hash{+BACKGROUND}, else BACKGROUND() will not be inlined in the compilation phase and the function BACKGROUND will be called each time the line is executed...

Max.

Leave a comment

About Neil Bowers

user-pic Perl hacker since 1992.