shared database connection trait
[catagits/Catalyst-TraitFor-Model-DBIC-Schema-SharedDatabaseConnection.git] / lib / Catalyst / TraitFor / Model / DBIC / Schema / SharedDatabaseConnection.pm
CommitLineData
1bf7f06b 1use strict;
2use warnings;
3
4package Catalyst::TraitFor::Model::DBIC::Schema::SharedDatabaseConnection;
5
6use Moose::Role;
7
8has parent_model => (
9 is => 'ro',
10 isa => 'Str',
11 required => 1,
12);
13
14has cloned => (
15 is => 'rw',
16 default => 0,
17);
18around ACCEPT_CONTEXT => sub {
19 my ( $orig, $self, $app, @rest ) = ( shift, shift, @_ );
20 unless ( $self->cloned ) {
21 $self->schema->storage(
22 $app->model( $self->parent_model )->schema->storage );
23 $self->cloned(1);
24 }
25 $self->$orig( $app, @rest );
26};
27
28no Moose::Role;
291;