Subject: | using UNIVERSAL::isa as function discouraged |
Date: | Sun, 12 Jun 2011 13:54:45 +0200 |
To: | bug-net-EPP [...] rt.cpan.org |
From: | Salvatore Bonaccorso <carnil [...] cpan.org> |
Hi
This is related to [1]. Reading trough the manpage of UNIVERSAL there
was a pointer that indeed importing 'isa' function is deprecated.
However the manpage points too to:
# but never do this!
$is_io = UNIVERSAL::isa($fd, "IO::Handle");
$sub = UNIVERSAL::can($obj, "print");
and instead use the method form for isa:
EXPORTS
None by default.
You may request the import of three functions ("isa", "can", and
"VERSION"), but this feature is deprecated and will be removed.
Please don't do this in new code.
For example, previous versions of this documentation suggested
using "isa" as a function to determine the type of a reference:
use UNIVERSAL 'isa';
$yes = isa $h, "HASH";
$yes = isa "Foo", "Bar";
The problem is that this code will never call an overridden "isa"
method in any class. Instead, use "reftype" from Scalar::Util for
the first case:
use Scalar::Util 'reftype';
$yes = reftype( $h ) eq "HASH";
and the method form of "isa" for the second:
$yes = Foo->isa("Bar");
[1] https://rt.cpan.org/Public/Bug/Display.html?id=67327
I attach a patch to substitute the direct invokation of
UNIVERSAL::isa with the method form. Does this looks correct? If you
agree, could you apply this to the next upstream version?
Bests
Salvatore
Message body is not shown because sender requested not to inline it.
Message body not shown because it is not plain text.