Myco::Entity 1.22 review

Download
by rbytes.net on

Myco::Entity is a common base class for all Myco entity classes. SYNOPSIS ### Entity class definition package Myco::Foo;

License: Perl Artistic License
File size: 106K
Developer: Charles Owens
0 stars award from rbytes.net

Myco::Entity is a common base class for all Myco entity classes.

SYNOPSIS

### Entity class definition

package Myco::Foo;
use base qw(Myco::Entity);

# Start building metadata
my $metadata = Myco::Entity::Meta->new
( name => __PACKAGE__,
tangram => { table => 'Foo' }
);

$metadata->add_attribute(name => 'attr1', type => 'string');
$metadata->add_attribute(name => 'attr2', type => 'string');

# class-specific methods defined ...
#

# Fill in $schema with all added_attributes and discover other metadata
$metadata->activate_class;



### Entity class usage

use Myco::Foo;

# Constructor
$obj = Myco::Foo->new;
$obj = Myco::Foo->new(attr1 => value, attr2 => value);

# Access class metadata (see Myco::Entity::Meta)
$meta = Myco::Foo->introspect;
$meta = $obj->introspect;

# Accessors
$obj->get_attr1; # get attribute value
$obj->set_attr1('value'); # set attribute value

# Instance methods
$id = $obj->save; # update object's state in persistent
# storage, create new record if needed;
# returns object's Tangram id
$obj->destroy;
$obj->modify(attr1 => val, attr2 => val);
$object_id = $obj->id;
$obj->is_transient; # returns true if object is in Tangram
# transient storage

## object retrieval (see class Myco documentation
# for full detail)

$obj = Myco->load($object_id);

# fetch all objects of given type
@objects = Myco->select(ref $obj);

Provides, via inheritence, common interface in support of basic lifecycle needs for myco entity objects.

This is accomplished through the encapsulation of the CPAN module Class::Tangram which provides a basis for "in-memory" object behavior. Consult its documentation for details on schema definition syntax, getter/setter behavior, check functions, etc.

The common interface for object persistence behavior (referred within myco as "transaction" behavior) is provided through defintion of a handful of related instance methods. This is done with reliance on the services of the class Myco, which encapsulates the functionality of Tangram::Storage and provides system-wide connection handling.

Requirements:
Perl

Myco::Entity 1.22 keywords