line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DateTime::Format::Builder::Parser::Strptime; |
2
|
|
|
|
|
|
|
|
3
|
24
|
|
|
24
|
|
157
|
use strict; |
|
24
|
|
|
|
|
46
|
|
|
24
|
|
|
|
|
609
|
|
4
|
24
|
|
|
24
|
|
116
|
use warnings; |
|
24
|
|
|
|
|
40
|
|
|
24
|
|
|
|
|
977
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.83'; |
7
|
|
|
|
|
|
|
|
8
|
24
|
|
|
24
|
|
15097
|
use DateTime::Format::Strptime 1.04; |
|
24
|
|
|
|
|
1663760
|
|
|
24
|
|
|
|
|
144
|
|
9
|
24
|
|
|
24
|
|
2379
|
use Params::Validate qw( validate SCALAR HASHREF ); |
|
24
|
|
|
|
|
51
|
|
|
24
|
|
|
|
|
1334
|
|
10
|
|
|
|
|
|
|
|
11
|
24
|
|
|
24
|
|
135
|
use parent 'DateTime::Format::Builder::Parser::generic'; |
|
24
|
|
|
|
|
45
|
|
|
24
|
|
|
|
|
156
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->valid_params( |
14
|
|
|
|
|
|
|
strptime => { |
15
|
|
|
|
|
|
|
type => SCALAR |
16
|
|
|
|
|
|
|
| HASHREF, # straight pattern or options to DTF::Strptime |
17
|
|
|
|
|
|
|
}, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub create_parser { |
21
|
29
|
|
|
29
|
0
|
77
|
my ( $self, %args ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Arguments to DTF::Strptime |
24
|
29
|
|
|
|
|
51
|
my $pattern = $args{strptime}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Create our strptime parser |
27
|
29
|
50
|
|
|
|
109
|
my $strptime = DateTime::Format::Strptime->new( |
28
|
|
|
|
|
|
|
( ref $pattern ? %$pattern : ( pattern => $pattern ) ), |
29
|
|
|
|
|
|
|
); |
30
|
29
|
50
|
|
|
|
31262
|
unless ( ref $self ) { |
31
|
29
|
|
|
|
|
133
|
$self = $self->new(%args); |
32
|
|
|
|
|
|
|
} |
33
|
29
|
|
|
|
|
61
|
$self->{strptime} = $strptime; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Create our parser |
36
|
|
|
|
|
|
|
return $self->generic_parser( |
37
|
|
|
|
|
|
|
( |
38
|
116
|
50
|
|
|
|
267
|
map { exists $args{$_} ? ( $_ => $args{$_} ) : () } |
39
|
|
|
|
|
|
|
qw( |
40
|
|
|
|
|
|
|
on_match on_fail preprocess postprocess |
41
|
|
|
|
|
|
|
) |
42
|
|
|
|
|
|
|
), |
43
|
|
|
|
|
|
|
label => $args{label}, |
44
|
29
|
|
|
|
|
57
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub do_match { |
48
|
43
|
|
|
43
|
1
|
62
|
my $self = shift; |
49
|
43
|
|
|
|
|
62
|
my $date = shift; |
50
|
43
|
|
|
|
|
98
|
local $^W; # bizarre bug |
51
|
|
|
|
|
|
|
# Do the match! |
52
|
43
|
|
|
|
|
65
|
my $dt = eval { $self->{strptime}->parse_datetime($date) }; |
|
43
|
|
|
|
|
99
|
|
53
|
43
|
50
|
|
|
|
9075
|
return $@ ? undef : $dt; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub post_match { |
57
|
14
|
|
|
14
|
1
|
29
|
return $_[2]; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# ABSTRACT: strptime based date parsing |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=pod |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=encoding UTF-8 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
DateTime::Format::Builder::Parser::Strptime - strptime based date parsing |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 VERSION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
version 0.83 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SYNOPSIS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $parser = DateTime::Format::Builder->create_parser( |
81
|
|
|
|
|
|
|
strptime => '%e/%b/%Y:%H:%M:%S %z', |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 SPECIFICATION |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=over 4 |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item * strptime |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
B<strptime> takes as its argument a strptime string. See |
91
|
|
|
|
|
|
|
L<DateTime::Format::Strptime> for more information on valid patterns. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=back |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SEE ALSO |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
C<datetime@perl.org> mailing list. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
http://datetime.perl.org/ |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L<perl>, L<DateTime>, |
102
|
|
|
|
|
|
|
L<DateTime::Format::Builder> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SUPPORT |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Bugs may be submitted at L<https://github.com/houseabsolute/DateTime-Format-Builder/issues>. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SOURCE |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
The source code repository for DateTime-Format-Builder can be found at L<https://github.com/houseabsolute/DateTime-Format-Builder>. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHORS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=over 4 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Iain Truskett <spoon@cpan.org> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This software is Copyright (c) 2020 by Dave Rolsky. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This is free software, licensed under: |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
The full text of the license can be found in the |
137
|
|
|
|
|
|
|
F<LICENSE> file included with this distribution. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |