line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormHandler::Field::DateTime; |
2
|
|
|
|
|
|
|
# ABSTRACT: compound DateTime field |
3
|
|
|
|
|
|
|
$HTML::FormHandler::Field::DateTime::VERSION = '0.40067'; |
4
|
7
|
|
|
7
|
|
5244
|
use Moose; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
56
|
|
5
|
|
|
|
|
|
|
extends 'HTML::FormHandler::Field::Compound'; |
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
36690
|
use DateTime; |
|
7
|
|
|
|
|
1555936
|
|
|
7
|
|
|
|
|
271
|
|
8
|
7
|
|
|
7
|
|
51
|
use Try::Tiny; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
2257
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has '+widget' => ( default => 'Compound' ); |
12
|
|
|
|
|
|
|
has '+inflate_default_method' => ( default => sub { \&datetime_inflate } ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $class_messages = { |
15
|
|
|
|
|
|
|
'datetime_invalid' => 'Not a valid DateTime', |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
sub get_class_messages { |
18
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
19
|
|
|
|
|
|
|
return { |
20
|
1
|
|
|
|
|
2
|
%{ $self->next::method }, |
|
1
|
|
|
|
|
5
|
|
21
|
|
|
|
|
|
|
%$class_messages, |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub datetime_inflate { |
26
|
1
|
|
|
1
|
0
|
2
|
my ( $self, $value ) = @_; |
27
|
1
|
50
|
|
|
|
5
|
return $value unless ref $value eq 'DateTime'; |
28
|
1
|
|
|
|
|
1
|
my %hash; |
29
|
1
|
|
|
|
|
33
|
foreach my $field ( $self->all_fields ) { |
30
|
3
|
|
|
|
|
74
|
my $meth = $field->name; |
31
|
3
|
|
|
|
|
12
|
$hash{$meth} = $value->$meth; |
32
|
|
|
|
|
|
|
} |
33
|
1
|
|
|
|
|
8
|
return \%hash; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub validate { |
37
|
13
|
|
|
13
|
1
|
33
|
my ($self) = @_; |
38
|
13
|
|
|
|
|
30
|
my @dt_parms; |
39
|
13
|
|
|
|
|
486
|
foreach my $child ( $self->all_fields ) { |
40
|
39
|
50
|
|
|
|
99
|
next unless $child->value; |
41
|
39
|
|
|
|
|
990
|
push @dt_parms, ( $child->accessor => $child->value ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# set the value |
45
|
13
|
|
|
|
|
27
|
my $dt; |
46
|
|
|
|
|
|
|
try { |
47
|
13
|
|
|
13
|
|
892
|
$dt = DateTime->new(@dt_parms); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
catch { |
50
|
1
|
|
|
1
|
|
881
|
$self->add_error( $self->get_message('datetime_invalid') ); |
51
|
13
|
|
|
|
|
147
|
}; |
52
|
13
|
100
|
|
|
|
4918
|
if( $dt ) { |
53
|
12
|
|
|
|
|
912
|
$self->_set_value($dt); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
1
|
|
|
|
|
10
|
$self->_set_value( {@dt_parms} ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
61
|
7
|
|
|
7
|
|
40
|
use namespace::autoclean; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
58
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=pod |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=encoding UTF-8 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
HTML::FormHandler::Field::DateTime - compound DateTime field |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 VERSION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
version 0.40067 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 DESCRIPTION |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This is a compound field that requires you to define the subfields |
81
|
|
|
|
|
|
|
for month/day/year/hour/minute. Widget type is 'compound'. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
If you want to use drop-down select boxes for your DateTime, you |
84
|
|
|
|
|
|
|
can select fields like: |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
has_field 'my_date' => ( type => 'DateTime' ); |
87
|
|
|
|
|
|
|
has_field 'my_date.month' => ( type => 'Month' ); |
88
|
|
|
|
|
|
|
has_field 'my_date.day' => ( type => 'MonthDay' ); |
89
|
|
|
|
|
|
|
has_field 'my_date.year' => ( type => 'Year' ); |
90
|
|
|
|
|
|
|
has_field 'my_date.hour' => ( type => 'Hour' ); |
91
|
|
|
|
|
|
|
has_field 'my_date.minute' => ( type => 'Minute' ); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
If you want simple input fields: |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
has_field 'my_date' => ( type => 'DateTime' ); |
96
|
|
|
|
|
|
|
has_field 'my_date.month' => ( type => 'Integer', range_start => 1, |
97
|
|
|
|
|
|
|
range_end => 12 ); |
98
|
|
|
|
|
|
|
has_field 'my_date.day' => ( type => 'Integer', range_start => 1, |
99
|
|
|
|
|
|
|
range_end => 31 ); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Customizable error: 'datetime_invalid' (default = "Not a valid DateTime") |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
See the 'Date' field for a single input date field. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 AUTHOR |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
FormHandler Contributors - see HTML::FormHandler |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Gerda Shank. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
114
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |