So I'm writing an article about how to use Test::Class and hoping it will be accepted. However, I was receiving a lot of strange, hard-to-find errors like the following:
Can't call method "isa" without a package or object reference at /usr/local/lib/perl5/site_perl/5.8.7/Test/Class.pm line 278.
That was coming from the isa check in this method:
sub _test_classes { my $class = shift; grep { $_ && $_->isa( $class ) } Devel::Symdump->rnew->packages; };
What? I clearly have a package or else Devel::Symdump wouldn't return it, right? After a lot of debugging, I discovered that whenever I was creating a class, such as Person, I would get two packages created. One for "Person" and another one for " Person" (note the leading space). This came about from the following code in Class::MethodMaker::Engine:
# Generate a unique stash name for the sub. Use a preceding space # to avoid collisions with anything in the Perl space. Class::MethodMaker::set_sub_name($code, $target, $name, " ${target}::${name}");
So this is clearly a feature of Class::MethodMaker and it's certainly not something which Adrian Howard (the author of Test::Class), should have reasonably expected. So I can create a patch for Test::Class, which seems like the only reasonable solution here, but what should invoking a method on this package name with a leading space do? I think the behavior is correct and that Class::MethodMaker should try a different approach, but it's a tough call.
In any event, this means I have to rewrite much of the code for the article. The reason I used Class::MethodMaker in the first place is because I didn't want to clutter the code with a lot of boring stub methods but I also thought it would be cheeky to just use my Class::BuildMethods module.