NAME
Data::Pack - pack data structures so only real content remains
SYNOPSIS
use Data::Pack ':all';
my $h = {
a => 1,
b => [ 2..4, undef, 6..8 ],
c => [],
d => {},
e => undef,
f => (bless {
f1 => undef,
f2 => 'f2',
}, 'Foo'),
g => {
g1 => undef,
g2 => undef,
g3 => [ undef, undef, undef ],
g4 => {
g4a => undef,
g4b => undef,
},
},
};
my $p = pack_data($h);
The result is
$p = {
a => 1,
b => [ 2..4, 6..8 ],
f => (bless {
f2 => 'f2',
}, 'Foo'),
};
DESCRIPTION
This module provides a way to traverse data structures and eliminate any undefined or otherwise empty pieces from it. None of the functions are exported automatically, but you can request them by name, or get all of them if you use the :all
tag.
FUNCTIONS
- pack_data
-
This function takes a possibly blessed hash or array reference and traverses it, returning a copy that has no undefined or otherwise empty pieces. That is, key/value pairs where the value is undefined - or recursively deemed contentless - are eliminated from the copy, as are undefined or contentless elements from arrays. "Deemed contentless" is done with
has_content()
, so for example a hash key/value pair whose value is a hash of arrays or the like, but whose leaves are all undefined or empty, is omitted. See the Synopsis for an example. - has_content
-
This is really just a convenience function used by
data_pack()
, but it is still exportable.Given a scalar, it returns whether this is a defined value.
Given a possibly blessed array reference, it returns whether that array contains any elements.
Given a possibly blessed hash reference, it returns whether that hash contains any key/value pairs.
Given any other type of reference, it will die.
BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests through the web interface at http://rt.cpan.org.
INSTALLATION
See perlmodinstall for information and options on installing Perl modules.
AVAILABILITY
The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit <http://www.perl.com/CPAN/> to find a CPAN site near you. Or see <http://www.perl.com/CPAN/authors/id/M/MA/MARCEL/>.
AUTHORS
Marcel Grünauer, <marcel@cpan.org>
COPYRIGHT AND LICENSE
Copyright 2008 by Marcel Grünauer
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.