| 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.83'; | |||||||||
| 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 | 31 | ▶ | sub create_parser { | ||||||||
|
Subroutine
create_parser: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||
| 21 | 31 | my ( $self, %args ) = @_; | |||||||||
| 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 | 43 | ▶ | sub do_match { | ||||||||
|
Subroutine
do_match: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 48 | 43 | my $self = shift; | |||||||||
| 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 | 14 | ▶ | sub post_match { | ||||||||
|
Subroutine
post_match: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 57 | 14 | return $_[2]; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 24 | 1; | |||||||||
| 61 | |||||||||||
| 62 | # ABSTRACT: strptime based date parsing | ||||||||||
| 63 | |||||||||||
| 64 | __END__ | ||||||||||