line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Labyrinth::Constraints; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
36220
|
use warnings; |
|
9
|
|
|
|
|
27
|
|
|
9
|
|
|
|
|
257
|
|
4
|
9
|
|
|
9
|
|
32
|
use strict; |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
252
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
32
|
use vars qw($VERSION $AUTOLOAD @ISA @EXPORT); |
|
9
|
|
|
|
|
9
|
|
|
9
|
|
|
|
|
583
|
|
7
|
|
|
|
|
|
|
$VERSION = '5.32'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Labyrinth::Constraints - Basic Constraint Handler for Labyrinth |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Provides basic constraint methods used within Labyrinth. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
20
|
|
|
|
|
|
|
# Libraries |
21
|
|
|
|
|
|
|
|
22
|
9
|
|
|
9
|
|
2381
|
use Labyrinth::Variables; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
25
|
|
|
|
|
|
|
# Exporter Settings |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
require Exporter; |
28
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
29
|
|
|
|
|
|
|
@EXPORT = qw( |
30
|
|
|
|
|
|
|
ddmmyy valid_ddmmyy match_ddmmyy |
31
|
|
|
|
|
|
|
url valid_url match_url |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
35
|
|
|
|
|
|
|
# Subroutines |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 FUNCTIONS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 ddmmyy |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Validates simple day-month-year date strings. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 4 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item ddmmyy |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item valid_ddmmyy |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item match_ddmmyy |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=back |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub ddmmyy { |
56
|
|
|
|
|
|
|
my %params = @_; |
57
|
|
|
|
|
|
|
return sub { |
58
|
|
|
|
|
|
|
my $self = shift; |
59
|
|
|
|
|
|
|
$self->set_current_constraint_name('ddmmyy'); |
60
|
|
|
|
|
|
|
$self->valid_ddmmyy(\%params); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my %mon = ( 1=>31,2=>29,3=>31,4=>30,5=>31,6=>30,7=>31,8=>31,9=>30,10=>31,11=>30,12=>31 ); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub valid_ddmmyy { |
67
|
|
|
|
|
|
|
my ($self,$text) = @_; |
68
|
|
|
|
|
|
|
return 0 unless($text); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my @part = $text =~ m< ^ (\d{2,2}) [-/.] (\d{2,2}) [-/.] (\d{4,4}) $ >x; |
71
|
|
|
|
|
|
|
return 0 unless(@part == 3); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return 0 if($part[2] < 1900 && $part[0] > 9999); |
74
|
|
|
|
|
|
|
return 0 if($part[1] < 1 && $part[0] > 12); |
75
|
|
|
|
|
|
|
return 0 if($part[0] < 1 && $part[0] > $mon{$part[1]}); |
76
|
|
|
|
|
|
|
return 0 if($part[0] > 28 && $part[1] == 2 && $part[2] % 4 != 0); # crude, but may surfice |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return 1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub match_ddmmyy { |
82
|
|
|
|
|
|
|
my ($self,$text) = @_; |
83
|
|
|
|
|
|
|
return unless defined $text; |
84
|
|
|
|
|
|
|
return $text if($text =~ m< ^ \d{2,2} [-/.] \d{2,2} [-/.] \d{4,4} $ >x); |
85
|
|
|
|
|
|
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 url |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Validates simple URL patterns. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=over 4 |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item url |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item valid_url |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item match_url |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=back |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub url { |
105
|
|
|
|
|
|
|
my %params = @_; |
106
|
|
|
|
|
|
|
return sub { |
107
|
|
|
|
|
|
|
my $self = shift; |
108
|
|
|
|
|
|
|
$self->set_current_constraint_name('url'); |
109
|
|
|
|
|
|
|
$self->valid_url(\%params); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub match_url { |
114
|
|
|
|
|
|
|
my ($self,$text) = @_; |
115
|
|
|
|
|
|
|
return unless($text); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my ($url) = $text =~ /^($settings{urlregex})$/x; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
return unless($url); |
120
|
|
|
|
|
|
|
$text = 'http://' . $text unless($text =~ m!^\w+://!); |
121
|
|
|
|
|
|
|
return $text; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub AUTOLOAD { |
125
|
|
|
|
|
|
|
my $name = $AUTOLOAD; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
no strict qw/refs/; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$name =~ m/^(.*::)(valid_|RE_)(.*)/; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
my ($pkg,$prefix,$sub) = ($1,$2,$3); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# Since all the valid_* routines are essentially identical we're |
134
|
|
|
|
|
|
|
# going to generate them dynamically from match_ routines with the same names. |
135
|
|
|
|
|
|
|
if ((defined $prefix) and ($prefix eq 'valid_')) { |
136
|
|
|
|
|
|
|
return defined &{$pkg.'match_' . $sub}(@_) ? 1 : 0; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
__END__ |