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