Skip Menu |

This queue is for tickets about the Hash-Merge CPAN distribution.

Report information
The Basics
Id: 55978
Status: patched
Priority: 0/
Queue: Hash-Merge

People
Owner: Nobody in particular
Requestors: sunnavy [...] gmail.com
Cc:
AdminCc:

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



Subject: to avoid the eval in _get_obj
Hi guys We've encountered a warning like "Can't call method "isa" on unblessed reference" at Hash/Merge.pm line 100 as I dug, the problem is we call _merge_hashes( $_[0], $_[1] ) when specify_behavior. well surely, since $_[0] is hashref, the warning pops out. _get_obj calls $_[0]->isa when ref $_[0] is not empty, though it's safe to call in an eval block, maybe we can get rid of eval by more testing before calling $_[0]->isa? I suggest use blessed in Scalar::Util or just skip the SCALAR|ARRAY|HASH. the patch for the latter one is attached. best wishes sunnavy
Subject: Merge.pm.diff
--- Merge.pm 2010-02-15 23:50:11.000000000 +0800 +++ Merge.pm.new 2010-03-27 00:36:02.000000000 +0800 @@ -96,8 +96,13 @@ $GLOBAL->{'clone'} = 1; sub _get_obj { - if ( my $type = ref $_[0] ) { - return shift() if $type eq __PACKAGE__ || eval { $_[0]->isa(__PACKAGE__) }; + my $type = ref $_[0]; + + if ( $type + && $type !~ /^(?:SCALAR|ARRAY|HASH)$/ + && ( $type eq __PACKAGE__ || $_[0]->isa(__PACKAGE__) ) ) + { + return shift(); } return $context;
From: heikki.j.laaksonen [...] kolumbus.fi
On Fri Mar 26 13:00:11 2010, SUNNAVY wrote: Show quoted text
> Hi guys > > We've encountered a warning like "Can't call method "isa" on unblessed > reference" at > Hash/Merge.pm line 100
Same problem. This prevents using Hash::Merge. For some reason it seems that the eval block dies on this line. If I run a simple example, this works. But when this is a part of bigger script, the problem appears and it must be my script. Unfortunately I cannot identify the root problem. Also, should the OR be AND on that line? I could also guess that the eval part is unnecessary? But at least using AND instead of OR prevents calling the eval block and seems to work for me. sub _get_obj { if ( my $type = ref $_[0] ) { return shift() if $type eq __PACKAGE__ || eval { $_[0]->isa(__PACKAGE__) }; }
From: hessu75
On Fri Mar 26 13:00:11 2010, SUNNAVY wrote: Show quoted text
> Hi guys > > We've encountered a warning like "Can't call method "isa" on unblessed > reference" at > Hash/Merge.pm line 100
Same problem. This prevents using Hash::Merge. For some reason it seems that the eval block dies on this line. If I run a simple example, this works. But when this is a part of bigger script, the problem appears and it must be my script. Unfortunately I cannot identify the root problem. Also, should the OR be AND on that line? I could also guess that the eval part is unnecessary? But at least using AND instead of OR prevents calling the eval block and seems to work for me. sub _get_obj { if ( my $type = ref $_[0] ) { return shift() if $type eq __PACKAGE__ || eval { $_[0]->isa(__PACKAGE__) }; }
Hi, This also causes issues with a __DIE__ handler as the eval generates errors, it ends up in the handler. The code should use Scalar::Util::blessed to test whether it's an object or not: diff Merge.pm.original Merge.pm 5a6 Show quoted text
> use Scalar::Util qw(blessed);
100c101 < return shift() if $type eq __PACKAGE__ || eval { $_[0]->isa(__PACKAGE__) }; --- Show quoted text
> return shift() if $type eq __PACKAGE__ || ( blessed $_[0] && $_[0]->isa(__PACKAGE__) );
otherwise please localise $@ and $SIG{__DIE__} to prevent the error to leak outside. Note that Scalar::Util is standard after perl 5.8 and it can be installed on the archaic 5.6. Thanks, Burak
This has been patched upstream with commit c01a97cdb9930ca81a276d3e6c216f05d6adac08. Use Scalar::Util::blessed to test whether the arg is a reference or not, before calling "isa" on it. Blindly calling "isa" and using eval to ignore the resulting error still triggers DIE handlers when it does not need to. Submitted by Larry Leszczynski