line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FormValidator::LazyWay::Rule::String; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
326346
|
use strict; |
|
18
|
|
|
|
|
39
|
|
|
18
|
|
|
|
|
627
|
|
4
|
18
|
|
|
18
|
|
94
|
use warnings; |
|
18
|
|
|
|
|
33
|
|
|
18
|
|
|
|
|
480
|
|
5
|
18
|
|
|
18
|
|
3435
|
use utf8; |
|
18
|
|
|
|
|
60
|
|
|
18
|
|
|
|
|
119
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub length { |
8
|
34
|
|
|
34
|
1
|
20935
|
my $text = shift; |
9
|
34
|
|
|
|
|
221
|
my $args = shift; |
10
|
|
|
|
|
|
|
|
11
|
34
|
50
|
|
|
|
109
|
die 'you must set max argument' unless exists $args->{max}; |
12
|
34
|
50
|
|
|
|
255
|
die 'you must set min argument' unless exists $args->{min}; |
13
|
|
|
|
|
|
|
|
14
|
34
|
100
|
100
|
|
|
762
|
return ( length $text > $args->{max} or length $text < $args->{min} ) ? 0 : 1; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub stash_test { |
18
|
2
|
|
|
2
|
1
|
4
|
my ( $text, $args, $stash ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# # for debug |
21
|
|
|
|
|
|
|
# use Data::Dumper; |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# warn $text; |
24
|
|
|
|
|
|
|
# warn Dumper $args; |
25
|
|
|
|
|
|
|
# warn Dumper $stash; |
26
|
|
|
|
|
|
|
|
27
|
2
|
50
|
|
|
|
7
|
return $stash ? 1 : 0; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub ascii { |
31
|
25
|
|
|
25
|
1
|
43152
|
my $text = shift; |
32
|
25
|
100
|
|
|
|
327
|
return $text =~ /^[\x20-\x7E]+$/ ? 1 : 0; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub nonsymbol_ascii { |
36
|
7
|
|
|
7
|
1
|
19789
|
my ($text, $args) = @_; |
37
|
|
|
|
|
|
|
|
38
|
7
|
100
|
|
|
|
29
|
if ( ref $args->{allow} eq 'ARRAY' ) { |
39
|
2
|
|
|
|
|
3
|
foreach my $allow ( @{$args->{allow}} ) { |
|
2
|
|
|
|
|
6
|
|
40
|
2
|
|
|
|
|
32
|
$text =~ s{$allow}{}xmsg; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
7
|
100
|
|
|
|
42
|
return $text =~ /^[a-zA-Z0-9]+$/ ? 1 : 0; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub alphabet { |
48
|
5
|
|
|
5
|
1
|
23802
|
my $text = shift; |
49
|
5
|
100
|
|
|
|
31
|
return $text =~ /^[a-zA-Z]+$/ ? 1 : 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub number { |
53
|
6
|
|
|
6
|
1
|
19082
|
my $text = shift; |
54
|
6
|
100
|
|
|
|
46
|
return $text =~ /^[0-9]+$/ ? 1 : 0; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 NAME |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
FormValidator::LazyWay::Rule::String - String Rule |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 METHOD |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 length |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 stash_test |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 ascii |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 nonsymbol_ascii |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
only alphabets and numbers. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
you add $args->{allow} if you accept symbols. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
username: |
78
|
|
|
|
|
|
|
rule: |
79
|
|
|
|
|
|
|
- String#nonsimbol_ascii: |
80
|
|
|
|
|
|
|
args: |
81
|
|
|
|
|
|
|
allow: |
82
|
|
|
|
|
|
|
- '_' |
83
|
|
|
|
|
|
|
- '-' |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 alphabet |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 number |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|