Skip to content

Commit

Permalink
Flatten new arrayref into previous arrayref in merge()
Browse files Browse the repository at this point in the history
  • Loading branch information
rwstauner committed Oct 16, 2011
1 parent 56e3c2b commit 66bdaea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Config/MVP/Slicer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ sub merge {
if( $previous ){
# FIXME: do we need to check blessed() and/or isa()?
if( ref $previous eq 'ARRAY' ){
push(@$previous, $value);
push(@$previous, ref $value eq 'ARRAY' ? @$value : $value);
}
# is this useful?
elsif( $type->name eq 'Str' && $opts->{join} ){
Expand Down
12 changes: 12 additions & 0 deletions t/merge-object.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ my $slicer = new_ok($mod, [{
'Plug.attr' => 'pa',
'Mod::Name.opt' => 'val',
'Moose.and[]' => 'squirrel',
'BigMoose.and' => 'little squirrel',
'Hunting.season[0]' => 'duck',
'Hunting.season[1]' => 'wabbit',
'Hunting.season[9]' => 'fudd',
Expand All @@ -34,6 +35,7 @@ foreach my $spec (
[qw( X::Plug attr Str )],
[qw( Mod::Name opt Str )],
[qw( X::Hunting season ArrayRef[Str] )],
[qw( X::Moose and Any )],
){
my ($pack, $attr, $type) = @$spec;
eval "{ package $pack; use Moose;" .
Expand All @@ -59,4 +61,14 @@ is_deeply
$exp,
'merge modifies object';

is_deeply
$slicer->merge(X::Moose->new({name => 'Moose'})),
X::Moose->new({name => Moose => and => [qw(squirrel)] }),
'set as arrayref when specified as []';

is_deeply
$slicer->merge(X::Moose->new({name => BigMoose => and => ['cow']})),
X::Moose->new({name => BigMoose => and => ['cow', 'little squirrel'] }),
'merged array ref when previous value was arrayref';

done_testing;

0 comments on commit 66bdaea

Please sign in to comment.