NAME

Mango::Object - Base class used for Mango result objects.

SYNOPSIS

package Mango::User;
use base qw/Mango::Object/;

DESCRIPTION

Mango::Object is the base class for all result objects in Mango. It provides common methods exposed by all results like "id", "created", "updated", "update", etc.

CONSTRUCTOR

new

Arguments: \%args

Creates a new object, assigned each name/value pair to columns of the same name. In addition to using the column names, the following special keys are available:

meta

This is a hash containing the meta data for the object being created:

my $object = Mango::Object->new({
    col1 => 'foo',
    col2 => 12,
    meta => {
        provider => $provider
    }
});

$object->meta->provider->delete(...);
meta_class

See "meta_class".

METHODS

created

Returns the date and time in UTC the object was created as a DateTime object.

print $object->created;

destroy

Deletes the current object from the provider.

get_column

Arguments: $column

Returns the value of the specified column from "data".

print $object->get_column('foo');
# same as $object->foo;

get_columns

Returns a hash of all columns as name/value pairs.

my %columns = $object->get_columns;

id

Returns id of the current object.

print $object->id;

meta

Returns the meta information for the current object. The default meta class is Mango::Object::Meta.

my $provider = $object->meta->provider;

meta_class

Arguments: $class

Gets/sets the class to be used to handle meta data for objects.

Mango::Object->meta_class('MyMetaClass');

This can also be set on a per object basis in the constructor:

my $object = Mango::Object->new({
    meta => {...},
    meta_class => 'MyMetaClass'
});

set_column

Arguments: $column, $value

Sets the value of the specified column.

$object->set_column('foo', 'bar');
# same as $object->foo('bar');

update

Saves any changes made to the object back to the provider.

$object->foo(2);
$object->update;

Whenever "update" is called, "updated" is automatically set to the current time in UTC.

updated

Returns the date and time in UTC the object was last updated as a DateTime object.

print $object->updated;

get_component_class

Arguments: $name

Gets the current class for the specified component name.

my $class = $self->get_component_class('result_class');

There is no good reason to use this. Use the specific class accessors instead.

set_component_class

Arguments: $name, $value

Sets the current class for the specified component name.

$self->set_component_class('result_class', 'MyItemClass');

A Mango::Exception exception will be thrown if the specified class can not be loaded.

There is no good reason to use this. Use the specific class accessors instead.

SEE ALSO

Mango::Object::Meta, Mango::Provider

AUTHOR

Christopher H. Laco
CPAN ID: CLACO
claco@chrislaco.com
http://today.icantfocus.com/blog/