Stories
Slash Boxes
Comments
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)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
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)

Friday December 07, 2007
12:31 PM

Thoughts on UNIVERSAL::isa

[ #35058 ]

Were it not for the latest release of UNIVERSAL::isa, we might have removed Test::MockObject from out test suite due the the huge numbers of warnings emitted. From our deps/ directory (these are all CPAN modules .. we ship our own dependencies):

$ ack -l 'UNIVERSAL::isa\(' perl5lib/|wc -l
     103

No, we don't have time to analyze 103 different packages and submit patches (with tests) which may or may not fix bugs but are really only sent to silence warnings in our test suite. We have the test suite to catch bugs and not one of those warnings appeared to be a bug. However, they could be. Here's another check:

ack  'sub isa ' perl5lib/
perl5lib/Exception/Class.pm
585: sub isa { shift->rethrow }

perl5lib/Contextual/Return.pm
898:sub isa {

Rethrowing an exception for Exception::Class is a bit surprising, but I can understand why it's done there. Contextual::Return also does the right thing. Unfortunately, we have over 100 CPAN dependencies which would handle these wrong if they encountered them. Sigh. Of course, we only use a small subset of the CPAN. Anyone happen to know offhand how many CPAN modules override isa and how many get it wrong? I can check when I get home, I suppose.

So with the new version of UNIVERSAL::isa, we can stay happy and get some safety against the insanity of calling this as a function without having unusable test results.

If you really must do that (usually you don't), you can do this (thanks to merlyn for this trick):

if ( eval { $thing->isa($class) } ) {

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • That bit of code supposedly from Exception::Class is just an example of something you could do in the pod. It's not actually in the code itself. I'm not insane.
  • I'll take that as one vote to release the developer version as stable, then.

  • You surely mean of course (defined $it and blessed $it and $it->isa('Foo'))...
    • That's a lot longer to type and while it's theoretically clearer, I don't think it wins over an eval. Did I miss something obvious?

      • In general, using eval willy nilly is not good because you might swallow an exception that should have bubbled up. But a properly working isa is not expected to throw exceptions (or so I hope), so this idiom seems just fine.

        • You're absolutely right. An overridden isa() that throws an would violate the Liskov substitution principle, so it would not in fact work properly.

    • No, I think you meant

      defined( blessed $it ) and $it->isa( '...' )
      . blessed() is not a sufficient boolean on its own. There are two false classes in perl.