| 1 | package Catalyst::TraitFor::Model::DBIC::ConfigPerSite; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Catalyst::TraitFor::Model::DBIC::ConfigPerSite - Extend Catalyst DBIC Model to work with multiple DB connections | ||||||||||
| 8 | |||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||
| 10 | |||||||||||
| 11 | package MyApp::Model::DBIC; | ||||||||||
| 12 | |||||||||||
| 13 | use Moose; | ||||||||||
| 14 | |||||||||||
| 15 | extends 'Catalyst::Model::DBIC::Schema'; | ||||||||||
| 16 | |||||||||||
| 17 | with qw(Catalyst::TraitFor::Model::DBIC::ConfigPerSite); | ||||||||||
| 18 | |||||||||||
| 19 | =head1 DESCRIPTION | ||||||||||
| 20 | |||||||||||
| 21 | This Role or Trait allows you to share an application between sites, clients, etc with different configuration for databases. It extends Catalyst DBIC Model to work with multiple DB connections, one per site or configuration. | ||||||||||
| 22 | |||||||||||
| 23 | =cut | ||||||||||
| 24 | |||||||||||
| 25 | 1 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 1 | with qw( Catalyst::Component::InstancePerContext Catalyst::TraitFor::Component::ConfigPerSite); | |||||||||
| 27 | |||||||||||
| 28 | =head1 METHODS | ||||||||||
| 29 | |||||||||||
| 30 | =head2 build_per_context_instance | ||||||||||
| 31 | |||||||||||
| 32 | =cut | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub build_per_context_instance { | ||||||||
|
Subroutine
build_per_context_instance: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 35 | 0 | my ($self, $c) = @_; | |||||||||
| 36 | 0 | ▶ | return $_[0] unless ref($_[1]); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | my $config = $self->get_component_config($c); | |||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | if (my $instance = $self->get_from_instance_cache($config)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | return $instance; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 0 | my @connect_info = ( @{$config->{connect_info}}{qw/dsn user password/}); | |||||||||
| 44 | |||||||||||
| 45 | 0 | my $new = bless({ %$self }, ref($self)); | |||||||||
| 46 | 0 | $new->config($config); | |||||||||
| 47 | 0 | $new->schema($self->schema->connect(@connect_info)); | |||||||||
| 48 | |||||||||||
| 49 | 0 | $self->put_in_instance_cache($config, $new); | |||||||||
| 50 | |||||||||||
| 51 | 0 | return $new; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | =head1 SEE ALSO | ||||||||||
| 55 | |||||||||||
| 56 | Catalyst::Component::InstancePerContext | ||||||||||
| 57 | |||||||||||
| 58 | Moose::Role | ||||||||||
| 59 | |||||||||||
| 60 | =head1 AUTHOR | ||||||||||
| 61 | |||||||||||
| 62 | Aaron Trevena, E<lt>aaron@aarontrevena.co.ukE<gt> | ||||||||||
| 63 | |||||||||||
| 64 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 65 | |||||||||||
| 66 | Copyright (C) 2010 by Aaron Trevena | ||||||||||
| 67 | |||||||||||
| 68 | This library is free software; you can redistribute it and/or modify | ||||||||||
| 69 | it under the same terms as Perl itself, either Perl version 5.10.0 or, | ||||||||||
| 70 | at your option, any later version of Perl 5 you may have available. | ||||||||||
| 71 | |||||||||||
| 72 | |||||||||||
| 73 | =cut | ||||||||||
| 74 | |||||||||||
| 75 | 1 | 1; | |||||||||