New to “Dynamic Subroutines”

“Dynamic Subroutines” is one of my favorite chapters in Mastering Perl, although it’s not a long one. When Allison Randal and I were first planning the book, we didn’t want to cover anything that was already done well in another book. Since Mark Jason Dominus had already exhausted the subject in Higher-Order Perl, I didn’t belabor the point.

Not much has changed in Perl in this regard, although Perl v5.16 added the __SUB__ token so we can reference the current subroutine even if we don’t know its name.

Check out this chapter in O’Reilly Atlas.

New to “Configuration”

I didn’t have to make many changes to Chapter 11: Configuration. This is mostly a stable part of the Perl ecosystem. I updated a few minor things.

Readonly is out, Const::Fast is in. I only talk about constants for a short section where I write about a particular way (anti-pattern even) to configure programs. The Readonly module hasn’t been updated in years. It uses tie to perform its magic and has several interesting edge cases from that as you can see in its RT queue. Leon Timmermans replaced it with Const::Fast. It uses almost the same interface but “by doing everything the opposite way Readonly does it.” I’ve asked Eric Roode, Readonly‘s maintainer, if I can get it into Github and have the community update it. I’ll see how that goes.

In two places I had mentioned Google Code Search, the now dead project that was part of Google’s mission to “organize the world’s information and make it universally accessible and useful”. Instead, I found Ohloh’s code search. In the chapter, I look for “DON’T EDIT BELOW THIS LINE” and to show how common those are.

AppConfig is out. I don’t think it was widely used even when it was fresh, but it’s as old as the first edition of Mastering Perl. Instead, I mentioned JSON and YAML, although I’ll cover those in Chapter 14: Lightweight Persistence. I should survey people to see how they are configuring things nowadays.

Do you have anything else I should include or update? See what I have so far by reading it through Atlas.

ReturnValue on PrePAN

As part of the “Error Handling and Reporting” chapter, I’ve developing my use of normal return values to indicate failure. Instead of tricky value checking, I can use the object type to decide what happened and then look in the object to get the value. That way, success and error values can use the same code path. I’ve created ReturnValue on Github.

Before uploading to CPAN, however, I’m trying PrePAN for the first time. This allows me to show off ReturnValue to the Perl community without claiming the namespace. I don’t deal with PAUSE at all. If I decide to abandon it, it’s no big deal. Comment on ReturnValue at PrePAN.

You can also read the draft chapter on O’Reilly Atlas.

New to “Error Handling”

There’s much to update in Chapter 12, “Error Handling”. I thought this would be an easy chapter.

Since v5.10, Fatal is different and now called autodie. I mostly had to change the module names. The biggest change was removing the non-void non-handling of builtins that Fatal could do. If Fatal saw I checked the return value of a builtin myself, it doesn’t throw the exception for me. I excised that paragraph.

In v5.14 the behavior of $@ changes quite a bit. An eval inside a destructor won’t mess up $@ as the scope is cleaning up.

I’m covering Try::Tiny and TryCatch. I’m still working on those sections.

Do you have anything else I should include or update? See what I have so far by reading it through Atlas.

New to “Logging”

I’ve expanded the Logging chapter to discuss more of the Log4perl features, including the Nested diagnostic context and the Mapped Diagnostic Context, both of which allow me to keep track of information that I can interpolate into log message.

I expanded the discussion of categories a bit more, but not that much. I think it’s a pretty simple feature.

See if you like it by reading it through Atlas.

New to “Cleaning Up Perl”

There’s not much that I needed to update in the chapter devoted to Perl style. The Perl::Tidy stuff is the same and I updated the Perl::Critic with a new program to analyze.

When I originally wrote this chapter, use.Perl was still going and I used my journal reading program as the violation program. Since that site is no longer active, I switched to my retweeter roulette program that I use to select winners from my twitter giveaways.

There are some errors there, but my style has evolved in the seven years since then so I had to work a little harder to get violations.

I also added a bit more on turning off policies, especially for single lines. I left it out last time as a way to discourage it through ignorance, but I’ve changed my mind about that. Using the ## no critic trick is so annoying that it’s easier to comply.

Have I left anything out that you like to do? You can read Chapter 7 through the O’Reilly Atlas pre-publication review program.

New to “Working with Pod”

There’s not much to update in the Pod chapter; the Pod specification hasn’t changed that much since I first wrote the book.

I did add a short section on the =encoding header and using non-ASCII characters directly instead of using interior sequences.

I updated the Pod::Perldoc::ToToc example, which had a couple of weird errors from a short period when I liked using shift to process argument lists. I’d make mistakes that strict would catch:

sub foo {
    my( $self ) = shift;

    do_something( $second_argument );

However, I was taking strict lines out to save a little space on the page. Going back and forth a few times introduced some newbie errors.

With v5.12 automatically turning on strict when you require that version, I won’t have that extra line problem.

New in “Secure Programming Techniques”

This chapter contains most of the original text, although with a few tweaks. There are two big additions which I did not cover in the first edition of this book.

I added a section on security with the DBI module and SQL injection. I don’t really think it belongs in this book any more than any other sort of problem with a CPAN module, but enough people complained that I relented.

And, I added a brief introduction to the Safe module. This is a rarely used security feature that you might find useful if you have to use string eval.

I’ve added some of the sample programs to the downloads page.

You can read the draft chapter now.