Builder/Parser/Strptime.pm

filter: Statementstmt 100% 33 / 33 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 66.6% 2 / 3 totaltotal 90.3% 47 / 52 CC 5 SCAR 8.0
CC
5
Cov
90%
create_parser
4.2
do_match
2.0
BEGIN
1.0
CRAP 2.2
« Builder/Parser/Regex.pm ↑ Summary
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
BranchTrueFalseTotal
ref $pattern ? : 0 31 31
28 ( ref $pattern ? %$pattern : ( pattern => $pattern ) ),
29 );
30 31 ▶ unless ( ref $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 31 0 31
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
BranchTrueFalseTotal
exists $args{$_} ? : 0 124 124
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
BranchTrueFalseTotal
$@ ? : 0 43 43
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__
« Builder/Parser/Regex.pm ↑ Summary