line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FormValidator::LazyWay::Setting; |
2
|
|
|
|
|
|
|
|
3
|
33
|
|
|
33
|
|
17291
|
use strict; |
|
33
|
|
|
|
|
68
|
|
|
33
|
|
|
|
|
1244
|
|
4
|
33
|
|
|
33
|
|
177
|
use warnings; |
|
33
|
|
|
|
|
64
|
|
|
33
|
|
|
|
|
1142
|
|
5
|
33
|
|
|
33
|
|
178
|
use Carp; |
|
33
|
|
|
|
|
57
|
|
|
33
|
|
|
|
|
2319
|
|
6
|
|
|
|
|
|
|
|
7
|
33
|
|
|
33
|
|
184
|
use base qw/Class::Accessor::Fast/; |
|
33
|
|
|
|
|
63
|
|
|
33
|
|
|
|
|
7368
|
|
8
|
33
|
|
|
33
|
|
72302
|
use UNIVERSAL::require; |
|
33
|
|
|
|
|
53270
|
|
|
33
|
|
|
|
|
349
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/alias config setting modules labels defaults/); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
132
|
|
|
132
|
1
|
94823
|
my $class = shift; |
14
|
132
|
|
|
|
|
314
|
my $args; |
15
|
132
|
50
|
|
|
|
397
|
if ( ref $_[0] eq 'HASH' ) { |
16
|
0
|
|
|
|
|
0
|
$args = shift; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
else { |
19
|
132
|
|
|
|
|
393
|
my %args = @_; |
20
|
132
|
|
|
|
|
281
|
$args = \%args; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
132
|
50
|
|
|
|
484
|
croak 'you must set config' unless exists $args->{config}; |
24
|
|
|
|
|
|
|
|
25
|
132
|
|
|
|
|
405
|
my $self = bless $args, $class; |
26
|
|
|
|
|
|
|
|
27
|
132
|
50
|
|
|
|
721
|
unless ( $self->init() ) { |
28
|
0
|
|
|
|
|
0
|
croak 'undefined init method?'; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
132
|
|
|
|
|
1495
|
$self->_load_setting(); |
32
|
|
|
|
|
|
|
|
33
|
132
|
|
|
|
|
527
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
0
|
0
|
0
|
sub init { 0; } |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub parse { |
39
|
117
|
|
|
117
|
0
|
1075
|
my $self = shift; |
40
|
117
|
|
|
|
|
172
|
my $value = shift; |
41
|
117
|
|
|
|
|
142
|
my $level = shift; |
42
|
117
|
|
|
|
|
294
|
my $field = shift; |
43
|
117
|
|
|
|
|
148
|
my $modified = 0; |
44
|
|
|
|
|
|
|
|
45
|
117
|
100
|
|
|
|
399
|
if (exists $self->{setting}{$level}{$field}) { |
46
|
101
|
|
|
|
|
120
|
for my $item ( @{$self->{setting}{$level}{$field}} ) { |
|
101
|
|
|
|
|
316
|
|
47
|
7
|
|
|
|
|
32
|
$value = $item->{method}->( $value , $item->{args} ); |
48
|
7
|
|
|
|
|
26
|
$modified =1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
16
|
|
|
|
|
25
|
for my $regexp ( keys %{ $self->{setting}{regex_map} } ) { |
|
16
|
|
|
|
|
66
|
|
53
|
21
|
50
|
|
|
|
403
|
if ( $field =~ qr/$regexp/ ) { |
54
|
21
|
|
|
|
|
27
|
for my $validator ( @{$self->{setting}{regex_map}{$regexp}} ) { |
|
21
|
|
|
|
|
109
|
|
55
|
1
|
|
|
|
|
5
|
$value = $validator->{method}->( $value, $validator->{args} ); |
56
|
1
|
|
|
|
|
6
|
$modified =1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
117
|
|
|
|
|
613
|
return ( $value, $modified ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _load_setting { |
65
|
132
|
|
|
132
|
|
229
|
my $self = shift; |
66
|
132
|
|
100
|
|
|
501
|
my $rules = $self->{config}{$self->name . ( $self->name =~ /x$/ ? 'es' : 's' ) } || []; |
67
|
|
|
|
|
|
|
|
68
|
132
|
|
100
|
|
|
2688
|
$self->{defaults} = $self->{config}{defaults} || {}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# * require modules and set alias |
71
|
132
|
|
|
|
|
335
|
my @modules = (); |
72
|
132
|
|
|
|
|
201
|
for my $rule ( @{$rules} ) { |
|
132
|
|
|
|
|
333
|
|
73
|
99
|
|
|
|
|
199
|
my $module = $rule; |
74
|
|
|
|
|
|
|
|
75
|
99
|
|
|
|
|
477
|
my @data = split( '=', $rule ); |
76
|
99
|
|
|
|
|
242
|
my $alias; |
77
|
99
|
100
|
|
|
|
776
|
if ( scalar @data == 1 ) { |
78
|
93
|
|
|
|
|
685
|
$module = $rule; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else { |
81
|
6
|
|
|
|
|
14
|
$alias = $data[0]; |
82
|
6
|
|
|
|
|
13
|
$module = $data[1]; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
99
|
100
|
|
|
|
485
|
unless ( $module =~ s/^\+// ) { |
86
|
86
|
|
|
|
|
388
|
$module = join( '::', $self->self , $module ); |
87
|
|
|
|
|
|
|
} |
88
|
99
|
100
|
|
|
|
797
|
$self->{alias}{$alias} = $module if $alias; |
89
|
|
|
|
|
|
|
|
90
|
99
|
50
|
|
|
|
1023
|
$module->require or die $@; |
91
|
99
|
|
|
|
|
3606
|
push @modules, $module; |
92
|
|
|
|
|
|
|
} |
93
|
132
|
|
|
|
|
365
|
$self->{modules} = \@modules; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# * make setting |
96
|
132
|
|
|
|
|
203
|
foreach my $key ( keys %{ $self->config->{setting} } ) { |
|
132
|
|
|
|
|
42010
|
|
97
|
147
|
|
|
|
|
1759
|
$self->{setting}{$key} = $self->_make_setting($key); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _make_setting { |
102
|
147
|
|
|
147
|
|
236
|
my $self = shift; |
103
|
147
|
|
|
|
|
258
|
my $type = shift; |
104
|
147
|
|
|
|
|
783
|
my $alias = $self->alias; |
105
|
147
|
|
|
|
|
745
|
my $setting = {}; |
106
|
147
|
|
|
|
|
420
|
my $config = $self->config; |
107
|
|
|
|
|
|
|
|
108
|
147
|
|
|
|
|
624
|
foreach my $field ( sort keys %{ $config->{setting}{$type} } ) { |
|
147
|
|
|
|
|
875
|
|
109
|
254
|
|
100
|
|
|
1215
|
my $validations = $config->{setting}{$type}{$field}{ $self->name } || []; |
110
|
254
|
|
|
|
|
2227
|
$setting->{$field} = []; |
111
|
|
|
|
|
|
|
|
112
|
254
|
|
|
|
|
358
|
for my $validation ( @{$validations} ) { |
|
254
|
|
|
|
|
826
|
|
113
|
|
|
|
|
|
|
|
114
|
125
|
|
|
|
|
185
|
my $label; |
115
|
125
|
|
|
|
|
208
|
my $args = {}; |
116
|
125
|
100
|
|
|
|
385
|
if ( ref $validation eq 'HASH' ) { |
117
|
42
|
|
|
|
|
77
|
($label) = keys %{$validation}; |
|
42
|
|
|
|
|
153
|
|
118
|
42
|
|
|
|
|
134
|
$args = $validation->{$label}; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else { |
121
|
83
|
|
|
|
|
169
|
$label = $validation; |
122
|
|
|
|
|
|
|
} |
123
|
125
|
50
|
|
|
|
401
|
$label = $label ? $label : ''; |
124
|
|
|
|
|
|
|
|
125
|
125
|
|
|
|
|
631
|
my $package = substr( $label , 0 , rindex( $label, '#' ) ); |
126
|
125
|
|
|
|
|
419
|
my $method = substr( $label, rindex( $label, '#' ) + 1 ); |
127
|
|
|
|
|
|
|
|
128
|
125
|
|
|
|
|
186
|
my $alias_name = undef; |
129
|
125
|
100
|
|
|
|
359
|
if ( $alias->{$package} ) { |
130
|
10
|
|
|
|
|
25
|
$alias_name = $package . '#' . $method; |
131
|
10
|
|
|
|
|
22
|
$package = $alias->{$package}; |
132
|
10
|
|
|
|
|
36
|
my $re = '^' . $self->self . '::(.+)'; |
133
|
10
|
|
|
|
|
172
|
($label) = $package =~ m/$re/; |
134
|
10
|
100
|
|
|
|
40
|
$label = '+' . $package unless $label; |
135
|
10
|
|
|
|
|
34
|
$label = $label . '#' . $method; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
else { |
138
|
115
|
100
|
|
|
|
353
|
if ( $package =~ m/^\+/ ) { |
139
|
4
|
|
|
|
|
23
|
$package =~ s/\++//g; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
else { |
142
|
111
|
|
|
|
|
385
|
$package = $self->self . '::' . $package; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
125
|
|
|
|
|
830
|
$package =~ s/#.+//g; |
147
|
125
|
|
|
|
|
754
|
$self->{labels}{$label} = { |
148
|
|
|
|
|
|
|
package => $package, |
149
|
|
|
|
|
|
|
method => $method, |
150
|
|
|
|
|
|
|
alias => $alias_name |
151
|
|
|
|
|
|
|
}; |
152
|
|
|
|
|
|
|
|
153
|
125
|
|
|
|
|
350
|
my $sub = $package . '::' . $method; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
my $method_ref = sub { |
156
|
94
|
|
|
94
|
|
363
|
my $item = shift; |
157
|
94
|
|
|
|
|
111
|
my $stash = shift; |
158
|
|
|
|
|
|
|
|
159
|
33
|
|
|
33
|
|
43692
|
no strict; |
|
33
|
|
|
|
|
78
|
|
|
33
|
|
|
|
|
5488
|
|
160
|
94
|
|
|
|
|
1078
|
my $result = $sub->( $item, $args, $stash ); |
161
|
94
|
|
|
|
|
21174
|
return $result; |
162
|
125
|
|
|
|
|
644
|
}; |
163
|
125
|
|
|
|
|
994
|
push( |
164
|
125
|
|
|
|
|
205
|
@{ $setting->{$field} }, |
165
|
|
|
|
|
|
|
{ label => $label, method => $method_ref, args => $args } |
166
|
|
|
|
|
|
|
); |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
147
|
|
|
|
|
891
|
return $setting; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 NAME |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
FormValidator::LazyWay::Rule - FormValidator::LazyWay Validation Rule module. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 DESCRIPTION |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
検証モジュールを読み込み、検証ルールハッシュを作成します。 |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 METHODS |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 new |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 alias |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 args |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 setting |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 AUTHOR |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Tomohiro Teranishi |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |