| 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 ||= {}
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
| |||||||||||||
| 10 | 9 | ▶ | $conf->{stash_checkers} //= 'plugin-check-checkers'; | ||||||||||
|
Condition50%1/2
$conf->{"stash_checkers"} //= "plugin-check-checkers"
MC/DC0%0/1
$conf->{"stash_checkers"} //= "plugin-check-checkers"
$conf->{"stash_checkers"}
Truth table50%1/2
A
A= $conf->{"stash_checkers"}
| |||||||||||||
| 11 | 9 | ▶ | $conf->{stash_actions} //= 'plugin-check-actions'; | ||||||||||
|
Condition50%1/2
$conf->{"stash_actions"} //= "plugin-check-actions"
MC/DC0%0/1
$conf->{"stash_actions"} //= "plugin-check-actions"
$conf->{"stash_actions"}
Truth table50%1/2
A
A= $conf->{"stash_actions"}
| |||||||||||||
| 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"}} //= {}
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"}}
| |||||||||||||
| 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"}} //= []
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"}}
| |||||||||||||
| 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"}} //= {}
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"}}
| |||||||||||||
| 35 | 2 | ▶ | my $actions = $c->stash->{$conf->{stash_actions}} //= []; | ||||||||||
|
Condition50%1/2
$c->stash->{$conf->{"stash_actions"}} //= []
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"}}
| |||||||||||||
| 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
| |||||||||||||
| 42 | |||||||||||||
| 43 | 0 | my @result = $checker->( @opts ); | |||||||||||
| 44 | |||||||||||||
| 45 | 0 | ▶ | if( @result ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | 0 | ▶ | if( defined $result[0] ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | 0 | ▶ | if( $result[0] ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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__ | ||||||||||||