« 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if (-d $dir->subdir('share') && -d $dir->subdir('share')->subdir('skin')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-d $dir->subdir("share") and -d $dir->subdir("share")->subdir("skin")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | confess "No widget_search_path in defaults.conf or skin.conf" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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))
}
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))
}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 179 | 32 | ▶ | next unless Class::Inspector->installed($class); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 9 | my $ok = eval { Class::MOP::load_class($class) }; | |||||||||||||||||||||||||||
| 182 | 9 | ▶ | confess("Failed to load widget '${class}': $@") if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||