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

Re: Blessed objects are `isa` their reftype

Thread Previous | Thread Next
From:
David Christensen
Date:
February 16, 2021 21:13
Subject:
Re: Blessed objects are `isa` their reftype
Message ID:
5769d008-747a-af7c-4c64-e843125a4231@holgerdanske.com
On 2021-02-16 04:09, Paul "LeoNerd" Evans wrote:
> There is an odd asymmetry with isa when testing if an object is derived
> from its reference type:
> 
>    my $aref = [ 1, 2, 3 ];
>    $aref isa ARRAY             # is false
> 
>    my $aobj = bless [ 5, 6, 7 ], "MyArray::Class";
>    $aobj isa MyArray::Class    # is true
>    $aobj isa ARRAY             # is true(!)


Please post a valid Perl program that demonstrates your point (e.g. 
Test::More, ok, TODO).


David



2021-02-16 13:03:18 dpchrist@tinkywinky ~/sandbox/perl/p5p
$ cat /etc/debian_version ; uname -a
9.13
Linux tinkywinky 4.9.0-13-amd64 #1 SMP Debian 4.9.228-1 (2020-07-05) 
x86_64 GNU/Linux

2021-02-16 13:03:30 dpchrist@tinkywinky ~/sandbox/perl/p5p
$ cat paul-leonerd-evans-20210216-0409.pl
   my $aref = [ 1, 2, 3 ];
   $aref isa ARRAY             # is false

   my $aobj = bless [ 5, 6, 7 ], "MyArray::Class";
   $aobj isa MyArray::Class    # is true
   $aobj isa ARRAY             # is true(!)

2021-02-16 13:03:37 dpchrist@tinkywinky ~/sandbox/perl/p5p
$ perl paul-leonerd-evans-20210216-0409.pl
Bareword found where operator expected at 
paul-leonerd-evans-20210216-0409.pl line 2, near "$aref isa"
	(Missing operator before isa?)
Bareword found where operator expected at 
paul-leonerd-evans-20210216-0409.pl line 5, near "$aobj isa"
	(Missing operator before isa?)
Bareword found where operator expected at 
paul-leonerd-evans-20210216-0409.pl line 6, near "$aobj isa"
	(Missing operator before isa?)
syntax error at paul-leonerd-evans-20210216-0409.pl line 4, near "$aref 
isa ARRAY             # is false

   "
syntax error at paul-leonerd-evans-20210216-0409.pl line 6, near "$aobj 
isa MyArray::Class    # is true
   "
Execution of paul-leonerd-evans-20210216-0409.pl aborted due to 
compilation errors.


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