line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormHandler::Field::Duration; |
2
|
|
|
|
|
|
|
# ABSTRACT: DateTime::Duration from HTML form values |
3
|
|
|
|
|
|
|
$HTML::FormHandler::Field::Duration::VERSION = '0.40067'; |
4
|
2
|
|
|
2
|
|
1394
|
use Moose; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
13
|
|
5
|
|
|
|
|
|
|
extends 'HTML::FormHandler::Field::Compound'; |
6
|
2
|
|
|
2
|
|
10521
|
use DateTime; |
|
2
|
|
|
|
|
581573
|
|
|
2
|
|
|
|
|
390
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $class_messages = { |
10
|
|
|
|
|
|
|
'duration_invalid' => 'Invalid value for [_1]: [_2]', |
11
|
|
|
|
|
|
|
}; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub get_class_messages { |
14
|
2
|
|
|
2
|
0
|
1
|
my $self = shift; |
15
|
|
|
|
|
|
|
return { |
16
|
2
|
|
|
|
|
3
|
%{ $self->next::method }, |
|
2
|
|
|
|
|
8
|
|
17
|
|
|
|
|
|
|
%$class_messages, |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub validate { |
23
|
4
|
|
|
4
|
1
|
6
|
my ($self) = @_; |
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
|
|
4
|
my @dur_parms; |
26
|
4
|
|
|
|
|
146
|
foreach my $child ( $self->all_fields ) { |
27
|
8
|
100
|
66
|
|
|
22
|
unless ( $child->has_value && $child->value =~ /^\d+$/ ) { |
28
|
2
|
|
|
|
|
13
|
$self->add_error( $self->get_message('duration_invalid'), $self->loc_label, $child->loc_label ); |
29
|
2
|
|
|
|
|
4
|
next; |
30
|
|
|
|
|
|
|
} |
31
|
6
|
|
|
|
|
142
|
push @dur_parms, ( $child->accessor => $child->value ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# set the value |
35
|
4
|
|
|
|
|
33
|
my $duration = DateTime::Duration->new(@dur_parms); |
36
|
4
|
|
|
|
|
401
|
$self->_set_value($duration); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
40
|
2
|
|
|
2
|
|
16
|
use namespace::autoclean; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
13
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=pod |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=encoding UTF-8 |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 NAME |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
HTML::FormHandler::Field::Duration - DateTime::Duration from HTML form values |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 VERSION |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
version 0.40067 |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SubFields |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Subfield names: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
years, months, weeks, days, hours, minutes, seconds, nanoseconds |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
For example: |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
has_field 'duration' => ( type => 'Duration' ); |
66
|
|
|
|
|
|
|
has_field 'duration.hours' => ( type => 'Hour' ); |
67
|
|
|
|
|
|
|
has_field 'duration.minutes' => ( type => 'Minute' ); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Customize error message 'duration_invalid' (default 'Invalid value for [_1]: [_2]') |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 AUTHOR |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
FormHandler Contributors - see HTML::FormHandler |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Gerda Shank. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
80
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |