lib/Reaction/UI/LayoutSet.pm

filter: Statementstmt 98.4% 62 / 63 Branchbran 78.5% 22 / 28 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 4 totaltotal 87.9% 95 / 108 CC 16 SCAR 16.3
CC
16
Cov
91%
_load_file
9.1
BUILD
5.4
widget_order_for
3.0
CRAP 5.1
« lib/Reaction/UI/Controller/Role/GetCollection.pm ↑ Summary lib/Reaction/UI/ViewPort/Collection/Grid/Member.pm »
1 package Reaction::UI::LayoutSet;
2  
3 5 ▶use Reaction::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use namespace::clean -except => [ qw(meta) ];
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 22 ▶has 'layouts' => (is => 'ro', default => sub { {} });
Subroutine __ANON__: called CC=1 SCAR=0.0
10  
11 5 has 'name' => (is => 'ro', required => 1);
12  
13 5 has 'source_file' => (is => 'ro', required => 1);
14  
15 5 has 'widget_class' => (
16 is => 'rw', lazy_fail => 1, predicate => 'has_widget_class'
17 );
18  
19 5 has 'widget_type' => (is => 'rw', lazy_build => 1);
20  
21 5 has 'super' => (is => 'rw', predicate => 'has_super');
22 22 ▶sub BUILD {
Subroutine BUILD: called CC=5 SCAR=16.8
Pod undocumented
23 22 my ($self, $args) = @_;
24 22 ▶ my @path = @{$args->{search_path}||[]};
Condition50%1/2
$args->{'search_path'} || []
l!l
022
MC/DC0%0/1
$args->{'search_path'} || []
$args->{'search_path'}
Truth table50%1/2
A
A= $args->{'search_path'}
Aresult
11
00
25 22 ▶ confess "No skin object provided" unless $args->{skin};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"skin"} 0 22 22
26 22 ▶ confess "No top skin object provided" unless $args->{top_skin};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"top_skin"} 0 22 22
27 22 $self->_load_file($self->source_file, $args);
28 22 ▶ unless ($self->has_widget_class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_widget_class) 22 0 22
29 22 $self->widget_class($args->{skin}->widget_class_for($self));
30 }
31 };
32 1543 ▶sub widget_order_for {
Subroutine widget_order_for: called CC=3 SCAR=11.0
Pod undocumented
33 1543 my ($self, $name) = @_;
34 return (
35 1543 ▶ ($self->has_layout($name)
Branch: 2 branches
BranchTrueFalseTotal
$self->has_layout($name) ? : 520 1023 1543
$self->has_super ? : 988 555 1543
36 ? ([ $self->widget_class, $self ]) #;
37 : ()),
38 ($self->has_super
39 ? ($self->super->widget_order_for($name))
40 : ()),
41 );
42 };
43 22 ▶sub layout_names {
Subroutine layout_names: called CC=2 SCAR=6.9
Pod undocumented
44 22 my ($self) = @_;
45 22 my %seen;
46 return [
47 210 grep { !$seen{$_}++ }
48 22 ▶ keys %{shift->layouts},
Branch: 1 branch
BranchTrueFalseTotal
$self->has_super ? : 13 9 22
49 ($self->has_super
50 22 ? (@{$self->super->layout_names})
51 : ())
52 ];
53 };
54 1543 ▶sub has_layout { exists $_[0]->layouts->{$_[1]} };
Subroutine has_layout: called CC=1 SCAR=0.0
Pod undocumented
55 22 ▶sub _load_file {
Subroutine _load_file: called CC=9 SCAR=22.1
56 22 my ($self, $file, $build_args) = @_;
57 22 my $data = $file->slurp;
58 22 ▶ utf8::decode($data)
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::is_utf8($data) 22 0 22
59 unless utf8::is_utf8($data);
60 22 my $layouts = $self->layouts;
61 # cheesy match for "=for layout name ... =something"
62 # final split group also handles last in file, (?==) is lookahead
63 # assertion for '=' so "=for layout name1 ... =for layout name2"
64 # doesn't have the match pos go past the latter = and lose name2
65 22 ▶ while ($data =~ m/=(.*?)\n(.*?)(?:\n(?==)|$)/sg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ /=(.*?)\n(.*?)(?:\n(?==)|$)/gs) 137 22 159
66 137 my ($data, $text) = ($1, $2);
67 137 ▶ if ($data =~ /^for layout (\S+)/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($data =~ /^for layout (\S+)/) { } 101 36 137
elsif ($data =~ /^extends (\S+)/) { } 13 23 36
elsif ($data =~ /^widget (\S+)/) { } 1 22 23
elsif ($data =~ /^cut/) { } 22 0 22
68 101 my $fname = $1;
69 101 $text =~ s/^(?:\s*\r?\n)+//; #remove leading empty lines
70 101 $text =~ s/[\s\r\n]+$//; #remove trailing whitespace
71 101 $layouts->{$fname} = $text;
72 } elsif ($data =~ /^extends (\S+)/) {
73 13 my $super_name = $1;
74 13 my $skin;
75 13 ▶ if ($super_name eq 'NEXT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($super_name eq 'NEXT') { } 9 4 13
76 confess "No next skin and layout extends NEXT"
77 9 ▶ unless $build_args->{next_skin};
Branch: 1 branch
BranchTrueFalseTotal
unless $build_args->{"next_skin"} 0 9 9
78 9 $skin = $build_args->{next_skin};
79 9 $super_name = $self->name;
80 } else {
81 4 $skin = $build_args->{top_skin};
82 }
83 13 $self->super($skin->create_layout_set($super_name));
84 } elsif ($data =~ /^widget (\S+)/) {
85 1 my $widget_type = $1;
86 1 $self->widget_type($1);
87 } elsif ($data =~ /^cut/) {
88 # no-op
89 } else {
90 0 confess "Unparseable directive ${data} in ${file}";
91 }
92 }
93 };
94 21 ▶sub _build_widget_type {
Subroutine _build_widget_type: called CC=1 SCAR=0.0
95 21 my ($self) = @_;
96 21 my $widget = join('', map { ucfirst($_) } split('_', $self->name));
97 21 $widget = join('::', map { ucfirst($_) } split('/', $widget));
98  
99 #print STDERR "--- ", $self->name, " maps to widget $widget \n";
100  
101 21 return $widget;
102 };
103  
104 5 __PACKAGE__->meta->make_immutable;
105  
106  
107 5 1;
« lib/Reaction/UI/Controller/Role/GetCollection.pm ↑ Summary lib/Reaction/UI/ViewPort/Collection/Grid/Member.pm »