Skip Menu |

This queue is for tickets about the Data-Path CPAN distribution.

Report information
The Basics
Id: 33610
Status: resolved
Worked: 10 min
Priority: 0/
Queue: Data-Path

People
Owner: Jeremy [...] marzhillstudios.com
Requestors: yoshikazu.kamoshida [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.3
Fixed in: (no value)



Subject: type checking for blessed arrayrefs
I found some cases that Data::Path does not work on blessed arrayrefs. The following output will be produced when the attached program is executed: trie to retrieve an index 0 from a no array value (in key k) at t.pl line 13 hello Can't coerce array into hash at /usr/local/share/perl/5.8.8/Data/Path.pm line 75. Can't coerce array into hash at /usr/local/share/perl/5.8.8/Data/Path.pm line 81. (I ran this script with perl 5.8.8.) I think the correct output should be: hello hello hello tried to retrieve a key from a no hash value (in key a) at t.pl line 16 This seems to be because Path.pm assumes blessed objects are always hashrefs. I think it is better to check types of objects before dereferencing hashrefs, like this: if not exists $data->{$key} and $rest; --> if UNIVERSAL::isa($value,'HASH') and not exists $data->{$key} and $rest; Type-checking like "ref($value) eq 'ARRAY'" will not work on blessed arrayrefs. Using UNIVERSAL::isa will be more general. Will you please consider to modify Data::Path to work on more general types of objects? Regards, Yoshikazu
Subject: t.pl
#!/usr/bin/perl use Data::Path; my $ary = bless(['hello'], 'myarray'); sub myarray::fst { shift->[0]; } # print $ary->fst, "\n"; my $t1 = { k => $ary }; # my $t1 = { k => ['hello'] }; my $dp1 = Data::Path->new($t1); eval{ print $dp1->get('/k[0]'), "\n"; } || print $@; eval{ print $dp1->get('/k')->[0], "\n"; } || print $@; eval{ print $dp1->get('/k/fst()'), "\n"; } || print $@; eval{ print $dp1->get('/k/a'), "\n"; } || print $@;
Fixed in 1.3.1