TraitFor/View/TT/ConfigPerSite.pm

filter: Statementstmt 96.4% 27 / 28 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 92.6% 38 / 41 CC 5 SCAR 11.2
CC
5
Cov
91%
build_per_context_instance
5.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.1
« TraitFor/Model/DBIC/ConfigPerSite.pm ↑ Summary Model/DBIC/ConfigPerSite.pm »
1 package Catalyst::TraitFor::View::TT::ConfigPerSite;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 Catalyst::TraitFor::View::TT::ConfigPerSite - Extend Catalyst TT View to work with multiple sites at once
8  
9 =head1 SYNOPSIS
10  
11 package MyApp::View::TT;
12  
13 use Moose;
14  
15 extends 'Catalyst::View::TT';
16  
17 with qw(Catalyst::TraitFor::View::TT::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 TT View to work with multiple template paths, per site or configuration.
22  
23 =cut
24  
25 4 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 with qw( Catalyst::Component::InstancePerContext Catalyst::TraitFor::Component::ConfigPerSite);
27  
28 4 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 =head1 METHODS
33  
34 =head2 build_per_context_instance
35  
36 =cut
37  
38 3 ▶sub build_per_context_instance {
Subroutine build_per_context_instance: called CC=5 SCAR=16.4
Pod documented
39 3 my ($self,$c,%args) = @_;
40 3 ▶ return $_[0] unless ref($_[1]);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[1] 0 3 3
41  
42 3 my $config = $self->get_component_config($c);
43  
44 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
45 0 return $instance;
46 }
47  
48 # Slightly evil - we use hash/array flattening side-effect in TT View constructor to inject/overwrite with site specific config
49 3 foreach my $key ( keys %$config ) {
50 14 ▶ next if ($key eq 'site_name');
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "site_name" 3 11 14
51 11 $args{$key} = $config->{$key};
52 }
53  
54 3 my $new = $self->new($c, \%args);
55  
56 3 $self->put_in_instance_cache($config, $new);
57  
58 3 return $new;
59 }
60  
61 =head1 SEE ALSO
62  
63 Catalyst::Component::InstancePerContext
64  
65 Moose::Role
66  
67 =head1 AUTHOR
68  
69 Aaron Trevena, E<lt>aaron@aarontrevena.co.ukE<gt>
70  
71 =head1 COPYRIGHT AND LICENSE
72  
73 Copyright (C) 2010-2013 by Aaron Trevena
74  
75 This library is free software; you can redistribute it and/or modify
76 it under the same terms as Perl itself, either Perl version 5.10.0 or,
77 at your option, any later version of Perl 5 you may have available.
78  
79  
80 =cut
81  
82 4 1;
« TraitFor/Model/DBIC/ConfigPerSite.pm ↑ Summary Model/DBIC/ConfigPerSite.pm »