Storage Plugins

Model::Envoy provides the ability to persist objects via any number of services via plugins. These plugins are referenced in Model::Envoy's role parameters, and dispatched to as needed.

Declaration & Configuration

    with 'Model::Envoy' => { storage => {
        'DBIC' => {
            schema => sub {
                ... connect to database here ...
            }
        }
    } };

Any configuration information you need passed into your plugin should be part of the hashref attached to the plugin key in the role parameters.

Instantiation

When Model::Envoy creates an instance of your plugin to track a model object via new(), it will pass in the configuration information and a reference to the model object to track.

Required Methods

save

save the data from the model object this instance is tracking to your persistence service.

delete

delete the data from the model object this instance is tracking from your persistence service.

fetch(%params)

This method is expected to take some parameters and return a single Model::Envoy based object in response. Typically this will be an id the plugin uses to look up a record, but it could be multiple parameters depending on the needs of the plugin.

list(%params)

This method is expected to take some search parameters and return an arrayref of zero or more Model::Envoy based objects in response.

Optional Methods

configure($self, $conf)

When your models first need to connect to storage, they will call configure on your storage plugin to give it a chance to perform setup that will be needed by all of your instance objects (a database handle, for example).

$self - the plugin's class
$conf - the hashref of configuration information specified in Model::Envoy's role parameters

If you implement this method, you should set the key _configured in the $conf hashref to a true value to tell Model::Envoy that configuration was successful.

build($class, $model_class, $object, [$no_rel] )

If your plugin knows how to take a particular kind of object (say, a database record class) and turn it into a matching Model::Envoy based object, it should implement this method.

$class - the plugin's class
$model_class - the Model::Envoy based class we're trying to make
$object - the raw datastructure you'll be trying to turn into the requested $model_class
$no_rel - an optional boolean to indicate whether to walk the relationship tree of the $object to create more Model::Envoy based objects (to limit recursion).