The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Object::FromData::Hash -> Create an object from a hashref.

SYNOPSIS

Don't instantiate directly using this module. Use Object::FromData instead.

    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.

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.

HASH KEYS OVERRIDING BUILT IN METHODS

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:

    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'