Watch Test::Class and Class::MethodMaker fight!

Ovid on 2006-08-13T11:06:52

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.


Oddball packages *ought* to be ok

jjore on 2006-08-13T23:36:20

That's just strange and weird. The only things disallowed in package names are apostrophe, double colon, and null. That shouldn't be an error at all!

Or rather... it appears that to be that package names may be created any which way but to call a method it has to match the following macro or a more complicated utf8 thing I'm having difficulty following.

#define isIDFIRST(c) (isALPHA(c) || (c) == '_')

Bummer! This is an arbitrary irregularity!

Fixed in 0.15

Adrian on 2006-10-04T10:34:56

Get there in the end.