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) } ) {
Re:err, that's pod
Ovid on 2007-12-07T20:48:23
Oops
:)
I'll take that as one vote to release the developer version as stable, then.
Re:eval?
Ovid on 2007-12-09T01:37:42
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?
Re:eval?
Aristotle on 2007-12-09T03:09:24
In general, using
eval
willy nilly is not good because you might swallow an exception that should have bubbled up. But a properly workingisa
is not expected to throw exceptions (or so I hope), so this idiom seems just fine.Re:eval?
chromatic on 2007-12-10T16:56:40
You're absolutely right. An overridden
isa()
that throws an would violate the Liskov substitution principle, so it would not in fact work properly.Re:eval?
jjore on 2007-12-11T00:25:37
No, I think you meant. blessed() is not a sufficient boolean on its own. There are two false classes in perl.defined( blessed $it ) and $it->isa( '...' )