Model::Envoy::Set
A role for creating, finding and listing Model::Envoy based objects. Similar in philosophy to DBIx::Class::ResultSets.
Synopsis
package My::Models;
use Moose;
with 'Model::Envoy::Set' => { namespace => 'My::Envoy' };
....then later...
my $widget = My::Models->m('Widget')->fetch( id => 2 );
$widget->name('renamed');
$widget->save;
Configuration
When incorporating this role into your class, you will need to specify the perl namespace where your model classes reside per the synopsis above.
Methods
m($type)
Returns an Envoy::Set of the specified $type. So for a class My::Model::Foo
my $set = My::Models->m('Foo');
build(\%params)
Create a new instance of the Model::Envoy based class referenced by the set:
my $instance = $set->build({
attribute => $value,
...
});
fetch(%params)
Retrieve an object from storage
my $model = $set->fetch( id => 1 );
list(%params)
Query storage and return a list of objects that matched the query
my $models = $set->list(
color => 'green',
size => 'small',
...
);
get_storage($storage_package)
Passes back the storage plugin specified by $storage_package
being used by the set's model type. Follows the same namespace resolution process as the Model::Envoy
method of the same name.
load_types(@names)
For now Model::Envoy does not slurp all the classes in a certain namespace for use with $set->m(). Call load_types() at the start of your program instead:
My::Models->load_types( qw( Foo Bar Baz ) );