blib/lib/BusyBird/DateTime/Format.pm

filter: Statementstmt 90.0% 27 / 30 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 100% 3 / 3 totaltotal 89.1% 41 / 46 CC 4 SCAR 7.7
CC
4
Cov
91%
parse_datetime
4.0
new
2.0
__ANON__
2.0
CRAP 2.2
↑ Summary
1 package BusyBird::DateTime::Format;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = "0.05";
8  
9 2 our $preferred = 0;
10  
11 2 my %OPT_DEFAULT = (
12 locale => 'en_US',
13 on_error => 'undef',
14 );
15  
16 2 my @FORMATS = (
17 DateTime::Format::Strptime->new(
18 %OPT_DEFAULT,
19 pattern => '%a %b %d %T %z %Y',
20 ),
21 DateTime::Format::Strptime->new(
22 %OPT_DEFAULT,
23 pattern => '%a, %d %b %Y %T %z',
24 ),
25 );
26  
27 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
28 0 my ($class) = @_;
29 0 return bless {}, $class;
30 }
31  
32 10 ▶sub parse_datetime {
Subroutine parse_datetime: called CC=4 SCAR=13.9
Pod documented
33 10 my ($class_self, $string) = @_;
34 10 my $parsed;
35 10 ▶ return undef if not defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 1 9 10
36 9 foreach my $f (@FORMATS) {
37 13 ▶ $parsed = try {
Subroutine __ANON__: called CC=1 SCAR=0.0
38 13 $f->parse_datetime($string);
39 0 ▶ }catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 0 undef;
41 13 };
42 13 ▶ last if defined($parsed);
Branch: 1 branch
BranchTrueFalseTotal
if defined $parsed 8 5 13
43 }
44 9 return $parsed;
45 }
46  
47 5 ▶sub format_datetime {
Subroutine format_datetime: called CC=1 SCAR=0.0
Pod documented
48 5 my ($class_self, $datetime) = @_;
49 5 return $FORMATS[$preferred]->format_datetime($datetime);
50 }
51  
52  
53  
54 2 1;
55 __END__
↑ Summary