line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::CheckArgs::date; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use base 'HTML::CheckArgs::Object'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
693
|
|
7
|
1
|
|
|
1
|
|
552
|
use HTML::FormatData; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub is_valid { |
10
|
|
|
|
|
|
|
my $self = shift; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $value = $self->value; |
13
|
|
|
|
|
|
|
my $config = $self->config; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$self->check_params( required => [ 'format' ], optional => [ 'regex' ], cleanable => 0 ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# no value passed in |
18
|
|
|
|
|
|
|
if ( $config->{required} && !$value ) { |
19
|
|
|
|
|
|
|
$self->error_code( 'date_00' ); # required |
20
|
|
|
|
|
|
|
$self->error_message( 'Not given.' ); |
21
|
|
|
|
|
|
|
return; |
22
|
|
|
|
|
|
|
} elsif ( !$config->{required} && !$value ) { |
23
|
|
|
|
|
|
|
return 1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $f = HTML::FormatData->new; |
27
|
|
|
|
|
|
|
unless ( $f->parse_date( $value, $config->{params}{format} ) ) { |
28
|
|
|
|
|
|
|
$self->error_code( 'date_01' ); # not valid |
29
|
|
|
|
|
|
|
$self->error_message( 'Not a valid date.' ); |
30
|
|
|
|
|
|
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# DateTime doesn't do strict parsing, so unfortunately |
34
|
|
|
|
|
|
|
# we need this extra (and not backwards compatible) hack. |
35
|
|
|
|
|
|
|
if ( $config->{params}{regex} ) { |
36
|
|
|
|
|
|
|
my $pat = $config->{params}{regex}; |
37
|
|
|
|
|
|
|
if ( $value !~ m/$pat/ ) { |
38
|
|
|
|
|
|
|
$self->error_code( 'date_02' ); # not match regex |
39
|
|
|
|
|
|
|
$self->error_message( 'Not a valid date.'); |
40
|
|
|
|
|
|
|
return; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return 1; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |