NAME

Farly::Object - The Farly entity object

SYNOPSIS

use Farly::Object;

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

$object1->set( 'id', Farly::Value::String->new('id1234') );
$object2->set( 'id', Farly::Value::String->new('id1234') );

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

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

DESCRIPTION

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

Farly::Objects use string keys to set and access value objects.

Value objects must be wrapped in an object supporting the "equals," "contains," "intersects," "as_string," and "compare" methods.

The "equals," "contains," and "intersects," methods allow two Farly::Object object properties to be compared.

The "equals," "contains," and "intersects" methods allow searching of Farly::Object objects within a Farly::Object::List.

The "compare" method allows Farly::Objects to be easily sorted and grouped.

METHODS

new()

The constructor.

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

No arguments.

clone()

Returns a new Farly::Object 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",  Farly::Value::String->new("string") );

Set throws an exception if the value object does not support the required methods.

Same as:

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

Without type checking.

get( <string> )

Get a value object.

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

Throws an exception if the specified key if not defined.

Same as:

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

Without checking that the key is defined.

equals( $other<Farly::Object> )

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

$object1->equals( $object2 );

matches( $other<Farly::Object> )

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( $other<Farly::Object> )

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( $other<Farly::Object> )

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( $other<Farly::Object> )

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 );

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"} );

as_string()

For debugging only.

dump()

For debugging only.

print $object->dump();

COPYRIGHT AND LICENCE

Farly::Object Copyright (C) 2013 Trystan Johnson

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.