lib/Reaction/UI/Skin.pm

filter: Statementstmt 82.3% 98 / 119 Branchbran 55.0% 22 / 40 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 95.6% 22 / 23 Podpod 0.0% 0 / 8 totaltotal 70.2% 144 / 205 CC 25 SCAR 22.0
CC
25
Cov
73%
_find_skin_dir
37.4
_load_skin_config
6.3
widget_class_for
6.3
CRAP 9.1
« lib/Reaction/UI/ViewPort/Field/Mutable/ChooseMany.pm ↑ Summary lib/Reaction/UI/Controller/Role/Action/Create.pm »
1 package Reaction::UI::Skin;
2  
3 5 ▶use Reaction::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # declaring dependencies
6 5 ▶use Reaction::UI::LayoutSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Reaction::UI::RenderingContext;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use File::ShareDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Config::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use aliased 'Path::Class::Dir';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 ▶use namespace::clean -except => [ qw(meta) ];
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 6 ▶has '_layout_set_cache' => (is => 'ro', default => sub { {} });
Subroutine __ANON__: called CC=1 SCAR=0.0
18 6 ▶has '_widget_class_cache' => (is => 'ro', default => sub { {} });
Subroutine __ANON__: called CC=1 SCAR=0.0
19  
20 5 has 'name' => (is => 'ro', isa => 'Str', required => 1);
21 5 has 'skin_dir' => (is => 'rw', isa => Dir, lazy_fail => 1);
22  
23 has 'widget_search_path' => (
24 6 ▶ is => 'rw', isa => 'ArrayRef', required => 1, default => sub { [] }
Subroutine __ANON__: called CC=1 SCAR=0.0
25 5 );
26  
27 5 has 'view' => (
28 is => 'ro', required => 1, weak_ref => 1,
29 handles => [ qw(layout_set_class) ],
30 );
31  
32 5 has 'super' => (
33 is => 'rw', isa => Skin, required => 0, predicate => 'has_super',
34 );
35  
36 6 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
37 6 my ($self, $args) = @_;
38 6 $self->_find_skin_dir($args);
39 6 $self->_load_skin_config($args);
40 }
41 6 ▶sub _find_skin_dir {
Subroutine _find_skin_dir: called CC=8 SCAR=36.2
42 6 my ($self, $args) = @_;
43 6 my $skin_name = $self->name;
44 6 ▶ if ($skin_name =~ s!^/(.*?)/!!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skin_name =~ s[^/(.*?)/][]) 0 6 6
45 0 my $dist = $1;
46 0 $args->{skin_base_dir} = eval {
47 0 Dir->new(File::ShareDir::dist_dir($dist))
48 ->subdir('skin');
49 };
50 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
51 # No installed Reaction
52 0 my $file = __FILE__;
53 0 my $dir = Dir->new(dirname($file));
54 0 my $skin_base;
55 0 ▶ while ($dir->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir->parent) 0 0 0
56 0 ▶ if (-d $dir->subdir('share') && -d $dir->subdir('share')->subdir('skin')) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dir->subdir("share") and -d $dir->subdir("share")->subdir("skin")) 0 0 0
Condition0%0/3
-d $dir->subdir("share") and -d $dir->subdir("share")->subdir("skin")
!ll&&!rl&&r
000
MC/DC0%0/2
-d $dir->subdir("share") and -d $dir->subdir("share")->subdir("skin")
-d $dir->subdir("share") -d $dir->subdir("share")->subdir("skin")
Truth table0%0/3
A and B
A= -d $dir->subdir("share")B= -d $dir->subdir("share")->subdir("skin")
ABresult
0X0
100
111
57 0 $skin_base = $dir->subdir('share')->subdir('skin');
58 0 last;
59 }
60 0 $dir = $dir->parent;
61 }
62 0 ▶ confess "could not find skinbase by recursion. ended up at $dir, from $file"
Branch: 1 branch
BranchTrueFalseTotal
unless $skin_base 0 0 0
63 unless $skin_base;
64 0 $args->{skin_base_dir} = $skin_base;
65 }
66 }
67 6 my $base = $args->{skin_base_dir}->subdir($skin_name);
68 6 ▶ confess "No such skin base directory ${base}"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $base 0 6 6
69 unless -d $base;
70 6 $self->skin_dir($base);
71 };
72 6 ▶sub _load_skin_config {
Subroutine _load_skin_config: called CC=6 SCAR=18.5
73 6 my ($self, $args) = @_;
74 6 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
600
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
75 6 my $base = $self->skin_dir;
76 6 ▶ my $lst = sub { (ref $_[0] eq 'ARRAY') ? $_[0] : [$_[0]] };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 4 2 6
77 my @files = (
78 6 $args->{skin_base_dir}->file('defaults.conf'), $base->file('skin.conf')
79 );
80 # we get [ { $file => $conf }, ... ]
81 10 my %cfg = (map { %{(values %{$_})[0]} }
82 6 @{Config::Any->load_files({
83 6 files => [ grep { -e $_ } map { $_->stringify } @files ],
84 use_ext => 1,
85 })}
86 );
87 6 ▶ if (my $super_name = $cfg{extends}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $super_name = $cfg{"extends"}) 4 2 6
88 my $super = $class->new(
89 name => $super_name,
90 view => $self->view,
91 skin_base_dir => $args->{skin_base_dir},
92 4 );
93 4 $self->super($super);
94 }
95 6 ▶ if (exists $cfg{widget_search_path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cfg{"widget_search_path"}) 6 0 6
96 6 $self->widget_search_path($lst->($cfg{widget_search_path}));
97 }
98 # For some reason this conditional doesn't work correctly without
99 # the "my @x". Answers on a postcard.
100 6 ▶ unless (my @x = $self->full_widget_search_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (my(@x) = $self->full_widget_search_path) 0 6 6
101 0 ▶ confess "No widget_search_path in defaults.conf or skin.conf"
Branch: 1 branch
BranchTrueFalseTotal
$self->has_super ? : 0 0 0
102 .($self->has_super
103 ? " and no search path provided from super skin "
104 .$self->super->name
105 : "");
106 }
107 }
108 22 ▶sub create_layout_set {
Subroutine create_layout_set: called CC=1 SCAR=0.0
Pod undocumented
109 22 my ($self, $name) = @_;
110 22 $self->_create_layout_set($name, [], $self);
111 };
112 35 ▶sub _create_layout_set {
Subroutine _create_layout_set: called CC=3 SCAR=11.1
113 35 my ($self, $name, $tried, $top_skin) = @_;
114 35 ▶ if (my $path = $self->layout_path_for($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = $self->layout_path_for($name)) 22 13 35
115 22 return $self->layout_set_class->new(
116 $self->layout_set_args_for($name),
117 source_file => $path,
118 top_skin => $top_skin,
119 );
120 }
121 13 $tried = [ @{$tried}, $self->our_path_for_type('layout') ];
122 13 ▶ if ($self->has_super) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_super) 13 0 13
123 13 return $self->super->_create_layout_set($name, $tried, $top_skin);
124 }
125 0 confess "Couldn't find layout set file for ${name}, tried "
126 .join(', ', @$tried);
127 };
128 22 ▶sub layout_set_args_for {
Subroutine layout_set_args_for: called CC=2 SCAR=6.9
Pod undocumented
129 22 my ($self, $name) = @_;
130 return (
131 22 ▶ name => $name,
Branch: 1 branch
BranchTrueFalseTotal
$self->has_super ? : 10 12 22
132 skin => $self,
133 ($self->has_super ? (next_skin => $self->super) : ()),
134 $self->view->layout_set_args_for($name),
135 );
136 };
137 35 ▶sub layout_path_for {
Subroutine layout_path_for: called CC=2 SCAR=6.9
Pod undocumented
138 35 my ($self, $layout) = @_;
139 35 my $file_name = join(
140 '.', $layout, $self->view->layout_set_file_extension
141 );
142 35 my $path = $self->our_path_for_type('layout')
143 ->file($file_name);
144 35 ▶ return (-e $path ? $path : undef);
Branch: 1 branch
BranchTrueFalseTotal
-e $path ? : 22 13 35
145 };
146 0 ▶sub search_path_for_type {
Subroutine search_path_for_type: not called CC=2 SCAR=17.9
Pod undocumented
147 0 my ($self, $type) = @_;
148 return [
149 $self->our_path_for_type($type),
150 ($self->has_super
151 0 ▶ ? @{$self->super->search_path_for_type($type)}
Branch: 1 branch
BranchTrueFalseTotal
$self->has_super ? : 0 0 0
152 : ()
153 )
154 ];
155 };
156 48 ▶sub our_path_for_type {
Subroutine our_path_for_type: called CC=1 SCAR=0.0
Pod undocumented
157 48 my ($self, $type) = @_;
158 48 return $self->skin_dir->subdir($type)
159 };
160 47 ▶sub full_widget_search_path {
Subroutine full_widget_search_path: called CC=2 SCAR=6.9
Pod undocumented
161 47 my ($self) = @_;
162 return (
163 47 ▶ @{$self->widget_search_path},
Branch: 1 branch
BranchTrueFalseTotal
$self->has_super ? : 19 28 47
164 ($self->has_super ? $self->super->full_widget_search_path : ())
165 );
166 };
167 22 ▶sub widget_class_for {
Subroutine widget_class_for: called CC=6 SCAR=18.4
Pod undocumented
168 22 my ($self, $layout_set) = @_;
169 22 my $base = blessed($self);
170 22 my $widget_type = $layout_set->widget_type;
171 22 ▶ return $self->_widget_class_cache->{$widget_type} ||= do {
Condition33%1/3
$self->_widget_class_cache->{$widget_type} ||= do { my(@search_path) = $self->full_widget_search_path; my(@haystack) = map({join "::", $_, $widget_type;} @search_path); foreach my $class (@haystack) { return $class if Class::MOP::is_class_loaded($class); next unless "Class::Inspector"->installed($class); my $ok = eval { do { Class::MOP::load_class($class) } }; confess("Failed to load widget '${class}': $@") if $@; return $class; } ; confess("Couldn't locate widget '${widget_type}' for layout " . "'${\$layout_set->name;}': tried: " . join(", ", @haystack)) }
l!l&&r!l&&!r
0022
MC/DC0%0/2
$self->_widget_class_cache->{$widget_type} ||= do { my(@search_path) = $self->full_widget_search_path; my(@haystack) = map({join "::", $_, $widget_type;} @search_path); foreach my $class (@haystack) { return $class if Class::MOP::is_class_loaded($class); next unless "Class::Inspector"->installed($class); my $ok = eval { do { Class::MOP::load_class($class) } }; confess("Failed to load widget '${class}': $@") if $@; return $class; } ; confess("Couldn't locate widget '${widget_type}' for layout " . "'${\$layout_set->name;}': tried: " . join(", ", @haystack)) }
$self->_widget_class_cache->{$widget_type} do { my(@search_path) = $self->full_widget_search_path; my(@haystack) = map({join "::", $_, $widget_type;} @search_path); foreach my $class (@haystack) { return $class if Class::MOP::is_class_loaded($class); next unless "Class::Inspector"->installed($class); my $ok = eval { do { Class::MOP::load_class($class) } }; confess("Failed to load widget '${class}': $@") if $@; return $class; } ; confess("Couldn't locate widget '${widget_type}' for layout " . "'${\$layout_set->name;}': tried: " . join(", ", @haystack)) }
Truth table33%1/3
A ||= B
A= $self->_widget_class_cache->{$widget_type}B= do { my(@search_path) = $self->full_widget_search_path; my(@haystack) = map({join "::", $_, $widget_type;} @search_path); foreach my $class (@haystack) { return $class if Class::MOP::is_class_loaded($class); next unless "Class::Inspector"->installed($class); my $ok = eval { do { Class::MOP::load_class($class) } }; confess("Failed to load widget '${class}': $@") if $@; return $class; } ; confess("Couldn't locate widget '${widget_type}' for layout " . "'${\$layout_set->name;}': tried: " . join(", ", @haystack)) }
ABresult
1X1
011
000
172  
173 22 my @search_path = $self->full_widget_search_path;
174 22 my @haystack = map {join('::', $_, $widget_type)} @search_path;
175  
176 22 foreach my $class (@haystack) {
177 #if the class is already loaded skip the call to Installed etc.
178 45 ▶ return $class if Class::MOP::is_class_loaded($class);
Branch: 1 branch
BranchTrueFalseTotal
if Class::MOP::is_class_loaded($class) 13 32 45
179 32 ▶ next unless Class::Inspector->installed($class);
Branch: 1 branch
BranchTrueFalseTotal
unless "Class::Inspector"->installed($class) 23 9 32
180  
181 9 my $ok = eval { Class::MOP::load_class($class) };
182 9 ▶ confess("Failed to load widget '${class}': $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 9 9
183 9 return $class;
184 }
185 0 confess "Couldn't locate widget '${widget_type}' for layout "
186 0 ."'${\$layout_set->name}': tried: ".join(", ", @haystack);
187 };
188 };
189  
190 5 __PACKAGE__->meta->make_immutable;
191  
192  
193 5 1;
« lib/Reaction/UI/ViewPort/Field/Mutable/ChooseMany.pm ↑ Summary lib/Reaction/UI/Controller/Role/Action/Create.pm »