line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::RuledValidator::Util; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
31
|
use strict; |
|
6
|
|
|
|
|
1319
|
|
|
6
|
|
|
|
|
241
|
|
4
|
6
|
|
|
6
|
|
33
|
use warnings qw/all/; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
1874
|
|
5
|
6
|
|
|
6
|
|
31
|
use base qw/Exporter/; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
4461
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw(NEED_ALIAS ALLOW_NO_VALUE RKEYS _arg _vand _vor); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = 0.02; |
10
|
|
|
|
|
|
|
|
11
|
123
|
|
|
123
|
0
|
477
|
sub NEED_ALIAS { 1 } |
12
|
333
|
|
|
333
|
0
|
2098
|
sub ALLOW_NO_VALUE { 2 } |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# '&' validation for multiple values |
15
|
|
|
|
|
|
|
sub _vand{ |
16
|
181
|
|
|
181
|
|
369
|
my ($self, $key, $c, $val, $sub) = @_; |
17
|
181
|
|
|
|
|
232
|
my $ok = 1; |
18
|
181
|
|
|
|
|
299
|
foreach my $v (@$val){ |
19
|
222
|
|
|
|
|
269
|
my $_ok = 1; |
20
|
222
|
100
|
|
|
|
683
|
if($_ok = $sub->($self, $v) ? 1 : 0){ |
|
|
100
|
|
|
|
|
|
21
|
207
|
|
100
|
|
|
7885
|
push @{$self->{right}->{"${key}_$c"} ||= []}, $v; |
|
207
|
|
|
|
|
1621
|
|
22
|
|
|
|
|
|
|
}else{ |
23
|
15
|
|
50
|
|
|
514
|
push @{$self->{wrong}->{"${key}_$c"} ||= []}, $v; |
|
15
|
|
|
|
|
139
|
|
24
|
|
|
|
|
|
|
} |
25
|
222
|
|
|
|
|
625
|
$ok &= $_ok; |
26
|
|
|
|
|
|
|
} |
27
|
181
|
|
|
|
|
738
|
return $ok; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# '|' validation for multiple values |
31
|
|
|
|
|
|
|
sub _vor{ |
32
|
35
|
|
|
35
|
|
71
|
my ($self, $key, $c, $val, $sub) = @_; |
33
|
35
|
|
|
|
|
49
|
my $ok = 0; |
34
|
35
|
|
|
|
|
98
|
foreach my $v (@$val){ |
35
|
56
|
|
|
|
|
79
|
my $_ok = 0; |
36
|
56
|
100
|
|
|
|
157
|
if($_ok = $sub->($self, $v) ? 1 : 0){ |
|
|
100
|
|
|
|
|
|
37
|
34
|
|
100
|
|
|
37
|
push @{$self->{right}->{"${key}_$c"} ||= []}, $v; |
|
34
|
|
|
|
|
227
|
|
38
|
|
|
|
|
|
|
}else{ |
39
|
22
|
|
100
|
|
|
32
|
push @{$self->{wrong}->{"${key}_$c"} ||= []}, $v; |
|
22
|
|
|
|
|
133
|
|
40
|
|
|
|
|
|
|
} |
41
|
56
|
|
|
|
|
131
|
$ok |= $_ok; |
42
|
|
|
|
|
|
|
} |
43
|
35
|
|
|
|
|
137
|
return $ok; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _arg{# to escape quote, use \ |
47
|
18
|
50
|
|
18
|
|
50
|
shift if $_[0] eq __PACKAGE__; |
48
|
|
|
|
|
|
|
# it is refer to Perl memo() |
49
|
|
|
|
|
|
|
# http://www.din.or.jp/~ohzaki/perl.htm#CSV2Values |
50
|
18
|
|
|
|
|
28
|
my($arg) = @_; |
51
|
18
|
|
|
|
|
22
|
my @arg; |
52
|
18
|
|
|
|
|
113
|
$arg =~ s/(?:\x0D\x0A|[\x0D\x0A])?$/,/; |
53
|
18
|
50
|
|
|
|
47
|
return \@arg if $arg eq ','; |
54
|
18
|
|
|
|
|
42
|
while($arg){ |
55
|
54
|
50
|
|
|
|
312
|
if($arg =~ s/^\s*('[^']*(?:\\'[^']*)*')\s*,//){ |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# value quoted with "" |
57
|
0
|
|
|
|
|
0
|
$_ = $1; |
58
|
0
|
|
|
|
|
0
|
push @arg, scalar(s/^\s*'(.*)'\s*$/$1/, s/\\'/'/g, $_) |
59
|
|
|
|
|
|
|
}elsif($arg =~ s/^\s*("[^"]*(?:\\"[^"]*)*")\s*,//){ |
60
|
|
|
|
|
|
|
# value quoted with '' |
61
|
7
|
|
|
|
|
14
|
$_ = $1; |
62
|
7
|
|
|
|
|
33
|
push @arg, scalar(s/^\s*"(.*)"\s*$/$1/, s/\\"/"/g, $_) |
63
|
|
|
|
|
|
|
}elsif($arg =~s/^([^,]+),//){ |
64
|
47
|
|
|
|
|
91
|
$_ = $1; |
65
|
47
|
|
|
|
|
213
|
s/\s*$//g; |
66
|
47
|
50
|
|
|
|
296
|
push @arg, $_ unless $_ eq ''; |
67
|
|
|
|
|
|
|
}else{ |
68
|
0
|
|
|
|
|
0
|
warn $arg; |
69
|
|
|
|
|
|
|
} |
70
|
54
|
|
|
|
|
238
|
$arg =~s/^[,\s]*//; |
71
|
|
|
|
|
|
|
} |
72
|
18
|
|
|
|
|
360
|
return @arg; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 Name |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Data::RuledValidator::Util - utilitie functions to be used Data::RuledValidator* |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 Description |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 Synopsys |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 Author |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Ktat, Ektat@cpan.orgE |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 Copyright |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Copyright 2006-2007 by Ktat |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This program is free software; you can redistribute it |
94
|
|
|
|
|
|
|
and/or modify it under the same terms as Perl itself. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
See http://www.perl.com/perl/misc/Artistic.html |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |