Model/DBIC/ConfigPerSite.pm

filter: Statementstmt 96.1% 25 / 26 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 91.4% 32 / 35 CC 3 SCAR 7.1
CC
3
Cov
90%
build_per_context_instance
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« TraitFor/View/TT/ConfigPerSite.pm ↑ Summary
1 package Catalyst::Model::DBIC::ConfigPerSite;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 Catalyst::Model::DBIC::ConfigPerSite - superclass for DBIC::Schema models
7  
8 =head1 DESCRIPTION
9  
10 Provides per-site database connections in your DBIC::Schema model
11  
12 =head1 SYNOPSIS
13  
14 package MyApp::Model::DBIC;
15  
16 use Moose;
17  
18 extends 'Catalyst::Model::DBIC::ConfigPerSite';
19  
20 ...
21  
22 =cut
23  
24 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 4 extends 'Catalyst::Model::DBIC::Schema';
28  
29 4 with qw( Catalyst::Component::InstancePerContext Catalyst::TraitFor::Component::ConfigPerSite);
30  
31 4 has '+schema_class' => (
32 required => 0
33 );
34  
35 =head1 METHODS
36  
37 =head2 build_per_context_instance
38  
39 =cut
40  
41 3 ▶sub build_per_context_instance {
Subroutine build_per_context_instance: called CC=3 SCAR=11.1
Pod documented
42 3 my ($self, $c) = @_;
43 3 ▶ return $self unless blessed($c);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($c) 0 3 3
44 3 my $config = $self->get_component_config($c);
45  
46 3 ▶ if (my $instance = $self->get_from_instance_cache($config)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $instance = $self->get_from_instance_cache($config)) 0 3 3
47 0 return $instance;
48 }
49  
50 3 my @connect_info = ( @{$config->{connect_info}}{qw/dsn user password/});
51  
52 3 my $new = bless({ %$self }, ref($self));
53 3 my $schema = $new->schema->clone;
54 3 $new->config($config);
55  
56 3 $new->schema($self->schema->connect(@connect_info));
57  
58 3 $self->put_in_instance_cache($config, $new);
59  
60 3 return $new;
61 }
62  
63 =head1 SEE ALSO
64  
65 Catalyst::Component::InstancePerContext
66  
67 Moose::Role
68  
69 =head1 AUTHOR
70  
71 Aaron Trevena, E<lt>aaron@aarontrevena.co.ukE<gt>
72  
73 =head1 COPYRIGHT AND LICENSE
74  
75 Copyright (C) 2010-2013 by Aaron Trevena
76  
77 This library is free software; you can redistribute it and/or
78 it under the same terms as Perl itself, either Perl version 5
79 at your option, any later version of Perl 5 you may have avai
80  
81 =cut
82  
83 4 1;
« TraitFor/View/TT/ConfigPerSite.pm ↑ Summary