NAME

Hash::Fold - fold and unfold nested hashrefs

SYNOPSIS

use Hash::Fold qw(flatten unflatten);

my $object = bless { foo => 'bar' };
my $nested = {
    foo => $object,
    baz => {
        a => 'b',
        c => [ 'd', { e => 'f' }, 42 ],
    },
};

my $flattened = flatten($nested);
my $roundtrip = unflatten($flattened);

is_deeply $flattened, {
    'baz.a'     => 'b',
    'baz.c.0'   => 'd',
    'baz.c.1.e' => 'f',
    'baz.c.2'   => 42,
    'foo'       => $object,
};

is_deeply $roundtrip, $nested;

DESCRIPTION

This module provides functional and OO interfaces that can be used to flatten and unflatten hashrefs.

EXPORTS

Nothing by default. The following functions can be imported.

flatten

Takes a nested hashref and returns a single-level hashref with (by default) dotted keys.

Unblessed arrayrefs and unblessed hashrefs are traversed. All other values (e.g. strings, numbers, objects &c.) are treated as terminals and passed through verbatim.

fold

Provided as an alias for "flatten".

unflatten

Takes a flattened hashref and returns the corresponding nested hashref.

unfold

Provided as an alias for "unflatten".

VERSION

0.0.1

SEE ALSO

CGI::Expand
Hash::Flatten

AUTHOR

chocolateboy <chocolate@cpan.org>

COPYRIGHT

Copyright (c) 2014, chocolateboy.

This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.