line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormFu::Constraint::DateTime; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
804
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
179
|
|
4
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
13
|
use Moose; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
25
|
|
7
|
|
|
|
|
|
|
extends 'HTML::FormFu::Constraint'; |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
18313
|
use DateTime::Format::Builder; |
|
4
|
|
|
|
|
726955
|
|
|
4
|
|
|
|
|
39
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has _builder => ( |
12
|
|
|
|
|
|
|
is => 'rw', |
13
|
|
|
|
|
|
|
default => sub { DateTime::Format::Builder->new }, |
14
|
|
|
|
|
|
|
lazy => 1, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub parser { |
18
|
3
|
|
|
3
|
1
|
5
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
|
|
83
|
$self->_builder->parser(@_); |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
4596
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub constrain_value { |
26
|
3
|
|
|
3
|
0
|
6
|
my ( $self, $value ) = @_; |
27
|
|
|
|
|
|
|
|
28
|
3
|
50
|
33
|
|
|
19
|
return 1 if !defined $value || $value eq ''; |
29
|
|
|
|
|
|
|
|
30
|
3
|
|
|
|
|
82
|
my $dt = $self->_builder->parse_datetime($value); |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
1713
|
return 1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub clone { |
36
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $clone = $self->SUPER::clone(@_); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$clone->_builder( $self->_builder->clone ); |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return $clone; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
HTML::FormFu::Constraint::DateTime - DateTime constraint |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 VERSION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
version 2.05 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SYNOPSIS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
--- |
62
|
|
|
|
|
|
|
elements: |
63
|
|
|
|
|
|
|
- type: Text |
64
|
|
|
|
|
|
|
name: start_date |
65
|
|
|
|
|
|
|
constraints: |
66
|
|
|
|
|
|
|
- type: DateTime |
67
|
|
|
|
|
|
|
parser: |
68
|
|
|
|
|
|
|
strptime: '%d-%m-%Y' |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
- type: Text |
71
|
|
|
|
|
|
|
name: end_time |
72
|
|
|
|
|
|
|
constraints: |
73
|
|
|
|
|
|
|
- type: DateTime |
74
|
|
|
|
|
|
|
parser: |
75
|
|
|
|
|
|
|
regex: !!perl/regexp '^(\d{2}) - (\d{2}) - (\d{4})$' |
76
|
|
|
|
|
|
|
params: [day, month, year] |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
An example of using the same parser declaration for both a DateTime |
79
|
|
|
|
|
|
|
constraint and a DateTime inflator, using YAML references: |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
--- |
82
|
|
|
|
|
|
|
elements: |
83
|
|
|
|
|
|
|
- type: Text |
84
|
|
|
|
|
|
|
name: date |
85
|
|
|
|
|
|
|
constraints: |
86
|
|
|
|
|
|
|
- type: DateTime |
87
|
|
|
|
|
|
|
parser: &PARSER |
88
|
|
|
|
|
|
|
strptime: '%d-%m-%Y' |
89
|
|
|
|
|
|
|
inflators: |
90
|
|
|
|
|
|
|
- type: DateTime |
91
|
|
|
|
|
|
|
parser: *PARSER |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 DESCRIPTION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Ensure input can later be inflated to a DateTime object. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 METHODS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 parser |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Arguments: \%args |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Required. Define the expected input string, so L<DateTime::Format::Builder> |
104
|
|
|
|
|
|
|
knows how to turn it into a L<DateTime> object. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Accepts arguments to be passed to L<DateTime::Format::Builder/parser>. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHOR |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Carl Franks, C<cfranks@cpan.org> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 LICENSE |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
115
|
|
|
|
|
|
|
the same terms as Perl itself. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |