The Test Anything Protocol, or just TAP, is the formalization of Perl 5’s test structure from the Test::Harness module. Either Andreas König or Tim Bunce (they don’t remember which one of them did it) created the module, but they can’t remember who did what or when. The Changes file for the Test-Harness starts in seriousness in 2006, around the time that people started working on the next generation of Perl’s testing backend, despite it existing for several years before that. Now TAP is semi-formalized (and IETF RFC is in the works) and has it’s own website at testanything.org. Continue reading “Understand the Test Anything Protocol”
Category: book
Pass the empty subclass test
Is your object-oriented module subclassable? Do you know that from testing or are you just guessing? Setting aside other Perl programmers reaching into your package and redefining your subroutines, there are some basic things you can do to ensure that you’ve made life unhard for the people you want to extend your classes. Continue reading “Pass the empty subclass test”
Use Git::CPAN::Patch to make quick patches to CPAN distributions
The Git distributed version control system is very popular in with Perlers, and even if you aren’t using it for your own project, you should know how to do simple things with it so you can interact with the most active parts of the community. It’s not that hard. Not only that, many Perl projects are on Github, and it’s something else you’ll know when you go to your next interview. Continue reading “Use Git::CPAN::Patch to make quick patches to CPAN distributions”
Understand autovivification
Perl will autovivify complex data structures when you use them as if they already exist. This feature saves you a lot of annoying work defining structures that you intend to use. However, this also means that Perl might create data structures that you don’t intend to use in code that isn’t just assigning values. Continue reading “Understand autovivification”
Use the C3 method resolution order in multiple inheritance
Perl 5.10 introduced a flexible method resolution order mechanism. Instead of Perl’s default order (see Understand Perl’s default inheritance model), you can try something less stupid by using the mro pragma to specify which order perl
. Continue reading “Use the C3 method resolution order in multiple inheritance”
Use DateTime to disprove internet calendar memes
There’s a popular internet meme that says a July will only ever have five complete weekends, a Friday-Saturday-Sunday triplet, only every 823 years. To programmers, that might seem just absurd, but a lot of people believe it without thinking about it: that’s how it becomes the popular internet meme. Continue reading “Use DateTime to disprove internet calendar memes”
Read a few lines from a file
How would you get more than one line from a file? In the original Effective Perl blog that Joseph set up to support the first edition of Effective Perl Programming, he shows two possible techniques. One uses a foreach
: Continue reading “Read a few lines from a file”
Use the > and < pack modifiers to specify the architecture
Byte-order modifiers are one of the Perl 5.10 features farther along in perl5100delta, after the really big features. To any pack
format, you can append a <
or a >
to specify that the format is little-endian or big-endian, respectively. This allows you to handle endianness in the formats that don’t have specify versions for each architecture already, as well as apply endianness to groups. Continue reading “Use the > and < pack modifiers to specify the architecture"
Understand Perl’s default inheritance model
Perl’s default inheritance mechanism is a bit weird, and it’s not something that any language designer would want to repeat. However, it is what it is and by knowing its quirks you should have any easier time tracking down inheritance problems. Continue reading “Understand Perl’s default inheritance model”
Know the two different forms of eval
Perl’s eval
leads a double life, and, like Dr. Jekyl and Mr. Hyde, one is dangerous and one is almost safe. And, it’s important to know which one is dangerous; I grew up thinking that Dr. Jekyl was the bad one because evil people, such as Dr. No, had titles.
You can recognize the eval
s by their first, and only, argument. One form takes a string and the other takes a block. The string version compiles a string as Perl code and executes its, all at runtime. The block form runs, at run time, code that perl
has already compiled. Continue reading “Know the two different forms of eval”