develooper Front page | perl.perl5.porters | Postings from June 2021

Re: PSC #024 2021-06-11

Thread Previous
From:
Dan Book
Date:
June 14, 2021 05:57
Subject:
Re: PSC #024 2021-06-11
Message ID:
CABMkAVVHJGgzQNBJN-DzKJg0uTSd1bcKacYJosb=dkSCVR0gig@mail.gmail.com
On Mon, Jun 14, 2021 at 12:09 AM mah.kitteh via perl5-porters <
perl5-porters@perl.org> wrote:

> b. dealing with the fact that what's being checked is not a reference and
> therefore has no access to UNIVERSAL::isa?
>

Not a blessed reference, specifically. It does also work on non-references,
since those are class names.

I just happened to find this when doing some "fact checking"; does this
> infix "isa" address the shortcomings of UNIVERSAL::isa?
>

Yes. It calls isa on the blessed reference, but doesn't throw an exception
when called on an unblessed reference or undef, thus replacing the common
(but not well known) idiom to do this correctly: `defined(blessed $thing)
&& $thing->isa($class)`

-Dan

Thread Previous


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