
EntityModel::Support::Perl::Base - base class for entity instances

version 0.017

say $_->name foreach Entity::Thing->find({name=>'test'});

All entities are derived from this base class by default.

When data has not yet been loaded for an entity, some additional logic is used to allow asynchronous requests via chained method accessors.
Given a chain $book->author->address->city, where the first three entries are regular entities and the last item in the chain is an accessor for a scalar method:
First, we check $book to see whether it has an author yet. If the author information is loaded (to the extent that ->author contains an entity instance), then we can use this existing instance. If not, we instantiate a new entity of this type, marked as incomplete and as a pending request, and continue.
This means that a chain where some of the elements can be null is still valid. As data is populated, entries in this chain will be filled out, and cases where the foreign key value was null will end up marked as invalid entities.
In general, unless you know beforehand that all entities in the chain have been populated, all access to chained entities should go through the EntityModel::Gather interface to ensure that values are consistent.
This also allows the backend storage to apply optimisations if available - if several pending requests address related storage areas, it may be possible for the storage engine to combine queries and return data faster.

Two types of events can be defined:
These are handled by the "_queue_task" and "_attach_event" methods respectively.
Instantiate from an ID or a pre-fabricated object (hashref).
EntityModel::Support::Perl::Base->new(1)
EntityModel::Support::Perl::Base->new(1)
EntityModel::Support::Perl::Base->new('123-456')
EntityModel::Support::Perl::Base->new([123,456])
EntityModel::Support::Perl::Base->new({ x => 1, y => 2 })
Any remaining options indicate callbacks:
The before_XXX callbacks are also aliased to on_XXX for convenience.
Queues a new one-shot task for the given event type.
Supports the following event types:
Pass the given event through to any defined callbacks.
Private method to generate hashref containing spec information suitable for bless to requested class, given a hashref which represents the keys/values for the object.
This will flatten any Entity objects down to the required ID key+values.
Create a new object.
Takes a hashref, and sets the flag so that ->commit does the insert.
Write current values back to storage.
Populate this instance with values from the database.
Returns true if this instance is due to be committed to the database.
Returns true if this instance is due to be committed to the database.
Insert this instance into the db.
Commit any pending changes to the database.
Revert any pending changes to the database.
Primary key (id) for this instance.
Instantiate from an ID.
Remove this instance from the database.
Returns the view corresponding to this object.

Tom Molesworth <cpan@entitymodel.com>

Copyright Tom Molesworth 2008-2011. Licensed under the same terms as Perl itself.