Modern::Perl Updates

The Modern::Perl CPAN distribution is much more conservative than I think most people thought it would be when I first released it. (Count me in that group.) Where I once intended to collect a bunch of useful CPAN modules in the style of Task::Kensho or perl5i, both of those do what they do far better than I can do.

Instead, I see Modern::Perl as enabling the core features I wish were on out of the box by default in Perl 5. While it'd be nice to pull in Try::Tiny and sometimes I might wish for fatal warnings, the former is not a core module and the second isn't something I use in every program.

Consequently the module hasn't needed much maintenance. Yet I've added a couple of missing features that should keep it useful and usable into the future. I uploaded a new version yesterday and will upload one more today with a little bit more polish.

First, it now requires autodie as a distribution dependency. It doesn't load autodie, but installing Modern::Perl on 5.10.0 will also install autodie. (Anything 5.10.1 and newer includes autodie in the core.) You don't have to use it, but now you can rely on any Perl considered modern to have autodie available.

Second, it now loads IO::File and IO::Handle so that you can call methods on lexical filehandles without having to load either manually. Perl 5.14 fixed that usability niggle, but Modern::Perl fixes this for people using 5.10 or 5.12. (Why both? I can never remember which one superseded the other in 5.12, but better safe than sorry. I welcome a patch to load one over the other with a version check—and please test carefully.)

Third, I added unimporting support so that you can write no Modern::Perl; within a scope to disable strictures, warnings, and language bundle features. It's an all or nothing switch and will remain that way, but I can see this being useful in specific cases, especially when updating older code in stages.

Finally I added date support to importing. If you write use Modern::Perl; you'll get the features of Perl 5.10 (with the caveat that if you're using Perl 5.11.3 or newer, you also get the unicode_strings feature, of which all you're likely to notice is that Unicode strings work better in more places).

Yet for forward compatibility, you should be using:

use Modern::Perl 2012;

... which enables 5.14 features. You can use 2009 and 2010 to get 5.10 features and 2011 to get 5.12 features. If you use the wrong date on the wrong version of Perl 5, you'll get an error, which is as it should be.

Next year I'm likely to drop support for Perl 5.10, in which case you'll probably get an error message that that year isn't modern enough, but I could be convinced to do a version check instead. I haven't decided. The tradeoff is between providing a minimal module suitable for use in programs which helps people write better code from the start and between telling people what they should and shouldn't use. Besides all that, the relevant code is only a couple of dozen lines of very simple Perl. Anyone reading this can reimplement it almost trivially.

Of course, this all comes about because the Modern Perl book goes to the printer today. We're very proud of the new 2011-2012 edition which concentrates on Perl 5.12 and Perl 5.14. It addresses all of the known typos and confusing parts of the previous edition, covers new features in Perl 5.14, and is, from all reports, even better than the first edition.

The book should be in stores in the next week or so, and we'll have electronic editions up this month for free download and redistribution. (We hope you tell lots of people to buy the print edition because it's great and more people need it on their desks, but sharing is caring and we support that.)

Modern Perl: The Book

cover image for Modern Perl: the book

The best Perl Programmers read Modern Perl: The Book.

sponsored by the How to Make a Smoothie guide



About this Entry

This page contains a single entry by chromatic published on January 5, 2012 12:34 PM.

Do It Wrong Sometimes was the previous entry in this blog.

A Little Bit is A Lot Better is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by the Perl programming language

what is programming?