| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ABSTRACT: Centralized Input Validation For Dancer |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Dancer::Plugin::ValidationClass; |
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
433551
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
63
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
59
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
2115
|
use Dancer ':syntax'; |
|
|
2
|
|
|
|
|
406746
|
|
|
|
2
|
|
|
|
|
11
|
|
|
9
|
2
|
|
|
2
|
|
2498
|
use Dancer::Plugin; |
|
|
2
|
|
|
|
|
2985
|
|
|
|
2
|
|
|
|
|
815
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.120490'; # VERSION |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $Self; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# instance should only remained cached for the duration of the request |
|
17
|
|
|
|
|
|
|
hook before => sub { |
|
18
|
|
|
|
|
|
|
$Dancer::Plugin::ValidationClass::Self = undef; |
|
19
|
|
|
|
|
|
|
}; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# register the keyword |
|
22
|
|
|
|
|
|
|
register rules => sub { |
|
23
|
0
|
|
|
0
|
|
|
my @args = @_; |
|
24
|
0
|
|
0
|
|
|
|
my $cfg = plugin_setting || {}; |
|
25
|
|
|
|
|
|
|
|
|
26
|
0
|
0
|
0
|
|
|
|
$Self = ref $Self ? $Self : instantiate( $cfg || {}, @args ); |
|
27
|
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
return $Self; |
|
29
|
|
|
|
|
|
|
}; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# instantiation routine |
|
32
|
|
|
|
|
|
|
sub instantiate { |
|
33
|
0
|
|
|
0
|
0
|
|
my ( $cfg, @args ) = @_; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#find validation class |
|
36
|
0
|
|
|
|
|
|
my $class = my $path = $cfg->{class}; |
|
37
|
0
|
|
0
|
|
|
|
$class ||= setting('appname') . '::Validation'; |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
if ( $class =~ /::/ ) { |
|
|
|
0
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$path = "$class.pm"; |
|
41
|
0
|
|
|
|
|
|
$path =~ s/::/\//g; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
elsif ( $class =~ /\.pm$/ ) { |
|
44
|
0
|
|
|
|
|
|
$path = $class; |
|
45
|
0
|
|
|
|
|
|
$class =~ s/\.pm$//; |
|
46
|
0
|
|
|
|
|
|
$class =~ s/\//::/; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
{ |
|
50
|
2
|
|
|
2
|
|
14
|
no warnings 'redefine'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
295
|
|
|
|
0
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
require $path unless defined $Self; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $args = {@args}; # specified params supersedes frameworks |
|
55
|
0
|
|
0
|
|
|
|
$args->{params} ||= { params() }; |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return $class->new(%{ $args }); |
|
|
0
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
register_plugin; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |