File Coverage

blib/lib/DateTime/Format/Builder/Parser/Strptime.pm
Criterion Covered Total %
statement 33 33 100.0
branch 4 8 50.0
condition n/a
subroutine 9 9 100.0
pod 2 3 66.6
total 48 53 90.5


line stmt bran cond sub pod time code
1             package DateTime::Format::Builder::Parser::Strptime;
2             {
3             $DateTime::Format::Builder::Parser::Strptime::VERSION = '0.81';
4             }
5              
6              
7 24     24   121 use strict;
  24         49  
  24         739  
8 24     24   156 use warnings;
  24         44  
  24         645  
9 24     24   113 use vars qw( @ISA );
  24         46  
  24         1162  
10 24     24   38545 use DateTime::Format::Strptime 1.04;
  24         402989  
  24         1953  
11 24     24   312 use Params::Validate qw( validate SCALAR HASHREF );
  24         54  
  24         1667  
12              
13 24     24   141 use DateTime::Format::Builder::Parser::generic;
  24         52  
  24         6988  
14             @ISA = qw( DateTime::Format::Builder::Parser::generic );
15              
16             __PACKAGE__->valid_params(
17             strptime => {
18             type => SCALAR
19             | HASHREF, # straight pattern or options to DTF::Strptime
20             },
21             );
22              
23             sub create_parser {
24 29     29 0 69 my ( $self, %args ) = @_;
25              
26             # Arguments to DTF::Strptime
27 29         49 my $pattern = $args{strptime};
28              
29             # Create our strptime parser
30 29 50       163 my $strptime = DateTime::Format::Strptime->new(
31             ( ref $pattern ? %$pattern : ( pattern => $pattern ) ),
32             );
33 29 50       9988 unless ( ref $self ) {
34 29         180 $self = $self->new(%args);
35             }
36 29         82 $self->{strptime} = $strptime;
37              
38             # Create our parser
39 116 50       345 return $self->generic_parser(
40             (
41 29         51 map { exists $args{$_} ? ( $_ => $args{$_} ) : () }
42             qw(
43             on_match on_fail preprocess postprocess
44             )
45             ),
46             label => $args{label},
47             );
48             }
49              
50             sub do_match {
51 43     43 1 61 my $self = shift;
52 43         48 my $date = shift;
53 43         128 local $^W; # bizarre bug
54             # Do the match!
55 43         227 my $dt = eval { $self->{strptime}->parse_datetime($date) };
  43         151  
56 43 50       20661 return $@ ? undef : $dt;
57             }
58              
59             sub post_match {
60 14     14 1 40 return $_[2];
61             }
62              
63             1;
64              
65             # ABSTRACT: strptime based date parsing
66              
67             __END__