| 1 | package DateTime::Format::Builder::Parser::Strptime; | ||||||||||
| 2 | |||||||||||
| 3 | 24 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 24 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 24 | our $VERSION = '0.82'; | |||||||||
| 7 | |||||||||||
| 8 | 24 | ▶ | use DateTime::Format::Strptime 1.04; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 24 | ▶ | use Params::Validate qw( validate SCALAR HASHREF ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 24 | ▶ | use parent 'DateTime::Format::Builder::Parser::generic'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 24 | __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 | 31 | ▶ | my ( $self, %args ) = @_; | ||||||||
|
Subroutine
create_parser: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||
| 22 | |||||||||||
| 23 | # Arguments to DTF::Strptime | ||||||||||
| 24 | 31 | my $pattern = $args{strptime}; | |||||||||
| 25 | |||||||||||
| 26 | # Create our strptime parser | ||||||||||
| 27 | 31 | ▶ | my $strptime = DateTime::Format::Strptime->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | ( ref $pattern ? %$pattern : ( pattern => $pattern ) ), | ||||||||||
| 29 | ); | ||||||||||
| 30 | 31 | ▶ | unless ( ref $self ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 31 | $self = $self->new(%args); | |||||||||
| 32 | } | ||||||||||
| 33 | 31 | $self->{strptime} = $strptime; | |||||||||
| 34 | |||||||||||
| 35 | # Create our parser | ||||||||||
| 36 | return $self->generic_parser( | ||||||||||
| 37 | ( | ||||||||||
| 38 | 124 | ▶ | map { exists $args{$_} ? ( $_ => $args{$_} ) : () } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | qw( | ||||||||||
| 40 | on_match on_fail preprocess postprocess | ||||||||||
| 41 | ) | ||||||||||
| 42 | ), | ||||||||||
| 43 | label => $args{label}, | ||||||||||
| 44 | 31 | ); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | sub do_match { | ||||||||||
| 48 | 43 | ▶ | my $self = shift; | ||||||||
|
Subroutine
do_match: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 49 | 43 | my $date = shift; | |||||||||
| 50 | 43 | local $^W; # bizarre bug | |||||||||
| 51 | # Do the match! | ||||||||||
| 52 | 43 | my $dt = eval { $self->{strptime}->parse_datetime($date) }; | |||||||||
| 53 | 43 | ▶ | return $@ ? undef : $dt; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | sub post_match { | ||||||||||
| 57 | 14 | ▶ | return $_[2]; | ||||||||
|
Subroutine
post_match: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 24 | 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.82 | ||||||||||
| 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 * | ||||||||||
| 89 | |||||||||||
| 90 | B<strptime> takes as its argument a strptime string. | ||||||||||
| 91 | See L<DateTime::Format::Strptime> for more information | ||||||||||
| 92 | on valid patterns. | ||||||||||
| 93 | |||||||||||
| 94 | =back | ||||||||||
| 95 | |||||||||||
| 96 | =head1 SEE ALSO | ||||||||||
| 97 | |||||||||||
| 98 | C<datetime@perl.org> mailing list. | ||||||||||
| 99 | |||||||||||
| 100 | http://datetime.perl.org/ | ||||||||||
| 101 | |||||||||||
| 102 | L<perl>, L<DateTime>, | ||||||||||
| 103 | L<DateTime::Format::Builder> | ||||||||||
| 104 | |||||||||||
| 105 | =head1 SUPPORT | ||||||||||
| 106 | |||||||||||
| 107 | Bugs may be submitted at L<http://rt.cpan.org/Public/Dist/Display.html?Name=DateTime-Format-Builder> or via email to L<bug-datetime-format-builder@rt.cpan.org|mailto:bug-datetime-format-builder@rt.cpan.org>. | ||||||||||
| 108 | |||||||||||
| 109 | I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>. | ||||||||||
| 110 | |||||||||||
| 111 | =head1 SOURCE | ||||||||||
| 112 | |||||||||||
| 113 | The source code repository for DateTime-Format-Builder can be found at L<https://github.com/houseabsolute/DateTime-Format-Builder>. | ||||||||||
| 114 | |||||||||||
| 115 | =head1 AUTHORS | ||||||||||
| 116 | |||||||||||
| 117 | =over 4 | ||||||||||
| 118 | |||||||||||
| 119 | =item * | ||||||||||
| 120 | |||||||||||
| 121 | Dave Rolsky <autarch@urth.org> | ||||||||||
| 122 | |||||||||||
| 123 | =item * | ||||||||||
| 124 | |||||||||||
| 125 | Iain Truskett | ||||||||||
| 126 | |||||||||||
| 127 | =back | ||||||||||
| 128 | |||||||||||
| 129 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 130 | |||||||||||
| 131 | This software is Copyright (c) 2019 by Dave Rolsky. | ||||||||||
| 132 | |||||||||||
| 133 | This is free software, licensed under: | ||||||||||
| 134 | |||||||||||
| 135 | The Artistic License 2.0 (GPL Compatible) | ||||||||||
| 136 | |||||||||||
| 137 | The full text of the license can be found in the | ||||||||||
| 138 | F<LICENSE> file included with this distribution. | ||||||||||
| 139 | |||||||||||
| 140 | =cut | ||||||||||