The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Model::Envoy::Storage::DBIC

A Moose Role that adds a DBIx::Class persistence layer to your Moose class

Configuration

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

The only configuration option for this plugin is a 'schema' method that returns a DBIx::Class:Schema based object with an open connection to the database.

dbic()

This is a method you will need to implement in each Model::Envoy object that use this storage plugin. It should return the name of the DBIx::Class ResultClass that your Model uses for database storage.

Traits

This role implements one trait:

DBIC

Marking an attribute on your object with the 'DBIC' trait tells this role that it is backed by a DBIx::Class ResultClass column of the same name. It also allows for a few custom options you can apply to that attribute:

primary_key => 1

Indicates that this attribute corresponds to the primary key for the database record

rel => 'rel_type'

Indicates that the attribute is a relationship to another model or a list of models. Possible values for this option are

belongs_to
has_many
many_to_many
mm_rel => 'bridge_name'

For many-to-many relationships it is necessary to indicate what class provides the linkage between the two ends of the relationship ( the linking class maps to the join table in the database).

Plugin Methods

build( $dbic_result, [$no_rel] )

Takes a DBIx::Class result object and, if it's class matches your class's dbic() method, attempts to build a new instance of your class based on the $dbic_result passed in.

The `no_rel` boolean option prevents the creation process from traversing attributes marked as relationships, minimizing the amount of data pulled from the database and the number of new class instances created.

Returns the class instance if successful.

save()

Performs either an insert or an update for the model, depending on whether there is already a record for it in the database.

Returns the calling object for convenient chaining.

delete()

Deletes the persistent copy of the current model from the database, if has been stored there.

Returns nothing.

in_storage()

Uses DBIx::Class's internal mechanisms to determine if this model is tied to a record in the database.

Returns a true value if it is, otherwise returns a false value.