Hack 73. Know What s Core and When


Hack 73. Know What's Core and When

Keep track of the core modules you're using and not using.

Not every Perl installation is fortunate enough to be able to install the latest released version of the core as soon as it is available or to install the freshest modules off of the CPAN as soon as they hit the index. Some developers on legacy systems have to be very careful to avoid the wrath of their system administrators for whom stability is a way of life, not just a goal.

Though Perl 5's standard library has always provided a lot of features, it has grown over time. What's standard and usable everywhere as of Perl 5.8.7 isn't the same as what existed as of Perl 5.004. How can you know, though, without either digging through release notes or watching your carefully constructed code break when put on the testing machine?

Use Module::CoreList.

The Hack

Suppose you've read perldoc perlport and have resolved never to write unportable, hardcoded file paths anymore. You've browsed the documentation of File::Spec and realize that a few careful calls can make your code more likely to work on platforms as exotic as Windows (or even VMS, but that's scary).

Unfortunately for your good intentions, your development platform is a box that shipped with Perl 5.004 from way back when the network really was the computer. Before replacing all of your join( '/', @path, $filename ) code with calls to shiny catfile( ), your sense of duty and due diligence causes you to ask "Wait, when did File::Spec enter the core?"

Install Module::CoreList from the CPAN, and then bring up a command line:

$ perl -MModule::CoreList -e 'print Module::CoreList->first_release(                "File::Spec" ), "\\n"' 5.005

Good thing you checked. Now you have three choices: submit the paperwork to upgrade Perl on that machine to something released this millennium,[3] bribe the sysadmin to install File::Spec on that machine, or sadly give up on the idea that this code will work unmodified on Mac OS classic.

[3] Perl 5.004_05 released in April 1999.

Checking by version

Maybe knowing the first occurrence of the module isn't good enough. Consider the case of poor Test::Simple. Though the first versions were useful and good, it wasn't until release 0.30 and the introduction of Test::Builder that the golden age of Perl testing began. If you haven't upgraded Perl in a couple of years and rely on the universal Perl testing backend, what's the minimum version of Perl you can use without having to install a newer Test::Simple?

Pass an optional second value to first_release( ), the version number of the package:

$ perl -MModule::CoreList -e 'print Module::CoreList->first_release(                   "Test::Simple", '0.30' ), "\\n"' 5.007003

Anything released after Perl 5.7.3 contains Test::Builder. Of course, note that this doesn't mean that releases of Perl with lower numbers don't contain Test::BuilderPerl 5.6.2, released after Perl 5.7.3, contains Test::Simple 0.47.

If you're really curious, and especially if you end up with information about development releases of Perl, browse through the data structures at the end of Module::CoreList by hand [Hack #2] for more detailed information.

When did Module::CoreList make it in the core? Perl 5.9.2.



Perl Hacks
Perl Hacks: Tips & Tools for Programming, Debugging, and Surviving
ISBN: 0596526741
EAN: 2147483647
Year: 2004
Pages: 141

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net