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

Re: Blessed objects are `isa` their reftype

Thread Previous | Thread Next
Paul "LeoNerd" Evans
February 17, 2021 10:15
Re: Blessed objects are `isa` their reftype
Message ID:
On Tue, 16 Feb 2021 22:17:19 -0800
L A Walsh <> wrote:

> So why introducing another new keyword when it's already in
> the core library?

$ref->isa(...)  crashes if $ref isn't a blessed object.

  $ perl -E 'say "ISA" if []->isa("ARRAY")'
  Can't call method "isa" on unblessed reference at -e line 1.

The `isa` operator does not

  $ perl -E 'use experimental qw(isa); say "ISA" if [] isa ARRAY; say "OK"'

This makes it much safer:

  if(blessed $obj and $obj->isa($class))

can become simply

  if($obj isa $class)

Paul "LeoNerd" Evans      |  |

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About