Skip Menu |

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

Report information
The Basics
Id: 123785
Status: resolved
Priority: 0/
Queue: Hash-Merge

People
Owner: Nobody in particular
Requestors: MAROS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.299
Fixed in: 0.300



Subject: Custom behaviours in 2.99
The following code used to work with Hash::Merge 2.00. Since 2.99 it dies with "Behavior 'My Behavior' does not exist". The code is mostly from the module synopsis. use Hash::Merge; use Modern::Perl; my %a = ( 'foo' => 1, 'bar' => [qw( a b e )], 'querty' => { 'bob' => 'alice' }, ); my %b = ( 'foo' => 2, 'bar' => [qw(c d)], 'querty' => { 'ted' => 'margeret' }, ); # Set behaviour my $behaviour = Hash::Merge::specify_behavior( { 'SCALAR' => { 'SCALAR' => sub { $_[1] }, 'ARRAY' => sub { [ $_[0], @{ $_[1] } ] }, 'HASH' => sub { $_[1] }, }, 'ARRAY' => { 'SCALAR' => sub { $_[1] }, 'ARRAY' => sub { [ @{ $_[0] }, @{ $_[1] } ] }, 'HASH' => sub { $_[1] }, }, 'HASH' => { 'SCALAR' => sub { $_[1] }, 'ARRAY' => sub { [ values %{ $_[0] }, @{ $_[1] } ] }, 'HASH' => sub { Hash::Merge::_merge_hashes( $_[0], $_[1] ) }, }, }, 'My Behavior', ); # set global behaviour to default Hash::Merge::set_behavior('LEFT_PRECEDENT'); # Set local behaviour my $merge = Hash::Merge->new('My Behavior'); my %c = %{ $merge->merge( \%a, \%b ) };
Behavior specification does not longer modify a shared document between all instances of Hash::Merge. SYNOPSIS does not tell you mix procedural and object context. Please do: my $merge = Hash::Merge->new; $merge->specify_behavior({...}, 'My Behavior'); $merge->set_behavior('My Behavior');
Updated API and Doc for clarification.