blib/lib/DateTime/Infinite.pm

filter: Statementstmt 93.1% 95 / 102 Branchbran 83.3% 5 / 6 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 84.4% 38 / 45 Podpod 83.3% 10 / 12 totaltotal 90.1% 156 / 173 CC 6 SCAR 3.1
CC
6
Cov
93%
AUTOLOAD
3.0
_rd2ymd
2.1
_infinity_string
2.0
CRAP 1.4
« blib/lib/DateTime/Helpers.pm ↑ Summary DateTime.xs »
1 ## no critic (Modules::ProhibitMultiplePackages)
2 package DateTime::Infinite;
3  
4 49 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 49 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 49 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 49 our $VERSION = '1.68';
9  
10 49 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 49 ▶use DateTime::TimeZone;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 49 ▶use parent qw(DateTime);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 49 foreach my $m (qw( set set_time_zone truncate )) {
16 ## no critic (TestingAndDebugging::ProhibitNoStrict)
17 49 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶ *{"DateTime::Infinite::$m"} = sub { return $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
19 }
20  
21 2 ▶sub is_finite {0}
Subroutine is_finite: called CC=1 SCAR=0.0
Pod documented
22 6 ▶sub is_infinite {1}
Subroutine is_infinite: called CC=1 SCAR=0.0
Pod documented
23  
24 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
25 98 ▶sub _rd2ymd {
Subroutine _rd2ymd: called CC=2 SCAR=7.6
26 98 ▶ return $_[2] ? ( $_[1] ) x 7 : ( $_[1] ) x 3;
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 98 0 98
27 }
28  
29 98 ▶sub _seconds_as_components {
Subroutine _seconds_as_components: called CC=1 SCAR=0.0
30 98 return ( $_[1] ) x 3;
31 }
32  
33 2 ▶sub ymd {
Subroutine ymd: called CC=1 SCAR=0.0
Pod documented
34 2 return $_[0]->iso8601;
35 }
36  
37 2 ▶sub mdy {
Subroutine mdy: called CC=1 SCAR=0.0
Pod documented
38 2 return $_[0]->iso8601;
39 }
40  
41 2 ▶sub dmy {
Subroutine dmy: called CC=1 SCAR=0.0
Pod documented
42 2 return $_[0]->iso8601;
43 }
44  
45 4 ▶sub hms {
Subroutine hms: called CC=1 SCAR=0.0
Pod documented
46 4 return $_[0]->iso8601;
47 }
48  
49 2 ▶sub hour_12 {
Subroutine hour_12: called CC=1 SCAR=0.0
Pod documented
50 2 return $_[0]->_infinity_string;
51 }
52  
53 2 ▶sub hour_12_0 {
Subroutine hour_12_0: called CC=1 SCAR=0.0
Pod documented
54 2 return $_[0]->_infinity_string;
55 }
56  
57 14 ▶sub datetime {
Subroutine datetime: called CC=1 SCAR=0.0
Pod documented
58 14 return $_[0]->_infinity_string;
59 }
60  
61 2 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
Pod documented
62 2 return $_[0]->_infinity_string;
63 }
64  
65 20 ▶sub _infinity_string {
Subroutine _infinity_string: called CC=2 SCAR=6.9
66 20 ▶ return $_[0]->{utc_rd_days} == DateTime::INFINITY
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'utc_rd_days'} == 9**9**9 ? : 10 10 20
67 ? DateTime::INFINITY . q{}
68 : DateTime::NEG_INFINITY . q{};
69 }
70  
71 2 ▶sub _week_values { [ $_[0]->{utc_rd_days}, $_[0]->{utc_rd_days} ] }
Subroutine _week_values: called CC=1 SCAR=0.0
72  
73 2 ▶sub STORABLE_freeze {return}
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
74 0 ▶sub STORABLE_thaw {return}
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
75  
76 package DateTime::Infinite::Future;
77  
78 49 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 49 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
80  
81 49 ▶use parent qw(DateTime::Infinite);
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 {
84 49 my $Pos = bless {
85 utc_rd_days => DateTime::INFINITY,
86 utc_rd_secs => DateTime::INFINITY,
87 local_rd_days => DateTime::INFINITY,
88 local_rd_secs => DateTime::INFINITY,
89 rd_nanosecs => DateTime::INFINITY,
90 tz => DateTime::TimeZone->new( name => 'floating' ),
91 locale => FakeLocale->instance,
92 },
93 __PACKAGE__;
94  
95 49 $Pos->_calc_utc_rd;
96 49 $Pos->_calc_local_rd;
97  
98 4 ▶ sub new {$Pos}
Subroutine new: called CC=1 SCAR=0.0
99 }
100  
101 49 package DateTime::Infinite::Past;
102  
103 49 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
104 49 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
105  
106 49 ▶use parent qw(DateTime::Infinite);
Subroutine BEGIN: called CC=1 SCAR=0.0
107  
108 {
109 49 my $Neg = bless {
110 utc_rd_days => DateTime::NEG_INFINITY,
111 utc_rd_secs => DateTime::NEG_INFINITY,
112 local_rd_days => DateTime::NEG_INFINITY,
113 local_rd_secs => DateTime::NEG_INFINITY,
114 rd_nanosecs => DateTime::NEG_INFINITY,
115 tz => DateTime::TimeZone->new( name => 'floating' ),
116 locale => FakeLocale->instance,
117 },
118 __PACKAGE__;
119  
120 49 $Neg->_calc_utc_rd;
121 49 $Neg->_calc_local_rd;
122  
123 4 ▶ sub new {$Neg}
Subroutine new: called CC=1 SCAR=0.0
124 }
125  
126 package # hide from PAUSE
127 49 FakeLocale;
128  
129 49 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
130 49 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
131  
132 49 ▶use DateTime::Locale;
Subroutine BEGIN: called CC=1 SCAR=0.0
133  
134 49 my $Instance;
135  
136 98 ▶sub instance {
Subroutine instance: called CC=2 SCAR=6.9
137 98 ▶ return $Instance ||= bless { locale => DateTime::Locale->load('en_US') },
Condition100%2/2
$Instance ||= bless({"locale", "DateTime::Locale"->load("en_US")}, __PACKAGE__)
l!l
4949
MC/DC100%1/1
$Instance ||= bless({"locale", "DateTime::Locale"->load("en_US")}, __PACKAGE__)
$Instance
Truth table100%2/2
A
A= $Instance
Aresult
11
00
138 __PACKAGE__;
139 }
140  
141 0 ▶sub id {
Subroutine id: not called CC=1 SCAR=6.9
142 0 return 'infinite';
143 }
144  
145 0 ▶sub language_id {
Subroutine language_id: not called CC=1 SCAR=6.9
146 0 return 'infinite';
147 }
148  
149 1 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
150 1 'Fake locale for Infinite DateTime objects';
151 }
152  
153 0 ▶sub language {
Subroutine language: not called CC=1 SCAR=6.9
154 0 'Fake locale for Infinite DateTime objects';
155 }
156  
157 49 my @methods = qw(
158 script_id
159 territory_id
160 variant_id
161 script
162 territory
163 variant
164 native_name
165 native_language
166 native_script
167 native_territory
168 native_variant
169 );
170  
171 49 for my $meth (@methods) {
172 ## no critic (TestingAndDebugging::ProhibitNoStrict)
173 49 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
174 0 ▶ *{$meth} = sub {undef};
Subroutine __ANON__: not called CC=1 SCAR=0.4
175 }
176  
177 # Totally arbitrary
178 0 ▶sub first_day_of_week {
Subroutine first_day_of_week: not called CC=1 SCAR=6.9
179 0 return 1;
180 }
181  
182 0 ▶sub prefers_24_hour_time {
Subroutine prefers_24_hour_time: not called CC=1 SCAR=6.9
183 0 return 0;
184 }
185  
186 49 our $AUTOLOAD;
187  
188 ## no critic (ClassHierarchies::ProhibitAutoloading)
189 5 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=3 SCAR=11.0
190 5 my $self = shift;
191  
192 5 my ($meth) = $AUTOLOAD =~ /::(\w+)$/;
193  
194 5 ▶ if ( $meth =~ /format/ && $meth !~ /^(?:day|month|quarter)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meth =~ /format/ and not $meth =~ /^(?:day|month|quarter)/) 1 4 5
Condition100%3/3
$meth =~ /format/ and not $meth =~ /^(?:day|month|quarter)/
!ll&&!rl&&r
311
MC/DC100%2/2
$meth =~ /format/ and not $meth =~ /^(?:day|month|quarter)/
$meth =~ /format/ not $meth =~ /^(?:day|month|quarter)/
Truth table100%3/3
A and not(B)
A= $meth =~ /format/B= not $meth =~ /^(?:day|month|quarter)/
ABresult
0X0
100
111
195 1 return $self->{locale}->$meth(@_);
196 }
197  
198 4 return [];
199 }
200  
201 49 1;
202  
203 # ABSTRACT: Infinite past and future DateTime objects
204  
205 __END__
« blib/lib/DateTime/Helpers.pm ↑ Summary DateTime.xs »