line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Check; |
2
|
6
|
|
|
6
|
|
76230
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
40
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub register { |
7
|
6
|
|
|
6
|
1
|
254
|
my ($self, $app, $conf) = @_; |
8
|
|
|
|
|
|
|
|
9
|
6
|
|
50
|
|
|
32
|
$conf ||= {}; |
10
|
6
|
|
50
|
|
|
57
|
$conf->{stash_checkers} //= 'plugin-check-checkers'; |
11
|
6
|
|
50
|
|
|
38
|
$conf->{stash_actions} //= 'plugin-check-actions'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$app->helper(add_checker => sub { |
14
|
6
|
|
|
6
|
|
1364
|
my ($c, $name, $sub) = @_; |
15
|
|
|
|
|
|
|
|
16
|
6
|
|
50
|
|
|
34
|
my $checkers = $c->app->routes->{$conf->{stash_checkers}} //= {}; |
17
|
6
|
|
|
|
|
100
|
$checkers->{$name} = $sub; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$c->app->routes->add_condition($name => sub { |
20
|
14
|
|
|
|
|
146914
|
my ($route, $c, $captures, $pattern) = @_; |
21
|
|
|
|
|
|
|
|
22
|
14
|
|
100
|
|
|
63
|
my $actions = $c->stash->{$conf->{stash_actions}} //= []; |
23
|
14
|
|
|
|
|
381
|
push @$actions, [$name, $route, $c, {%$captures}, $pattern]; |
24
|
|
|
|
|
|
|
|
25
|
14
|
|
|
|
|
48
|
return 1; |
26
|
6
|
|
|
|
|
21
|
}); |
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
|
|
155
|
return $self; |
29
|
6
|
|
|
|
|
53
|
}); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$app->hook(around_action => sub { |
32
|
12
|
|
|
12
|
|
2953
|
my ($next, $c, $action, $last) = @_; |
33
|
|
|
|
|
|
|
|
34
|
12
|
50
|
|
|
|
52
|
return $next->() unless $last; |
35
|
|
|
|
|
|
|
|
36
|
12
|
|
50
|
|
|
51
|
my $checkers = $c->app->routes->{$conf->{stash_checkers}} //= {}; |
37
|
12
|
|
50
|
|
|
170
|
my $actions = $c->stash->{$conf->{stash_actions}} //= []; |
38
|
|
|
|
|
|
|
|
39
|
12
|
|
|
|
|
156
|
for my $args ( @$actions ) { |
40
|
14
|
|
|
|
|
41
|
my $name = shift @$args; |
41
|
|
|
|
|
|
|
|
42
|
14
|
|
|
|
|
41
|
my $checker = $checkers->{ $name }; |
43
|
14
|
50
|
|
|
|
59
|
next unless $checker; |
44
|
|
|
|
|
|
|
|
45
|
14
|
|
|
|
|
64
|
my @result = $checker->( @$args ); |
46
|
|
|
|
|
|
|
|
47
|
14
|
50
|
|
|
|
85354
|
if( @result ) { |
48
|
14
|
100
|
|
|
|
70
|
if( defined $result[0] ) { |
49
|
13
|
100
|
|
|
|
39
|
if( $result[0] ) { |
50
|
10
|
|
|
|
|
35
|
next; |
51
|
|
|
|
|
|
|
} else { |
52
|
3
|
|
|
|
|
43
|
return $c->reply->not_found; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} else { |
55
|
1
|
|
|
|
|
18
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} else { |
58
|
0
|
|
|
|
|
0
|
return $c->reply->not_found; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
8
|
|
|
|
|
33
|
return $next->(); |
63
|
6
|
|
|
|
|
193
|
}); |
64
|
|
|
|
|
|
|
|
65
|
6
|
|
|
|
|
88
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |