NAME

Object::KVC::Hash - Key Value Coding Hash object

SYNOPSIS

use Object::KVC::Hash;
use Object::KVC::String;

my $object1 = Object::KVC::Hash->new();
my $object2 = Object::KVC::Hash->new();

$object1->set( "id", Object::KVC::String->new("id1234") );
$object2->set( "id", Object::KVC::String->new("id1234") );

print $object1->get( "id" )->as_string();

$object1->equals( $object2 ) ? print "Yes, the objects are equal";

DESCRIPTION

Object::KVC::Hash is a generic object which can be used to model a variety of objects without having to write a large number of classes.

Values must be wrapped in an object supporting the "equals," "contains," and "intersects" methods in order to allow two Object::KVC::Hash objects to be compared.

The "equals" and "contains" methods allow searching of Object::KVC::Hash objects within an Object::KVC::List.

METHODS

new()

The constructor.

my $object = Object::KVC::Hash->new();

No arguments.

clone()

Returns a new Object::KVC::Hash object with the same key value pairs as the original object.

my $cloned_object = $object->clone(); 

Does not copy the value objects.

set( <string>, <value object> )

Set a key value pair.

$object->set( "key",  Object::KVC::String->new("string") );

Same as:

$object->{ "key" } = Object::KVC::String->new("string");

get( <string> )

Get a value object.

my $value = $object->get( "key" );

Same as:

my $value = $object->{"key"};

get_keys()

Returns 'ARRAY' of currently defined keys.

my @keys = $object->get_keys()

Same as:

my @keys = keys( %$object );

has_defined( <string> )

Returns true if a key value pair is defined.

$object->has_defined( "key" );

Same as:

defined( $object->{"key"} );

delete_key( <string> )

Delete a key value pair.

$object->delete_key( "key" );

Same as.

delete( $object->{"key"} );

equals( <Object::KVC::Hash> )

Returns true if all keys exist in both objects and the corresponding value objects are equal.

$object1->equals( $object2 );

matches( <Object::KVC::Hash> )

Returns true if all keys in $object2 exist in $object1 and the corresponding value objects are equal.

Returns false if $object2 has a key which does not exist in $object1.

$object1->matches( $object2 );

intersects( <Object::KVC::Hash> )

Returns true if all keys in $object2 exist in $object1 and the corresponding value objects intersect.

Returns false if $object2 has a key which does not exist in $object1.

$object1->intersects( $object2 );

contains( <Object::KVC::Hash> )

Returns true if all keys in $object2 exist in $object1 and the corresponding value objects in $object1 contain the corresponding value objects in $object2.

Returns false if $object2 has a key which does not exist in $object1.

$object1->contains( $object2 );

contained_by( <Object::KVC::Hash> )

Returns true if all keys in $object2 exist in $object1 and the corresponding value objects in $object2 contain the corresponding value objects in $object1.

Returns false if $object2 has a key which does not exist in $object1.

$object1->contained_by( $object2 );

as_string()

For debugging only.

dump()

For debugging only.

print $object->dump();

COPYRIGHT AND LICENSE

Object::KVC::Hash Copyright (C) 2012 Trystan Johnson

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.