blib/lib/DBIO/Storage/DateTimeFormat.pm

filter: Statementstmt 100% 45 / 45 Branchbran 88.8% 16 / 18 Conditioncond 72.7% 8 / 11 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 90.5% 86 / 95 CC 14 SCAR 11.5
CC
14
Cov
93%
_preferred
5.0
_strptime_for
4.0
format_date
3.3
CRAP 3.1
« blib/lib/DBIO/Storage/Composed.pm ↑ Summary blib/lib/DBIO/AccessBroker.pm »
1 package DBIO::Storage::DateTimeFormat;
2 # ABSTRACT: Strptime-backed datetime format base for driver format classes
3  
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $VERSION = '0.900007';
8  
9 6 ▶use base 'DBIO::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 ▶use DBIO::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 __PACKAGE__->mk_group_accessors('inherited' => qw/
14 preferred_format_class
15 datetime_parse_pattern datetime_format_pattern
16 date_parse_pattern date_format_pattern
17 /);
18  
19  
20 6 my %preferred_loadable;
21 my %strptime_cache;
22  
23 27 ▶sub _preferred {
Subroutine _preferred: called CC=5 SCAR=16.1
24 27 my $class = shift;
25  
26 27 ▶ my $preferred = $class->preferred_format_class
Branch: 1 branch
BranchTrueFalseTotal
my $preferred = $class->preferred_format_class or return undef 5 22 27
27 or return undef;
28  
29 5 ▶ $preferred_loadable{$preferred} //= $class->load_optional_class($preferred) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$class->load_optional_class($preferred) ? : 1 1 2
Condition100%2/2
$preferred_loadable{$preferred} //= $class->load_optional_class($preferred) ? 1 : 0
l!l
32
MC/DC100%1/1
$preferred_loadable{$preferred} //= $class->load_optional_class($preferred) ? 1 : 0
$preferred_loadable{$preferred}
Truth table100%2/2
A
A= $preferred_loadable{$preferred}
Aresult
11
00
30  
31 5 ▶ return $preferred_loadable{$preferred} ? $preferred : undef;
Branch: 1 branch
BranchTrueFalseTotal
$preferred_loadable{$preferred} ? : 3 2 5
32 }
33  
34  
35 25 ▶sub _strptime_for {
Subroutine _strptime_for: called CC=4 SCAR=13.9
36 25 my ($class, $slot, $accessor) = @_;
37  
38 25 ▶ return $strptime_cache{"$class|$slot"} //= do {
Condition100%3/3
$strptime_cache{"$class|$slot"} //= do { my $pattern = $class->$accessor or "DBIO::Exception"->throw("$class defines no $accessor and no loadable preferred_format_class"); unless (eval { do { require DateTime::Format::Strptime; 1 } }) { my $err = $@; "DBIO::Exception"->throw("$class needs DateTime::Format::Strptime to parse/format datetimes, " . 'but it is not installed. Install DateTime::Format::Strptime (part ' . "of the optional DBIO::Timestamp/DateTime feature) and retry." . "\n\nUnderlying error: $err"); } ; "DateTime::Format::Strptime"->new("pattern", $pattern, "on_error", "croak") }
l!l&&r!l&&!r
6145
MC/DC100%2/2
$strptime_cache{"$class|$slot"} //= do { my $pattern = $class->$accessor or "DBIO::Exception"->throw("$class defines no $accessor and no loadable preferred_format_class"); unless (eval { do { require DateTime::Format::Strptime; 1 } }) { my $err = $@; "DBIO::Exception"->throw("$class needs DateTime::Format::Strptime to parse/format datetimes, " . 'but it is not installed. Install DateTime::Format::Strptime (part ' . "of the optional DBIO::Timestamp/DateTime feature) and retry." . "\n\nUnderlying error: $err"); } ; "DateTime::Format::Strptime"->new("pattern", $pattern, "on_error", "croak") }
$strptime_cache{"$class|$slot"} do { my $pattern = $class->$accessor or "DBIO::Exception"->throw("$class defines no $accessor and no loadable preferred_format_class"); unless (eval { do { require DateTime::Format::Strptime; 1 } }) { my $err = $@; "DBIO::Exception"->throw("$class needs DateTime::Format::Strptime to parse/format datetimes, " . 'but it is not installed. Install DateTime::Format::Strptime (part ' . "of the optional DBIO::Timestamp/DateTime feature) and retry." . "\n\nUnderlying error: $err"); } ; "DateTime::Format::Strptime"->new("pattern", $pattern, "on_error", "croak") }
Truth table100%3/3
A //= B
A= $strptime_cache{"$class|$slot"}B= do { my $pattern = $class->$accessor or "DBIO::Exception"->throw("$class defines no $accessor and no loadable preferred_format_class"); unless (eval { do { require DateTime::Format::Strptime; 1 } }) { my $err = $@; "DBIO::Exception"->throw("$class needs DateTime::Format::Strptime to parse/format datetimes, " . 'but it is not installed. Install DateTime::Format::Strptime (part ' . "of the optional DBIO::Timestamp/DateTime feature) and retry." . "\n\nUnderlying error: $err"); } ; "DateTime::Format::Strptime"->new("pattern", $pattern, "on_error", "croak") }
ABresult
1X1
011
000
39 19 ▶ my $pattern = $class->$accessor
Branch: 1 branch
BranchTrueFalseTotal
my $pattern = $class->$accessor or "DBIO::Exception"->throw("$class defines no $accessor and no loadable preferred_format_class") 14 5 19
40 or DBIO::Exception->throw(
41 "$class defines no $accessor and no loadable preferred_format_class"
42 );
43  
44 # Loaded lazily, not at compile time: a bare DBIO install that
45 # never inflates datetimes carries no DateTime stack at all. Only a driver
46 # format class that actually parses/formats via strptime patterns pulls it
47 # in — and only at that point, so the missing-pattern guard above still
48 # fires without DateTime::Format::Strptime present.
49 14 ▶ unless (eval { require DateTime::Format::Strptime; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require DateTime::Format::Strptime; 1 } }) 2 12 14
50 2 my $err = $@;
51 2 DBIO::Exception->throw(
52 "$class needs DateTime::Format::Strptime to parse/format datetimes, "
53 . "but it is not installed. Install DateTime::Format::Strptime (part "
54 . "of the optional DBIO::Timestamp/DateTime feature) and retry."
55 . "\n\nUnderlying error: $err"
56 );
57 }
58  
59 DateTime::Format::Strptime->new(
60 12 pattern => $pattern,
61 on_error => 'croak'
62 );
63 };
64 }
65  
66  
67 10 ▶sub parse_datetime {
Subroutine parse_datetime: called CC=2 SCAR=6.9
Pod documented
68 10 my ($class, $value) = @_;
69  
70 10 ▶ if (my $preferred = $class->_preferred) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $preferred = $class->_preferred) 1 9 10
71 1 return $preferred->parse_datetime($value);
72 }
73  
74 9 return $class->_strptime_for(datetime_parse => 'datetime_parse_pattern')
75 ->parse_datetime($value);
76 }
77  
78  
79 10 ▶sub format_datetime {
Subroutine format_datetime: called CC=2 SCAR=6.9
Pod documented
80 10 my ($class, $dt) = @_;
81  
82 10 ▶ if (my $preferred = $class->_preferred) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $preferred = $class->_preferred) 1 9 10
83 1 return $preferred->format_datetime($dt);
84 }
85  
86 9 return $class->_strptime_for(datetime_format => 'datetime_format_pattern')
87 ->format_datetime($dt);
88 }
89  
90  
91 3 ▶sub parse_date {
Subroutine parse_date: called CC=3 SCAR=11.3
Pod documented
92 3 my ($class, $value) = @_;
93  
94 3 my $preferred = $class->_preferred;
95 3 ▶ return $preferred->parse_date($value)
Branch: 1 branch
BranchTrueFalseTotal
if $preferred and $preferred->can("parse_date") 0 3 3
Condition66%2/3
$preferred and $preferred->can("parse_date")
!ll&&!rl&&r
210
MC/DC0%0/2
$preferred and $preferred->can("parse_date")
$preferred $preferred->can("parse_date")
Truth table66%2/3
A and B
A= $preferredB= $preferred->can("parse_date")
ABresult
0X0
100
111
96 if $preferred and $preferred->can('parse_date');
97  
98 3 return $class->_strptime_for(date_parse => 'date_parse_pattern')
99 ->parse_datetime($value);
100 }
101  
102  
103 4 ▶sub format_date {
Subroutine format_date: called CC=3 SCAR=12.0
Pod documented
104 4 my ($class, $dt) = @_;
105  
106 4 my $preferred = $class->_preferred;
107 4 ▶ return $preferred->format_date($dt)
Branch: 1 branch
BranchTrueFalseTotal
if $preferred and $preferred->can("format_date") 0 4 4
Condition33%1/3
$preferred and $preferred->can("format_date")
!ll&&!rl&&r
400
MC/DC0%0/2
$preferred and $preferred->can("format_date")
$preferred $preferred->can("format_date")
Truth table33%1/3
A and B
A= $preferredB= $preferred->can("format_date")
ABresult
0X0
100
111
108 if $preferred and $preferred->can('format_date');
109  
110 4 return $class->_strptime_for(date_format => 'date_format_pattern')
111 ->format_datetime($dt);
112 }
113  
114 6 1;
115  
116 __END__
« blib/lib/DBIO/Storage/Composed.pm ↑ Summary blib/lib/DBIO/AccessBroker.pm »