Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Sunday August 13, 2006
06:06 AM

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

[ #30610 ]

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/ 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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • 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!
  • Get there in the end.