line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::RuledValidator::Filter; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
31
|
use strict; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
336
|
|
4
|
6
|
|
|
6
|
|
32
|
use warnings qw/all/; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
192
|
|
5
|
6
|
|
|
6
|
|
30
|
use Data::RuledValidator::Util; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
2722
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 0.02; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub trim{ |
10
|
108
|
|
|
108
|
1
|
177
|
my($self, $v) = @_; |
11
|
108
|
50
|
|
|
|
325
|
if(defined $$v){ |
12
|
108
|
|
|
|
|
342
|
$$v =~ s/^\s*//o; |
13
|
108
|
|
|
|
|
771
|
$$v =~ s/\s*$//o; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub no_dash{ |
18
|
4
|
|
|
4
|
1
|
8
|
my($self, $v) = @_; |
19
|
4
|
|
|
|
|
30
|
$$v =~ s/\-//go; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub lc{ |
23
|
0
|
|
|
0
|
1
|
0
|
my($self, $v) = @_; |
24
|
0
|
|
|
|
|
0
|
$$v = lc($$v); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub uc{ |
28
|
1
|
|
|
1
|
1
|
4
|
my($self, $v) = @_; |
29
|
1
|
|
|
|
|
7
|
$$v = uc($$v); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub no_filter{ |
33
|
2
|
|
|
2
|
1
|
5
|
my($self, $v) = @_; |
34
|
2
|
|
|
|
|
11
|
return $$v; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 Name |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Data::RuledValidator::Filter - filters |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 lc |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
It makes values lower character. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
'Character' |
48
|
|
|
|
|
|
|
-> 'character' |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 uc |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
It makes values upper character. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
'Character' |
55
|
|
|
|
|
|
|
-> 'CHARACTER' |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 trim |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
It remove white space in front and back. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
' hoge ' |
62
|
|
|
|
|
|
|
-> 'hoge' |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 no_dash |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
It remove dash included in values. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
'000-000-000' |
69
|
|
|
|
|
|
|
-> '000000000' |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 no_filter |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
It does nothing. |
74
|
|
|
|
|
|
|
return given value as is. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
'000-000-000' |
77
|
|
|
|
|
|
|
-> '000-000-000' |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 How to create Filter? |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
package Data::RuledValidator::Filter::XXX; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub filter_xxx{ |
84
|
|
|
|
|
|
|
my($self, $v, $drv, $values) = @_; |
85
|
|
|
|
|
|
|
# do something |
86
|
|
|
|
|
|
|
return $$v; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$drv is Data::RuledValidator object. |
92
|
|
|
|
|
|
|
So, you can write like as following filter. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
package Data::RuledValidator::Filter; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub birth_year_check{ |
97
|
|
|
|
|
|
|
my($self, $v, $drv, $values) = @_; |
98
|
|
|
|
|
|
|
my($q, $method) = ($drv->obj, $drv->method); |
99
|
|
|
|
|
|
|
my($year) = $q->$method('birth_year'); |
100
|
|
|
|
|
|
|
my $r = $q->$method(birth_year_is_1777 => $year == 1777); |
101
|
|
|
|
|
|
|
return $$v = $r; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
And write the following rule. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
birth_year_is_1777 eq 1 with birth_year_check |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 Author |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Ktat, Ektat@cpan.orgE |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 Copyright |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Copyright 2006-2007 by Ktat |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This program is free software; you can redistribute it |
117
|
|
|
|
|
|
|
and/or modify it under the same terms as Perl itself. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
See http://www.perl.com/perl/misc/Artistic.html |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |