lib/Rapi/Blog/Template/Dispatcher.pm

filter: Statementstmt 35.6% 41 / 115 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 23.5% 8 / 34 Podpod 0.0% 0 / 6 totaltotal 21.4% 49 / 229 CC 31 SCAR 29.7
CC
31
Cov
23%
resolve
72.0
_resolve_best_scaffold
42.0
_get_factory_opts
30.0
CRAP 19.5
« lib/Rapi/Blog/DB/Result/PreauthAction.pm ↑ Summary lib/Rapi/Blog/DB/Result/Comment.pm »
1 package Rapi::Blog::Template::Dispatcher;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 1 ▶use RapidApp::Util qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Rapi::Blog::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Module::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
9
10 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Types::Standard ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
12
13
14 1 has 'AccessStore', is => 'ro', required => 1, isa => InstanceOf['Rapi::Blog::Template::AccessStore'];
15 1 has 'path', is => 'ro', required => 1, isa => Str;
16 1 has 'ctx', is => 'ro', required => 1;
17
18 0 ▶has 'Scaffold', is => 'ro', isa => Maybe[InstanceOf['Rapi::Blog::Scaffold']], default => sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=1.2
19
20
21 0 ▶has 'parent', is => 'ro', default => sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=1.2
22
23 0 ▶has 'type', is => 'ro', init_arg => undef, lazy => 1, default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 0 my $self = shift;
25 0 my ($pfx,$type) = split('Rapi::Blog::Template::Dispatcher::',(ref $self),2);
26 0 $type
27 1 };
28
29 0 ▶sub is_type {
Subroutine is_type: not called CC=3 SCAR=24.8
Pod undocumented
30 0 my ($self, $type) = @_;
31 0 ▶ $type && $self->type && $type eq $self->type
Branch: 1 branch
BranchTrueFalseTotal
$type and $self->type and $type eq $self->type 0 0 0
Condition0%0/3
$type and $self->type
!ll&&!rl&&r
000
MC/DC0%0/2
$type and $self->type
$type $self->type
Truth table0%0/3
A and B
A= $typeB= $self->type
ABresult
0X0
100
111
32 }
33
34 0 ▶sub find_parent_type {
Subroutine find_parent_type: not called CC=3 SCAR=24.8
Pod undocumented
35 0 my ($self, $type) = @_;
36 0 ▶ return undef unless ($self->parent);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parent 0 0 0
37 0 ▶ $self->parent->is_type($type) ? $self->parent : $self->parent->find_parent_type($type)
Branch: 1 branch
BranchTrueFalseTotal
$self->parent->is_type($type) ? : 0 0 0
38 }
39
40
41 0 ▶has 'claimed', is => 'ro', init_arg => undef, lazy => 1, default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
42 0 my $self = shift;
43 0 ▶ $self->parent ? 1 : 0
Branch: 1 branch
BranchTrueFalseTotal
$self->parent ? : 0 0 0
44 1 }, isa => Bool;
45
46
47 0 ▶has 'exists', is => 'ro', lazy => 1, isa => Bool, default => sub { 0 };
Subroutine __ANON__: not called CC=1 SCAR=1.2
48 0 ▶has 'mtime', is => 'ro', lazy => 1, isa => Maybe[Str], default => sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=1.2
49 0 ▶has 'content', is => 'ro', lazy => 1, isa => Maybe[Str], default => sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=1.2
50
51 0 ▶has 'restrict', is => 'ro', lazy => 1, isa => Bool, default => sub { 0 };
Subroutine __ANON__: not called CC=1 SCAR=1.2
52
53 0 ▶has 'template_vars', is => 'ro', lazy => 1, isa => HashRef, default => sub {{}};
Subroutine __ANON__: not called CC=1 SCAR=1.2
54
55
56 0 ▶has 'is_static', is => 'ro', lazy => 1, default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 my $self = shift;
58 0 $self->Scaffold->_is_static_path($self->path)
59 1 }, isa => Bool;
60
61 0 ▶has 'is_private', is => 'ro', lazy => 1, default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 0 my $self = shift;
63 0 $self->Scaffold->_is_private_path($self->path)
64 1 }, isa => Bool;
65
66 0 ▶has 'valid_not_found_tpl', is => 'ro', init_arg => undef, lazy => 1, default => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
67 0 my $self = shift;
68 0 ▶ my $tpl = $self->Scaffold->not_found_template or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $tpl = $self->Scaffold->not_found_template or return undef 0 0 0
69 0 ▶ $self->Scaffold->resolve_file($tpl) ? $tpl : undef
Branch: 1 branch
BranchTrueFalseTotal
$self->Scaffold->resolve_file($tpl) ? : 0 0 0
70 1 }, isa => Maybe[Str];
71
72
73 0 ▶sub rank { 0 }
Subroutine rank: not called CC=1 SCAR=6.9
Pod undocumented
74
75 0 ▶sub resolved { (shift) }
Subroutine resolved: not called CC=1 SCAR=6.9
Pod undocumented
76
77 0 ▶sub _factory_for {
Subroutine _factory_for: not called CC=1 SCAR=6.9
78 0 my ($self,$type,@args) = @_;
79
80 0 my $class = join('::',__PACKAGE__,$type);
81 0 Module::Runtime::require_module($class);
82
83 0 my %opts = $self->_get_factory_opts(@args);
84
85 0 $class->_factory_class(%opts)
86 }
87
88
89 0 ▶sub _get_factory_opts {
Subroutine _get_factory_opts: not called CC=5 SCAR=34.0
90 0 my $self = shift;
91 0 ▶ my %opts = (ref($_[0]) eq 'HASH') ? %{ $_[0] } : @_; # <-- arg as hash or hashref
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
92
93 0 my @attrs = qw(AccessStore path ctx Scaffold);
94 0 ▶ exists $opts{$_} or $opts{$_} = $self->$_ for (@attrs);
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{$_} or $opts{$_} = $self->$_ 0 0 0
95
96 0 ▶ $opts{parent} = $self if ($self->Scaffold);
Branch: 1 branch
BranchTrueFalseTotal
if $self->Scaffold 0 0 0
97
98 0 %opts
99 }
100
101 0 ▶sub _factory {
Subroutine _factory: not called CC=3 SCAR=24.8
102 0 my $self = shift;
103 0 my ($class, %opts);
104
105 0 ▶ if(ref($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
106 0 %opts = $self->_get_factory_opts(@_);
107 0 $class = ref($self)
108 }
109 else {
110 0 ▶ %opts = (ref($_[0]) eq 'HASH') ? %{ $_[0] } : @_; # <-- arg as hash or hashref
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
111 0 $class = $self
112 }
113
114 0 $class->_factory_class(%opts)
115 }
116
117
118 0 ▶sub _factory_class {
Subroutine _factory_class: not called CC=1 SCAR=6.9
119 0 my $class = shift;
120 0 $class->new(@_)->resolved
121 }
122
123
124 0 ▶sub us_or_better {
Subroutine us_or_better: not called CC=3 SCAR=24.8
Pod undocumented
125 0 my ($this,$that) = @_;
126 0 ▶ $that && $that->rank > $this->rank ? $that : $this
Branch: 1 branch
BranchTrueFalseTotal
$that && $that->rank > $this->rank ? : 0 0 0
Condition0%0/3
$that and $that->rank > $this->rank
!ll&&!rl&&r
000
MC/DC0%0/2
$that and $that->rank > $this->rank
$that $that->rank > $this->rank
Truth table0%0/3
A and B
A= $thatB= $that->rank > $this->rank
ABresult
0X0
100
111
127 }
128
129
130 0 ▶sub _resolve_best_scaffold {
Subroutine _resolve_best_scaffold: not called CC=6 SCAR=37.4
131 0 my $self = shift;
132
133 0 my @scaffolds = $self->AccessStore->ScaffoldSet->all;
134 0 ▶ scalar(@scaffolds) > 0 or die "Fatal error -- no Scaffolds detected. At least one Scaffold must be loaded.";
Branch: 1 branch
BranchTrueFalseTotal
scalar @scaffolds > 0 or die "Fatal error -- no Scaffolds detected. At least one Scaffold must be loaded." 0 0 0
135
136 0 ▶ if (my $uuid = $self->ctx->stash->{rapi_blog_only_scaffold_uuid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $uuid = $self->ctx->stash->{"rapi_blog_only_scaffold_uuid"}) 0 0 0
137 0 @scaffolds = grep { $_->uuid eq $uuid } @scaffolds;
138 0 ▶ scalar(@scaffolds) > 0 or die join('',
Branch: 1 branch
BranchTrueFalseTotal
scalar @scaffolds > 0 or die join("", "Fatal error -- rapi_blog_only_scaffold_uuid is set ('${uuid}') but there ", "is no Scaffold with that uuid") 0 0 0
139 "Fatal error -- rapi_blog_only_scaffold_uuid is set ('$uuid') but there ",
140 "is no Scaffold with that uuid"
141 );
142 }
143
144 0 my $Best = undef;
145 0 for (@scaffolds) {
146 0 my $Next = $self->_factory( Scaffold => $_ )->resolve;
147 0 ▶ $Best = $Best ? $Best->us_or_better($Next) : $Next;
Branch: 1 branch
BranchTrueFalseTotal
$Best ? : 0 0 0
148 }
149
150 $Best
151 0 }
152
153
154 0 ▶sub resolve {
Subroutine resolve: not called CC=8 SCAR=42.8
Pod undocumented
155 0 my $self = shift;
156
157 0 ▶ $self->Scaffold or return $self->_resolve_best_scaffold;
Branch: 1 branch
BranchTrueFalseTotal
$self->Scaffold or return $self->_resolve_best_scaffold 0 0 0
158
159 0 my $FileDispatch = $self->_factory_for('ScaffoldFile');
160
161 0 ▶ ($FileDispatch && $FileDispatch->exists ? $FileDispatch : undef) ||
Branch: 2 branches
BranchTrueFalseTotal
$FileDispatch && $FileDispatch->exists ? $FileDispatch : undef or $self->_resolve_DirectPost or $self->_resolve_ViewWrapper or $FileDispatch or $self->_factory_for("Unclaimed") 0 0 0
$FileDispatch && $FileDispatch->exists ? : 0 0 0
Condition0%0/12
$FileDispatch && $FileDispatch->exists ? $FileDispatch : undef or $self->_resolve_DirectPost or $self->_resolve_ViewWrapper or $FileDispatch
l!l&&r!l&&!r
000
$FileDispatch && $FileDispatch->exists ? $FileDispatch : undef or $self->_resolve_DirectPost or $self->_resolve_ViewWrapper
l!l&&r!l&&!r
000
$FileDispatch && $FileDispatch->exists ? $FileDispatch : undef or $self->_resolve_DirectPost
l!l&&r!l&&!r
000
$FileDispatch and $FileDispatch->exists
!ll&&!rl&&r
000
MC/DC0%0/5
$FileDispatch && $FileDispatch->exists ? $FileDispatch : undef or $self->_resolve_DirectPost or $self->_resolve_ViewWrapper or $FileDispatch
$FileDispatch $FileDispatch->exists $self->_resolve_DirectPost $self->_resolve_ViewWrapper $FileDispatch
Truth table0%0/9
A and B or C or D or E
A= $FileDispatchB= $FileDispatch->existsC= $self->_resolve_DirectPostD= $self->_resolve_ViewWrapperE= $FileDispatch
ABCDEresult
11XXX1
0X1XX1
101XX1
0X01X1
1001X1
0X0011
100011
0X0000
100000
162 $self->_resolve_DirectPost ||
163 $self->_resolve_ViewWrapper ||
164 $FileDispatch ||
165 $self->_factory_for('Unclaimed')
166 }
167
168
169
170
171 0 ▶sub _resolve_DirectPost {
Subroutine _resolve_DirectPost: not called CC=3 SCAR=24.8
172 0 my $self = shift;
173 0 my ($pfx,$name) = split($self->Scaffold->unique_int_post_path,$self->path,2);
174 0 ▶ ($name && $pfx eq '')
Branch: 1 branch
BranchTrueFalseTotal
$name && $pfx eq '' ? : 0 0 0
Condition0%0/3
$name and $pfx eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
$name and $pfx eq ""
$name $pfx eq ""
Truth table0%0/3
A and B
A= $nameB= $pfx eq ""
ABresult
0X0
100
111
175 ? $self->_factory_for('Post', name => $name, direct => 1)
176 : undef
177 }
178
179
180
181 0 ▶sub _resolve_ViewWrapper {
Subroutine _resolve_ViewWrapper: not called CC=2 SCAR=17.9
182 0 my $self = shift;
183 0 my ($VW, $path) = $self->Scaffold->resolve_ViewWrapper($self->path);
184 0 ▶ $VW ? $self->_factory_for('ViewWrapper', ViewWrapper => $VW, subpath => $path) : undef
Branch: 1 branch
BranchTrueFalseTotal
$VW ? : 0 0 0
185 }
186
187
188
189
190 0 ▶has 'maybe_psgi_response', is => 'ro', init_arg => undef, lazy => 1, default => sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=1.2
191
192
193 1 1;
« lib/Rapi/Blog/DB/Result/PreauthAction.pm ↑ Summary lib/Rapi/Blog/DB/Result/Comment.pm »