line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Check; |
2
|
9
|
|
|
9
|
|
118322
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
9
|
|
|
|
|
31
|
|
|
9
|
|
|
|
|
72
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub register { |
7
|
9
|
|
|
9
|
1
|
428
|
my ($self, $app, $conf) = @_; |
8
|
|
|
|
|
|
|
|
9
|
9
|
|
50
|
|
|
44
|
$conf ||= {}; |
10
|
9
|
|
50
|
|
|
75
|
$conf->{stash_checkers} //= 'plugin-check-checkers'; |
11
|
9
|
|
50
|
|
|
48
|
$conf->{stash_actions} //= 'plugin-check-actions'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$app->helper(add_checker => sub { |
14
|
11
|
|
|
11
|
|
2217
|
my ($c, $name, $sub) = @_; |
15
|
|
|
|
|
|
|
|
16
|
11
|
|
100
|
|
|
60
|
my $checkers = $c->app->routes->{$conf->{stash_checkers}} //= {}; |
17
|
11
|
|
|
|
|
185
|
$checkers->{$name} = $sub; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$c->app->routes->add_condition($name => sub { |
20
|
27
|
|
|
|
|
421128
|
my ($route, $c, $captures, $pattern) = @_; |
21
|
|
|
|
|
|
|
|
22
|
27
|
|
100
|
|
|
140
|
my $actions = $c->stash->{$conf->{stash_actions}} //= []; |
23
|
27
|
|
|
|
|
673
|
push @$actions, [$name, $route, $c, {%$captures}, $pattern]; |
24
|
|
|
|
|
|
|
|
25
|
27
|
|
|
|
|
112
|
return 1; |
26
|
11
|
|
|
|
|
41
|
}); |
27
|
|
|
|
|
|
|
|
28
|
11
|
|
|
|
|
255
|
return $self; |
29
|
9
|
|
|
|
|
81
|
}); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$app->hook(around_action => sub { |
32
|
19
|
|
|
19
|
|
27204
|
my ($next, $c, $action, $last) = @_; |
33
|
|
|
|
|
|
|
|
34
|
19
|
|
50
|
|
|
106
|
my $checkers = $c->app->routes->{$conf->{stash_checkers}} //= {}; |
35
|
19
|
|
100
|
|
|
325
|
my $actions = $c->stash->{$conf->{stash_actions}} //= []; |
36
|
|
|
|
|
|
|
|
37
|
19
|
|
|
|
|
323
|
for my $args ( @$actions ) { |
38
|
24
|
|
|
|
|
110
|
my $name = shift @$args; |
39
|
|
|
|
|
|
|
|
40
|
24
|
|
|
|
|
77
|
my $checker = $checkers->{ $name }; |
41
|
24
|
50
|
|
|
|
90
|
next unless $checker; |
42
|
|
|
|
|
|
|
|
43
|
24
|
|
|
|
|
135
|
my @result = $checker->( @$args ); |
44
|
|
|
|
|
|
|
|
45
|
24
|
50
|
|
|
|
92386
|
if( @result ) { |
46
|
24
|
100
|
|
|
|
83
|
if( defined $result[0] ) { |
47
|
23
|
100
|
|
|
|
70
|
if( $result[0] ) { |
48
|
17
|
|
|
|
|
70
|
next; |
49
|
|
|
|
|
|
|
} else { |
50
|
6
|
|
|
|
|
104
|
return $c->reply->not_found; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} else { |
53
|
1
|
|
|
|
|
20
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} else { |
56
|
0
|
|
|
|
|
0
|
return $c->reply->not_found; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
12
|
|
|
|
|
51
|
return $next->(); |
61
|
9
|
|
|
|
|
289
|
}); |
62
|
|
|
|
|
|
|
|
63
|
9
|
|
|
|
|
153
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |