Writing Perl Modules for CPAN

9781590590188.gif

This past weekend I dusted off my copy of Sam Tregar's Writing Perl Modules for CPAN. The book was published in 2002 and that gave me some trepidation about re-reading it almost nine years later. However, I not yet written a CPAN module and I wanted to give it a shot -- so this seemed like a logical place to start. Thankfully, any reservations were misplaced: this book should be on the shelf of any person wanting to expand their Perl repertoire.

Here's a quick summary of what really stood out for me this time:

  • Chapter 2, incorrectly titled "Perl Module Basics," should be a must-read for anyone new to Perl. It answers all the burning questions about Perl modules. Specifically, why modules are an improvement over one-off scripts almost 99% of the time, the difference between compile-time and runtime in the life of a Perl program, the concept of Packages, Symbols, Encapsulation, Object-Oriented vs. Functional style modules, Classes, Accessors and Mutators, Inheritance, Overloading, and much more. I've rarely read a programming book chapter so full of valuable information and so clearly written.

  • Chapter 3 covers "Module Design and Implementation" and does it quickly and thoroughly. It starts with an explanation of Plain Old Documentation in the context of a documentation-first approach to module design, and then quickly jumps into design decisions like functions vs. objects, naming, and parameters and return values. With that information delivered to the reader, it jumps another level deep and provides a thorough exploration of inheritance vs. composition and the challenges of dealing with multiple-inheritance, and then wraps up with a quick overview of how to visually map out a module's design with UML.

  • Chapter 5 delves into "Submitting Your Module to CPAN," and is a good read for the process-related concerns of getting a module submitted. It touches on how to get feedback from the Perl community and the nitty-gritty details of the PAUSE upload process. Of course, being from 2002, it could use a quick refresh and a section on newer tools like Dist::Zilla.

  • Last but not least, Chapter 7 -- "Great CPAN Modules" -- is a worthy read. Sections on DBI, Storable, and LWP are particularly noteworthy, while others like CGI.pm could be updated with newer examples, and -- generally -- there are a number of great CPAN modules that could be unpacked here for the reader's benefit, e.g.: modules that take advantage of Moose, and perhaps one of the event-loop modules.

Obviously, that's just four chapters out of eleven that hit the mark. But, nonetheless, I would still recommend the book as a great resource just for those chapters alone. However, the rest of the book is not without value -- just a bit outdated for the era of "Modern" and "Effective" Perl. Specifically:

  • I'm guessing that most folks would agree that h2xs is a bit outdated, and that people should probably just jump right into reading about module-starter or Dist::Zilla instead.
  • The chapter on module maintenance and community could be updated to include mention of blogging, Twitter, and, most importantly, Github, as ways to build community, find contributors, and manage patches.
  • The last three chapters are all devoted to various ways to write CPAN modules in C, either using XS or Inline::C, which didn't feel as contemporary or timeless as other chapters. (That said, I've never wanted to write a Perl module in C, so maybe it's just a topic that doesn't interest me.)
  • Writing Web applications in Perl is relegated to the last chapter, but seems to be a pressing concern "with the kids" these days. It could easily be presented earlier and be updated to include sections on Catalyst, Dancer, Mojolicious, and Plack.

In summary, my sense is that Apress could fairly easily update this book for 2011, and that doing so would make a great resource for years to come. I must admit, I enjoyed Sam Tregar's clear, simple writing enough to almost forgive him for leaving the Bricolage project to work on Krang (inside joke).

So, what's on your Perl back catalog reading list these days?

5 Comments

I'm (slowly) reading Effective Perl Programming 2nd Ed. by brian d foy et al. Also have chromatic's Modern Perl but didn't have time to read yet. Effective Perl is quite a good read although it seems to favor over using $_ for fancy coding (flame->start). The most surprising part for me is to learn that perl ignores any white space around a number as in:

perl -wle 'print qq{\n\n\n\n123\n\n\n\n} + 0'

I knew that things like 123aaa will return in numeric context but didn't know the ws issue.

Thanks for the review Philip! I'm flattered anyone is reading my book after so long.

Your suggestions for updates all sound right to me. Interesting that you didn't include Perl 6 updates in the changes you'd like to see; way back in 2002 Apress was worried that a book about Perl 5 would be outdated when Perl 6 came out. I guess that's taking a bit longer than expected!

-sam

I skimmed Mastering Regular Expressions, 3rd ed (2006) a couple of days ago, to see if the latest revision has any interesting new content (read the first edition many years ago). Unfortunately, since it predated Perl 5.10 by about a year, it does not mention any of 5.10 flavor of regex, which offers quite a major upgrade: named captures, recursive pattern, possesive quantifiers, etc.

Since I'm currently keen on learning more about parsing, will be looking forward to read Pro Perl Parsing (2005).

The last good book on Perl which I enjoyed was: Perl Testing: A Developer's Notebook, which I prefer chromatic's latest work, Modern Perl. I'm very happy to see that Modern Perl is widely well-received though.

Leave a comment

About Phillip Smith

user-pic Phillip Smith is a digital publishing consultant, online advocacy specialist, and strategic convener. And I blog about Perl.