A role for creating, finding and listing Model::Envoy based objects. Similar in philosophy to DBIx::Class::ResultSets.
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;
When incorporating this role into your class, you will need to specify the perl namespace where your model classes reside per the synopsis above.
Returns an Envoy::Set of the specified $type. So for a class My::Model::Foo
my $set = My::Models->m('Foo');
Create a new instance of the Model::Envoy based class referenced by the set:
my $instance = $set->build({ attribute => $value, ... });
Retrieve an object from storage
my $model = $set->fetch( id => 1 );
Query storage and return a list of objects that matched the query
my $models = $set->list( color => 'green', size => 'small', ... );
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.
$storage_package
Model::Envoy
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 ) );
To install Model::Envoy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Model::Envoy
CPAN shell
perl -MCPAN -e shell install Model::Envoy
For more information on module installation, please visit the detailed CPAN module installation guide.