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.40068'; |
4
|
7
|
|
|
7
|
|
5371
|
use Moose; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
58
|
|
5
|
|
|
|
|
|
|
extends 'HTML::FormHandler::Field::Compound'; |
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
48110
|
use DateTime; |
|
7
|
|
|
|
|
2018501
|
|
|
7
|
|
|
|
|
266
|
|
8
|
7
|
|
|
7
|
|
52
|
use Try::Tiny; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
2259
|
|
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
|
3
|
my $self = shift; |
19
|
|
|
|
|
|
|
return { |
20
|
1
|
|
|
|
|
3
|
%{ $self->next::method }, |
|
1
|
|
|
|
|
7
|
|
21
|
|
|
|
|
|
|
%$class_messages, |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub datetime_inflate { |
26
|
1
|
|
|
1
|
0
|
5
|
my ( $self, $value ) = @_; |
27
|
1
|
50
|
|
|
|
10
|
return $value unless ref $value eq 'DateTime'; |
28
|
1
|
|
|
|
|
3
|
my %hash; |
29
|
1
|
|
|
|
|
41
|
foreach my $field ( $self->all_fields ) { |
30
|
3
|
|
|
|
|
104
|
my $meth = $field->name; |
31
|
3
|
|
|
|
|
24
|
$hash{$meth} = $value->$meth; |
32
|
|
|
|
|
|
|
} |
33
|
1
|
|
|
|
|
12
|
return \%hash; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub validate { |
37
|
13
|
|
|
13
|
1
|
42
|
my ($self) = @_; |
38
|
13
|
|
|
|
|
32
|
my @dt_parms; |
39
|
13
|
|
|
|
|
488
|
foreach my $child ( $self->all_fields ) { |
40
|
39
|
50
|
|
|
|
132
|
next unless $child->value; |
41
|
39
|
|
|
|
|
989
|
push @dt_parms, ( $child->accessor => $child->value ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# set the value |
45
|
13
|
|
|
|
|
42
|
my $dt; |
46
|
|
|
|
|
|
|
try { |
47
|
13
|
|
|
13
|
|
1207
|
$dt = DateTime->new(@dt_parms); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
catch { |
50
|
1
|
|
|
1
|
|
1092
|
$self->add_error( $self->get_message('datetime_invalid') ); |
51
|
13
|
|
|
|
|
167
|
}; |
52
|
13
|
100
|
|
|
|
5986
|
if( $dt ) { |
53
|
12
|
|
|
|
|
124
|
$self->_set_value($dt); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
1
|
|
|
|
|
8
|
$self->_set_value( {@dt_parms} ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
61
|
7
|
|
|
7
|
|
55
|
use namespace::autoclean; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
62
|
|
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.40068 |
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) 2017 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 |