Skip to content

Commit

Permalink
Translate numeric index hashes back into arrays after json_decoding
Browse files Browse the repository at this point in the history
them from ZooKeeper
  • Loading branch information
mschilli committed Apr 22, 2011
1 parent 1c754e2 commit 1f59cee
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/Pogo/Engine/Namespace.pm
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,31 @@ sub _get_conf_r
$c->{$node} = $self->_get_conf_r($p);
}
}
return $c;
return numhash_to_array_r( $c );
}

sub numhash_to_array_r {
my ( $node ) = @_;

my $num_keys = 0;

for my $key ( keys %$node ) {
my $val = $node->{ $key };
if( ref( $val ) eq "HASH" ) {
$node->{ $key } = numhash_to_array_r( $val );
}
$num_keys++ if $key =~ /^\d+$/;
}

if( $num_keys and $num_keys == scalar keys %$node ) {
my @a = ();
for my $idx (keys %$node) {
$a[ $idx ] = $node->{$idx};
}
return \@a;
}

return $node;
}

sub get_conf
Expand Down

0 comments on commit 1f59cee

Please sign in to comment.