lib/Mojolicious/Plugin/Check.pm

filter: Statementstmt 59.4% 22 / 37 Branchbran 0.0% 0 / 8 Conditioncond 50.0% 7 / 14 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 48.6% 35 / 72 CC 13 SCAR 29.5
CC
13
Cov
49%
__ANON__
35.0
register
6.7
__ANON__
6.0
CRAP 19.1
↑ Summary
1 package Mojolicious::Plugin::Check;
2 9 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 9 our $VERSION = '0.03';
5  
6 9 ▶sub register {
Subroutine register: called CC=4 SCAR=19.1
Pod documented
7 9 my ($self, $app, $conf) = @_;
8  
9 9 ▶ $conf ||= {};
Condition50%1/2
$conf ||= {}
l!l
90
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
Aresult
11
00
10 9 ▶ $conf->{stash_checkers} //= 'plugin-check-checkers';
Condition50%1/2
$conf->{"stash_checkers"} //= "plugin-check-checkers"
l!l
09
MC/DC0%0/1
$conf->{"stash_checkers"} //= "plugin-check-checkers"
$conf->{"stash_checkers"}
Truth table50%1/2
A
A= $conf->{"stash_checkers"}
Aresult
11
00
11 9 ▶ $conf->{stash_actions} //= 'plugin-check-actions';
Condition50%1/2
$conf->{"stash_actions"} //= "plugin-check-actions"
l!l
09
MC/DC0%0/1
$conf->{"stash_actions"} //= "plugin-check-actions"
$conf->{"stash_actions"}
Truth table50%1/2
A
A= $conf->{"stash_actions"}
Aresult
11
00
12  
13 11 ▶ $app->helper(add_checker => sub {
Subroutine __ANON__: called CC=2 SCAR=8.7
14 11 my ($c, $name, $sub) = @_;
15  
16 11 ▶ my $checkers = $c->app->routes->{$conf->{stash_checkers}} //= {};
Condition100%2/2
$c->app->routes->{$conf->{"stash_checkers"}} //= {}
l!l
29
MC/DC100%1/1
$c->app->routes->{$conf->{"stash_checkers"}} //= {}
$c->app->routes->{$conf->{"stash_checkers"}}
Truth table100%2/2
A
A= $c->app->routes->{$conf->{"stash_checkers"}}
Aresult
11
00
17 11 $checkers->{$name} = $sub;
18  
19 0 ▶ $c->app->routes->add_condition($name => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
20 0 my ($route, $c, $captures, $pattern) = @_;
21  
22 0 ▶ my $actions = $c->stash->{$conf->{stash_actions}} //= [];
Condition0%0/2
$c->stash->{$conf->{"stash_actions"}} //= []
l!l
00
MC/DC0%0/1
$c->stash->{$conf->{"stash_actions"}} //= []
$c->stash->{$conf->{"stash_actions"}}
Truth table0%0/2
A
A= $c->stash->{$conf->{"stash_actions"}}
Aresult
11
00
23 0 push @$actions, [$name, $route, $c, {%$captures}, $pattern];
24  
25 0 return 1;
26 11 });
27  
28 11 return $self;
29 9 });
30  
31 2 ▶ $app->hook(around_action => sub {
Subroutine __ANON__: called CC=8 SCAR=35.6
32 2 my ($next, $c, $action, $last) = @_;
33  
34 2 ▶ my $checkers = $c->app->routes->{$conf->{stash_checkers}} //= {};
Condition50%1/2
$c->app->routes->{$conf->{"stash_checkers"}} //= {}
l!l
20
MC/DC0%0/1
$c->app->routes->{$conf->{"stash_checkers"}} //= {}
$c->app->routes->{$conf->{"stash_checkers"}}
Truth table50%1/2
A
A= $c->app->routes->{$conf->{"stash_checkers"}}
Aresult
11
00
35 2 ▶ my $actions = $c->stash->{$conf->{stash_actions}} //= [];
Condition50%1/2
$c->stash->{$conf->{"stash_actions"}} //= []
l!l
02
MC/DC0%0/1
$c->stash->{$conf->{"stash_actions"}} //= []
$c->stash->{$conf->{"stash_actions"}}
Truth table50%1/2
A
A= $c->stash->{$conf->{"stash_actions"}}
Aresult
11
00
36  
37 2 for my $args ( @$actions ) {
38 0 my ($name, @opts) = @$args;
39  
40 0 my $checker = $checkers->{ $name };
41 0 ▶ next unless $checker;
Branch: 1 branch
BranchTrueFalseTotal
unless $checker 0 0 0
42  
43 0 my @result = $checker->( @opts );
44  
45 0 ▶ if( @result ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@result) { } 0 0 0
46 0 ▶ if( defined $result[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result[0]) { } 0 0 0
47 0 ▶ if( $result[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result[0]) { } 0 0 0
48 0 next;
49 } else {
50 0 return $c->reply->not_found;
51 }
52 } else {
53 0 return;
54 }
55 } else {
56 0 return $c->reply->not_found;
57 }
58 }
59  
60 2 return $next->();
61 9 });
62  
63 9 return;
64 }
65  
66 9 1;
67  
68 __END__
↑ Summary