line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package String::Validator::Common; |
2
|
|
|
|
|
|
|
$String::Validator::Common::VERSION = '2.04'; # TRIAL |
3
|
|
|
|
|
|
|
# ABSTRACT: Base Module for creating new String::Validator Modules. |
4
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
586695
|
use 5.008; |
|
8
|
|
|
|
|
101
|
|
6
|
8
|
|
|
8
|
|
45
|
use strict; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
155
|
|
7
|
8
|
|
|
8
|
|
40
|
use warnings; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
220
|
|
8
|
8
|
|
|
8
|
|
68
|
no warnings 'uninitialized'; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
272
|
|
9
|
8
|
|
|
8
|
|
3273
|
use Data::Printer; |
|
8
|
|
|
|
|
185756
|
|
|
8
|
|
|
|
|
59
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $common_messages = { |
12
|
|
|
|
|
|
|
common_strings_not_match => "Strings don\'t match.", |
13
|
|
|
|
|
|
|
common_tooshort => "Does not meet requirement: Min Length ", |
14
|
|
|
|
|
|
|
common_toolong => " Does not meet requirement: Max Length ", |
15
|
|
|
|
|
|
|
}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _Messages { |
18
|
9
|
|
|
9
|
|
21
|
my $messages = {} ; |
19
|
9
|
|
|
|
|
31
|
for my $msg ( $common_messages, @_) { |
20
|
27
|
|
|
|
|
73
|
for my $c ( keys %{$msg} ) { |
|
27
|
|
|
|
|
115
|
|
21
|
34
|
|
|
|
|
89
|
$messages->{$c} = $msg->{$c}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
9
|
|
|
|
|
26
|
return $messages; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
28
|
9
|
|
|
9
|
1
|
4412
|
my $class = shift; |
29
|
9
|
|
|
|
|
34
|
my $self = {@_}; |
30
|
9
|
|
|
|
|
25
|
bless $self, $class; |
31
|
9
|
|
|
|
|
47
|
$self->{class} = $class; |
32
|
|
|
|
|
|
|
$self->{messages} |
33
|
9
|
|
|
|
|
52
|
= _Messages( $self->{language}, $self->{custom_messages} ); |
34
|
9
|
|
|
|
|
46
|
$self->_Init(); |
35
|
9
|
|
|
|
|
296
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub IncreaseErr { |
39
|
12
|
|
|
12
|
1
|
25
|
my $self = shift; |
40
|
12
|
|
|
|
|
46
|
$self->{errstring} .= "@_\n"; |
41
|
12
|
|
|
|
|
28
|
$self->{error}++; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Every time we get a new request |
45
|
|
|
|
|
|
|
# these values need to be reset from the |
46
|
|
|
|
|
|
|
# previous request. |
47
|
|
|
|
|
|
|
sub _Init { |
48
|
33
|
|
|
33
|
|
58
|
my $self = shift; |
49
|
33
|
|
|
|
|
66
|
$self->{errstring} = ''; |
50
|
33
|
|
|
|
|
64
|
$self->{error} = 0; |
51
|
33
|
|
|
|
|
68
|
$self->{string} = ''; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub Start { |
55
|
24
|
|
|
24
|
1
|
425
|
my ( $self, $string1, $string2 ) = @_; |
56
|
24
|
|
|
|
|
73
|
$self->_Init(); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# String comparison, must not fail if no string2 is provided. |
59
|
|
|
|
|
|
|
# string2 is also available for destructive operations. |
60
|
|
|
|
|
|
|
# Failing the string match alse necessitates immediate |
61
|
|
|
|
|
|
|
# error return as the other tests are meaningless as |
62
|
|
|
|
|
|
|
# we cannot know if either or neither string is the password. |
63
|
8
|
|
|
8
|
|
6178
|
no warnings 'uninitialized'; |
|
8
|
|
|
|
|
29
|
|
|
8
|
|
|
|
|
5082
|
|
64
|
24
|
100
|
|
|
|
101
|
if ( 0 == length $string2 ) { } |
|
|
100
|
|
|
|
|
|
65
|
|
|
|
|
|
|
elsif ( $string1 ne $string2 ) { |
66
|
6
|
|
|
|
|
26
|
$self->IncreaseErr( $self->{messages}{common_strings_not_match} ); |
67
|
6
|
|
|
|
|
25
|
return 99; |
68
|
|
|
|
|
|
|
} |
69
|
18
|
|
|
|
|
36
|
$self->{string} = $string1; |
70
|
18
|
|
|
|
|
55
|
return 0; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub Length { |
74
|
13
|
|
|
13
|
1
|
25
|
my $self = shift; |
75
|
13
|
|
|
|
|
21
|
my $string = $self->{string}; |
76
|
13
|
|
|
|
|
24
|
my $strlen = length( $self->{string} ); |
77
|
13
|
100
|
|
|
|
34
|
if ( $strlen < $self->{min_len} ) { |
78
|
|
|
|
|
|
|
$self->IncreaseErr( |
79
|
3
|
|
|
|
|
14
|
$self->{messages}{common_tooshort} . $self->{min_len} ); |
80
|
3
|
|
|
|
|
21
|
return $self->{error}; |
81
|
|
|
|
|
|
|
} |
82
|
10
|
100
|
|
|
|
23
|
if ( $self->{max_len} ) { |
83
|
8
|
100
|
|
|
|
23
|
if ( $strlen > $self->{max_len} ) { |
84
|
|
|
|
|
|
|
$self->IncreaseErr( |
85
|
3
|
|
|
|
|
13
|
$self->{messages}{common_toolong} . $self->{max_len} ); |
86
|
3
|
|
|
|
|
9
|
return $self->{error}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
7
|
|
|
|
|
17
|
return 0; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub CheckCommon { |
93
|
13
|
|
|
13
|
1
|
38
|
my ( $self, $string1, $string2 ) = @_; |
94
|
13
|
100
|
|
|
|
36
|
if ( $self->Start( $string1, $string2 ) ) { |
95
|
1
|
|
|
|
|
5
|
return $self->{error}; |
96
|
|
|
|
|
|
|
} |
97
|
12
|
100
|
|
|
|
26
|
if ( $self->Length ) { return $self->{error} } |
|
5
|
|
|
|
|
26
|
|
98
|
7
|
|
|
|
|
28
|
return 0; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Check serves as example, but more importantly lets |
102
|
|
|
|
|
|
|
# us test the module. |
103
|
|
|
|
|
|
|
# Takes 2 strings and runs Start. |
104
|
|
|
|
|
|
|
# If the strings match it returns 0, else 1. |
105
|
|
|
|
|
|
|
sub Check { |
106
|
7
|
|
|
7
|
1
|
19
|
my ( $self, $string1, $string2 ) = @_; |
107
|
7
|
|
|
|
|
21
|
my $started = $self->Start( $string1, $string2 ); |
108
|
7
|
|
|
|
|
23
|
return $self->{error}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub Errcnt { |
112
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
113
|
2
|
|
|
|
|
7
|
return $self->{error}; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub Errstr { |
117
|
6
|
|
|
6
|
1
|
13
|
my $self = shift; |
118
|
6
|
|
|
|
|
44
|
return $self->{errstring}; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub IsNot_Valid { |
122
|
3
|
|
|
3
|
1
|
11
|
( my $self, my $string1, my $string2 ) = @_; |
123
|
3
|
100
|
|
|
|
12
|
if ( $self->Check( $string1, $string2 ) ) { return $self->{errstring} } |
|
1
|
|
|
|
|
9
|
|
124
|
2
|
|
|
|
|
8
|
else { return 0 } |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub Is_Valid { |
128
|
3
|
|
|
3
|
1
|
11
|
( my $self, my $string1, my $string2 ) = @_; |
129
|
3
|
100
|
|
|
|
9
|
if ( $self->Check( $string1, $string2 ) ) { return 0 } |
|
1
|
|
|
|
|
5
|
|
130
|
2
|
|
|
|
|
8
|
else { return 1 } |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub String { |
134
|
6
|
|
|
6
|
1
|
18
|
my $self = shift; |
135
|
6
|
|
|
|
|
29
|
return $self->{string}; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# The lowercase version of methods. |
139
|
1
|
|
|
1
|
1
|
3
|
sub errcnt { my $self = shift; $self->Errcnt( @_) } |
|
1
|
|
|
|
|
3
|
|
140
|
1
|
|
|
1
|
1
|
4
|
sub errstr { my $self = shift; $self->Errstr( @_) } |
|
1
|
|
|
|
|
3
|
|
141
|
1
|
|
|
1
|
1
|
1031
|
sub isnot_valid { my $self = shift; $self->IsNot_Valid( @_) } |
|
1
|
|
|
|
|
6
|
|
142
|
1
|
|
|
1
|
1
|
688
|
sub is_valid { my $self = shift; $self->Is_Valid( @_ ) } |
|
1
|
|
|
|
|
7
|
|
143
|
2
|
|
|
2
|
1
|
5
|
sub string { my $self = shift; $self->String( @_ ) } |
|
2
|
|
|
|
|
6
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; # End of String::Validator::Common |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
__END__ |