A Zoidberg Story

I just read Buddy Burden’s recent post A Random Story and it was fun to see that his reasons for adopting Data::Random was the same as my reason for adopting Zoidberg: failing tests. The difference was that his failing tests were his own and mine were in Zoidberg.

I was a few years into using Linux and I had really fallen in love with Perl, which was my first real programming language (after Maple, Mathematica, and LaTeX), but I had never really gotten the hang of Bash. Since Perl was used in scripting, and even things that looked like shell scripting, I wondered if there was a Perl shell. I looked and I saw a few Zoidberg and Psh stood out as being functional.

Now I can’t remember what it was, but Zoidberg was the one that kept my attention, there was probably something, but I can’t remember anymore. It had a problem though, a failing test on installation through CPAN. I could install it through apt though, so no problem, right?

A little while longer, I had gotten better at Perl and I decided to see if I could play the sleuth and find the problem. It was an interesting problem (documented at SO) wherein its GetOpt module fails parsing its prototypes. Matches were leaking across loop iterations, not getting reset. This minimal example shows the problem.

#!/usr/bin/perl

use strict;
use warnings;

my @a = qw/n a$ b@ c/;
my @b = @a;
my @c = @a;

print "Test A -- Doesn't work (c !-> 0)\n";
for (@a) {
  s/([\$\@\%])$//;
  my $arg = $1 || 0;
  print $_ . " -> " . $arg . "\n";
}

print "\nTest B -- Works\n";
for (@b) {
  my $arg;
  if (s/([\$\@\%])$//) {
    $arg = $1;
  }
  $arg ||= 0;
  print $_ . " -> " . $arg . "\n";
}

print "\nTest C -- Works, more clever\n";
for (@c) {
  my $arg = s/([\$\@\%])$// ? $1 : 0;
  print $_ . " -> " . $arg . "\n";
}

The strange thing is, that test A worked before 5.10, even though it apparently wasn’t supposed to (cjm confirmed that I wasn’t going crazy). I think this may have scared many people away, but to me it was a great challenge.

Much like Buddy I submitted a patch, and while the author, Jaap Karssenberg, was responsive, he had moved on. He offered that I could adopt it if I wanted, and has helped, finding his old notes and commenting on some of my fixes.

Turns out the failing test had masked something much more sinister, the shared data wasn’t getting installed to the proper location anymore (was it installing at all?). Anyway, Module::Build had progressed a long way since Zoidberg 0.96 had been released and offered the share_dir feature, which when combined with File::ShareDir, fixes the problem quite nicely.

These and a few other fixes are essentially complete, and I hope to submit Zoidberg 0.97 to PAUSE soon. There are plenty of modernizations planned and features (literally, I want to add say, state and given/when), but those will probably have to wait until the next release.

This brings me back to the beginning of the story to say, thanks to all the CPAN authors for writing the tests, they can help an intermediate programmer try to reach in and salvage an excellent piece of software for falling into obscurity before it should. I hope to live up to the example (remember that when you start to feel lazy Joel!).

And P.S. Buddy, thanks for reminding me about done_testing, I need to look around to see if I have fallen victim to that one (I’m sure I have!).

Leave a comment

About Joel Berger

user-pic As I delve into the deeper Perl magic I like to share what I can.