develooper Front page | perl.perl5.porters | Postings from December 2009

Re: Pod::Abstract 0.19 generating warnings on 5.11.3

Thread Previous | Thread Next
From:
demerphq
Date:
December 28, 2009 04:22
Subject:
Re: Pod::Abstract 0.19 generating warnings on 5.11.3
Message ID:
9b18b3110912280422k1e62d177nf65974c4168889a7@mail.gmail.com
2009/12/23 Jerry D. Hedden <jdhedden@cpan.org>:
>> use UNIVERSAL ();
>
> This is not needed.  UNIVERSAL is always available.
>
>> and then replace the calls to isa()  and can() by
>> UNIVERSAL::isa() and UNIVERSAL::can()
>
> No, isa() and can() should not be called as procedures.
> They are methods:  $item->isa('thing') for example.

Actually there are two schools of thought on this one.

The one school of thought thinks you should write this:

use Scalar::Util qw(blessed);

if (defined blessed($item) and $item->isa("Thing")) { ... }

This is "nice" in that it works with any possible $item without
warnings and etc, and it delegates the isa() logic to the $item, so it
can overload and etc. It has the downside that its a bit of a
mouthful, involves loading modules to do core logic tests, and most
people do it wrong one way or the other.

The other school thinks that you should write this:

if (UNIVERSAL::isa($item,"Thing")) {}

which avoids most of the downsides of the other variant, but doesnt
respect overloading. That is if $item wants to override isa() to do
something different, possibly "lie" about its type so that it can be
used in places where something expects some other type, then things
don't work.

Which is "correct" is arguable/debatable.

For the record, I generally use the latter logic, although at times
might take the care to use the former logic too.

cheers,
Yves






-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About