Commit | Line | Data |
1bf7f06b |
1 | use strict; |
2 | use warnings; |
3 | |
4 | package Catalyst::TraitFor::Model::DBIC::Schema::SharedDatabaseConnection; |
5 | |
6 | use Moose::Role; |
7 | |
8 | has parent_model => ( |
9 | is => 'ro', |
10 | isa => 'Str', |
11 | required => 1, |
12 | ); |
13 | |
14 | has cloned => ( |
15 | is => 'rw', |
16 | default => 0, |
17 | ); |
18 | around 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 | |
28 | no Moose::Role; |
29 | 1; |