line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Form::Processor::Field::DateTimeDMYHM; |
2
|
|
|
|
|
|
|
$Form::Processor::Field::DateTimeDMYHM::VERSION = '1.162360'; |
3
|
1
|
|
|
1
|
|
500
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
3
|
use base 'Form::Processor::Field'; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
398
|
|
6
|
1
|
|
|
1
|
|
5
|
use DateTime; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
244
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
0
|
|
|
0
|
1
|
|
sub init_widget {'Compound'} |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# override completely validate |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub validate_field { |
16
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $params = $self->form->params; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $name = $self->name; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my %date; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $found = 0; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
for my $sub ( qw/ month day year hour minute / ) { |
27
|
0
|
|
|
|
|
|
my $value = $params->{ $name . '.' . $sub }; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
next unless defined $value; |
30
|
0
|
|
|
|
|
|
$found++; |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
unless ( $value =~ /^\d+$/ ) { |
33
|
0
|
|
|
|
|
|
$self->add_error( "Invalid value for '[_1]", $sub ); |
34
|
0
|
|
|
|
|
|
return; |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
|
$date{$sub} = $value; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# If any found, make sure all are entered |
40
|
0
|
0
|
|
|
|
|
if ( $self->required ) { |
41
|
0
|
0
|
|
|
|
|
unless ( $found ) { |
42
|
0
|
|
|
|
|
|
$self->add_error( "Date is required" ); |
43
|
0
|
|
|
|
|
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $dt; |
49
|
0
|
|
|
|
|
|
eval { $dt = DateTime->new( %date, time_zone => 'floating' ) }; |
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ( $@ ) { |
52
|
0
|
|
|
|
|
|
my $error = $@; |
53
|
0
|
|
|
|
|
|
$error =~ s! at .+$/!!; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# probably don't want to use that error message directly |
56
|
0
|
|
|
|
|
|
$self->add_error( "Invalid date ([_1])", "$error" ); |
57
|
0
|
|
|
|
|
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$self->value( $dt ); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub format_value { |
66
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $name = $self->name; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my %hash; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
0
|
|
|
|
my $dt = $self->value || return (); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
for my $sub ( qw/ month day year hour minute / ) { |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$hash{ $name . '.' . $sub } = sprintf( '%02d', $dt->$sub ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return %hash; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# ABSTRACT: DEPRECATED example of a compound field |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |