Object::FromData::Hash -> Create an object from a hashref.
Don't instantiate directly using this module. Use Object::FromData instead.
Object::FromData
my $hashref = Object::FromData->new( { ref => \%hash } ); while ( $hashref->has_more ) { my ( $key, $value ) = $hashref->each; ... }
has_more
while ( $hashref->has_more ) { my ( $key, $value ) = $hashref->each; ... }
Returns a boolean indicating if the iterator has been exhausted.
each
my ( $key, $value ) = $hashref->each;
Returns the next key and value in the hashref iterator, if any. Check $hashref->has_more to see if the iterator is exhausted.
$hashref->has_more
reset
$hashref->reset;
Resets the iterator to the start.
is_hashref
if ( $hashref->is_hashref ) { ... }
Returns true.
is_arrayref
if ( $hashref->is_arrayref ) { ... }
Returns false.
keys
my @keys = $hashref->keys;
Returns a list of the keys.
values
my @values = $hashref->values;
Returns a list of the values.
We've tried to keep the methods minimal, but because we're inheriting from Object::FromData::Hash and the hash you pass in might have keys which override the main keys. If that happens, call the methods as class methods, passing in the object as an argument:
Object::FromData::Hash
my %hash = ( keys => [qw/foo bar baz/], ); my $object = Object::FromData->new({ ref => \%hash }); my @keys = $hash->keys; # returns an Object::FromData::Array instance of foo, bar, and baz my @keys = Object::FromData::Hash->keys($hash); # returns 'keys'
To install Object::FromData, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Object::FromData
CPAN shell
perl -MCPAN -e shell install Object::FromData
For more information on module installation, please visit the detailed CPAN module installation guide.