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