BusyBird::SafeData - a wrapper of a complex data structure to access its internals safely
use BusyBird::SafeData qw(safed); my $data = { foo => { bar => [ 0, 1, 2 ], buzz => { hoge => 100 } } }; my $sd = safed($data); $sd->original; ## => $data $sd->val("foo", "bar", 1); ## => 1 $sd->val("foo", "buzz", "FOO"); ## => undef $sd->val("foo", "quux", "hoge"); ## => undef (and no autovivification) $sd->val("foo", "bar", "FOO"); ## => undef (and no exception thrown) $sd->val("foo", "buzz", "hoge", "FOO"); ## => undef (and no exception thrown) $sd->array("foo", "bar"); ## => (0, 1, 2) $sd->array("foo", "buzz"); ## => () $sd->array("foo", "bar", 1); ## => ()
BusyBird::SafeData is a wrapper around a complex data structure to provide a safe way to access its internal data.
The following function is exported only by request.
Same as BusyBird::SafeData->new($data).
BusyBird::SafeData->new($data).
The constructor.
$data is any scalar. $sd wraps the given $data.
$data
$sd
Returns the original $data that $sd wraps.
Return the value specified by @path from $sd.
@path
@path is a list of indices/keys from the root of the $sd down to the value you want. If it cannot traverse @path completely, it returns undef.
undef
This method never autovivifies anything in $sd.
Return the list of values in the array-ref specified by @path. If it cannot traverse @path completely, it returns an empty list. If the value at the @path is not an array-ref, it returns an empty list.
Toshio Ito <toshioito [at] cpan.org>
<toshioito [at] cpan.org>
To install BusyBird, copy and paste the appropriate command in to your terminal.
cpanm
cpanm BusyBird
CPAN shell
perl -MCPAN -e shell install BusyBird
For more information on module installation, please visit the detailed CPAN module installation guide.