|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
  
 
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Mojolicious::Plugin::Check;  | 
| 
2
 | 
9
 | 
 
 | 
 
 | 
  
9
  
 | 
 
 | 
125494
 | 
 use Mojo::Base 'Mojolicious::Plugin';  | 
| 
 
 | 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
26
 | 
    | 
| 
 
 | 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
60
 | 
    | 
| 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION        = '0.03';  | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub register {  | 
| 
7
 | 
9
 | 
 
 | 
 
 | 
  
9
  
 | 
  
1
  
 | 
447
 | 
     my ($self, $app, $conf) = @_;  | 
| 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
9
 | 
9
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
48
 | 
     $conf                   ||= {};  | 
| 
10
 | 
9
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
79
 | 
     $conf->{stash_checkers} //= 'plugin-check-checkers';  | 
| 
11
 | 
9
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
59
 | 
     $conf->{stash_actions}  //= 'plugin-check-actions';  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $app->helper(add_checker => sub {  | 
| 
14
 | 
11
 | 
 
 | 
 
 | 
  
11
  
 | 
 
 | 
2298
 | 
         my ($c, $name, $sub) = @_;  | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
16
 | 
11
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
82
 | 
         my $checkers = $c->app->routes->{$conf->{stash_checkers}} //= {};  | 
| 
17
 | 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
180
 | 
         $checkers->{$name} = $sub;  | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         $c->app->routes->add_condition($name => sub {  | 
| 
20
 | 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
329930
 | 
             my ($route, $c, $captures, $pattern) = @_;  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
22
 | 
27
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
125
 | 
             my $actions = $c->stash->{$conf->{stash_actions}} //= [];  | 
| 
23
 | 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
551
 | 
             push @$actions, [$name, $route, $c, {%$captures}, $pattern];  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
25
 | 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
85
 | 
             return 1;  | 
| 
26
 | 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
34
 | 
         });  | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
28
 | 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
273
 | 
         return $self;  | 
| 
29
 | 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
80
 | 
     });  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $app->hook(around_action => sub {  | 
| 
32
 | 
19
 | 
 
 | 
 
 | 
  
19
  
 | 
 
 | 
23710
 | 
         my ($next, $c, $action, $last) = @_;  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
34
 | 
19
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
76
 | 
         my $checkers    = $c->app->routes->{$conf->{stash_checkers}}    //= {};  | 
| 
35
 | 
19
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
268
 | 
         my $actions      = $c->stash->{$conf->{stash_actions}}          //= [];  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
37
 | 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
255
 | 
         for my $args ( @$actions ) {  | 
| 
38
 | 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
85
 | 
             my ($name, @opts) = @$args;  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
40
 | 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
63
 | 
             my $checker = $checkers->{ $name };  | 
| 
41
 | 
24
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
124
 | 
             next unless $checker;  | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
43
 | 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
117
 | 
             my @result = $checker->( @opts );  | 
| 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
45
 | 
24
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
83809
 | 
             if( @result ) {  | 
| 
46
 | 
24
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
71
 | 
                 if( defined $result[0] ) {  | 
| 
47
 | 
23
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
51
 | 
                     if( $result[0] ) {  | 
| 
48
 | 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
61
 | 
                         next;  | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     } else {  | 
| 
50
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
90
 | 
                         return $c->reply->not_found;  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     }  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 } else {  | 
| 
53
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16
 | 
                     return;  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 }  | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             } else {  | 
| 
56
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                 return $c->reply->not_found;  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
58
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
59
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
60
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
57
 | 
         return $next->();  | 
| 
61
 | 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
293
 | 
     });  | 
| 
62
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
63
 | 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
151
 | 
     return;  | 
| 
64
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
65
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
66
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
67
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |