lib/DR/DateTime.pm

filter: Statementstmt 90.9% 222 / 244 Branchbran 77.3% 65 / 84 Conditioncond 70.5% 24 / 34 MC/DCmcdc 33.3% 6 / 18 Subroutinesub 86.2% 44 / 51 Podpod 74.0% 20 / 27 totaltotal 83.1% 381 / 458 CC 78 SCAR 20.2
CC
78
Cov
86%
add
18.6
parse
17.4
new
9.1
CRAP 7.6
↑ Summary blib/lib/DR/DateTime/MouseType.pm »
1 package DR::DateTime;
2 7 ▶use DR::DateTime::Defaults;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 7 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 our $VERSION = '1.00';
8 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Time::Local ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Time::Zone ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 0 ▶sub TO_JSON { shift->strftime('%F %T%z') } # JSON::XS compatible
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
16  
17 use overload
18 8 ▶ 'bool' => sub { 1 },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
19 3 ▶ '""' => sub { shift->strftime('%F %T%z') },
Subroutine __ANON__: called CC=1 SCAR=0.0
20 2 ▶ '<=>' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
21 2 my ($self, $cv, $flip) = @_;
22 2 ▶ if ('DR::DateTime' eq ref $cv) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DR::DateTime" eq ref $cv) 1 1 2
23 1 return $self->fepoch <=> $cv->fepoch;
24 }
25 1 return $self->fepoch <=> $cv;
26 },
27  
28 2 ▶ 'cmp' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
29 2 my ($self, $cv, $flip) = @_;
30 2 ▶ if ('DR::DateTime' eq ref $cv) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DR::DateTime" eq ref $cv) 1 1 2
31 1 return $self->strftime('%F %T%z') cmp $cv->strftime('%F %T%z');
32 }
33 1 my $pct = $self->parse($cv);
34 1 ▶ return $self->strftime('%F %T%z') cmp $cv unless $pct;
Branch: 1 branch
BranchTrueFalseTotal
unless $pct 0 1 1
35 1 return $self->strftime('%F %T%z') cmp $pct->strftime('%F %T%z');
36 },
37  
38 2 ▶ int => sub { shift->epoch },
Subroutine __ANON__: called CC=1 SCAR=0.0
39  
40 2 ▶ '+' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
41 2 my ($self, $cv, $flip) = @_;
42 2 ▶ if ('DR::DateTime' eq ref $cv) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DR::DateTime" eq ref $cv) 0 2 2
43 0 return $self->new(
44 $self->fepoch + $cv->fepoch,
45 $self->[1]
46 )
47 }
48  
49 $self->new(
50 2 $self->fepoch + $cv,
51 $self->[1]
52 )
53 },
54  
55 4 ▶ '-' => sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
56 4 my ($self, $cv, $flip) = @_;
57  
58 4 ▶ if ($flip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flip) { } 2 2 4
59 2 ▶ if ('DR::DateTime' eq ref $cv) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DR::DateTime" eq ref $cv) 0 2 2
60 0 return $cv->fepoch - $self->fepoch;
61 }
62 2 return $cv - $self->fepoch;
63 } else {
64 2 ▶ if ('DR::DateTime' eq ref $cv) { # date1 - $date2
Branch: 1 branch
BranchTrueFalseTotal
if ("DR::DateTime" eq ref $cv) 1 1 2
65 1 return $self->fepoch - $cv->fepoch;
66 }
67 1 return $self->new($self->fepoch - $cv, $self->[1]);
68 }
69 }
70 7 ;
71  
72  
73 48 ▶sub new {
Subroutine new: called CC=9 SCAR=22.1
Pod documented
74 48 my ($class, $stamp, $tz) = @_;
75 48 ▶ $stamp //= time;
Condition100%2/2
$stamp //= time
l!l
444
MC/DC100%1/1
$stamp //= time
$stamp
Truth table100%2/2
A
A= $stamp
Aresult
11
00
76  
77 48 ▶ if (defined $tz) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tz) 39 9 48
78 39 $tz =~ /^([+-])?(\d{2})(\d{2})?$/;
79 39 ▶ croak "Wrong timezone format" unless defined $2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $2 0 39 39
80  
81 39 ▶ $tz = join '',
Condition100%4/4
$1 // "+"
l!l
381
$3 // "00"
l!l
381
MC/DC100%1/1
$1 // "+"
$1
MC/DC100%1/1
$3 // "00"
$3
Truth table100%2/2
A
A= $1
Aresult
11
00
Truth table100%2/2
A
A= $3
Aresult
11
00
82 $1 // '+',
83 $2,
84 $3 // '00';
85 }
86  
87 48 ▶ $tz = $DR::DateTime::Defaults::TZFORCE
Branch: 1 branch
BranchTrueFalseTotal
if defined $DR::DateTime::Defaults::TZFORCE 2 46 48
88 if defined $DR::DateTime::Defaults::TZFORCE;
89  
90 48 ▶ bless [ $stamp, $tz // () ] => ref($class) || $class;
Condition66%4/6
$tz // ()
l!l&&r!l&&!r
4170
ref $class || $class
l!l&&r!l&&!r
18300
MC/DC0%0/2
$tz // ()
$tz ()
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table66%2/3
A // B
A= $tzB= ()
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
91 }
92  
93 35 ▶sub parse {
Subroutine parse: called CC=17 SCAR=28.6
Pod documented
94 35 my ($class, $str, $default_tz, $nocheck) = @_;
95 35 ▶ return undef unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 35 35
96 35 my ($y, $m, $d, $H, $M, $S, $ns, $z);
97  
98 35 for ($str) {
99  
100 35 ▶ if (/^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\d+$/) 1 34 35
101 1 ▶ return $class->new($str, $default_tz // '+0000');
Condition50%1/2
$default_tz // "+0000"
l!l
01
MC/DC0%0/1
$default_tz // "+0000"
$default_tz
Truth table50%1/2
A
A= $default_tz
Aresult
11
00
102 }
103 34 ▶ if (/^(\d{4})-(\d{2})-(\d{2})(?:\s+|T)(\d{2}):(\d{2}):(\d{2})(\.\d+)?\s*(\S+)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\d{4})-(\d{2})-(\d{2})(?:\s+|T)(\d{2}):(\d{2}):(\d{2})(\.\d+)?\s*(\S+)?$/) 28 6 34
104 28 ($y, $m, $d, $H, $M, $S, $ns, $z) =
105 ($1, $2, $3, $4, $5, $6, $7, $8);
106 28 goto PARSED;
107 }
108
109 6 ▶ if (/^(\d{4})-(\d{2})-(\d{2})(?:\s+|T)(\d{2}):(\d{2})$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\d{4})-(\d{2})-(\d{2})(?:\s+|T)(\d{2}):(\d{2})$/) 2 4 6
110 2 ($y, $m, $d, $H, $M, $S, $ns, $z) =
111 ($1, $2, $3, $4, $5, 0, 0, undef);
112 2 goto PARSED;
113 }
114
115 4 ▶ if (/^(\d{4})-(\d{2})-(\d{2})$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\d{4})-(\d{2})-(\d{2})$/) 1 3 4
116 1 ($y, $m, $d, $H, $M, $S, $ns, $z) =
117 ($1, $2, $3, 0, 0, 0, 0, undef);
118 1 goto PARSED;
119 }
120  
121 3 ▶ if (/^(\d{1,2})\.(\d{1,2})\.(\d{4})\s+(\d{2}):(\d{2}):(\d{2})(\.\d+)?\s*(\S+)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\d{1,2})\.(\d{1,2})\.(\d{4})\s+(\d{2}):(\d{2}):(\d{2})(\.\d+)?\s*(\S+)?$/) 3 0 3
122 3 ($y, $m, $d, $H, $M, $S, $ns, $z) =
123 ($3, $2, $1, $4, $5, $6, $7, $8);
124 3 goto PARSED;
125 }
126  
127 0 return undef;
128 }
129  
130  
131 PARSED:
132  
133 34 ▶ $z //= $default_tz // '+0000';
Condition75%3/4
$z //= $default_tz // "+0000"
l!l
295
$default_tz // "+0000"
l!l
05
MC/DC100%1/1
$z //= $default_tz // "+0000"
$z
Truth table100%2/2
A
A= $z
Aresult
11
00
134 34 for ($z) {
135 34 ▶ if (/^[+-]\d{1,4}$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^[+-]\d{1,4}$/) { } 34 0 34
136 34 s/^([+-])(\d|\d{3})$/${1}0$2/;
137 34 s/^([+-])(\d{2})$/${1}${2}00/;
138 } else {
139 0 croak "Wrong time zone format: '$z'";
140 }
141 }
142 34 for ($m) {
143 34 s/^0//;
144 34 $_--;
145 }
146 34 for ($d, $H, $M, $S) {
147 136 s/^0//;
148 }
149 34 $y -= 1900;
150  
151 34 ▶ $ns //= 0;
Condition100%2/2
$ns //= 0
l!l
1816
MC/DC100%1/1
$ns //= 0
$ns
Truth table100%2/2
A
A= $ns
Aresult
11
00
152 34 my $stamp = eval {
153 34 ▶ local $SIG{__DIE__} = sub {}; # Ick!
Subroutine __ANON__: not called CC=1 SCAR=0.0
154 34 ▶ return Time::Local::timegm_nocheck($S,$M,$H,$d,$m,$y) if $nocheck;
Branch: 1 branch
BranchTrueFalseTotal
if $nocheck 9 25 34
155 25 Time::Local::timegm($S,$M,$H,$d,$m,$y);
156 };
157 34 $stamp += $ns;
158  
159 34 my $offset = Time::Zone::tz_offset($z, $stamp);
160 34 $class->new($stamp - $offset, $z);
161 }
162  
163 144 ▶sub fepoch { shift->[0] }
Subroutine fepoch: called CC=1 SCAR=0.0
Pod documented
164 290 ▶sub epoch { POSIX::floor(shift->[0]) }
Subroutine epoch: called CC=1 SCAR=0.0
Pod documented
165 201 ▶sub tz { shift->[1] // $DR::DateTime::Defaults::TZ }
Subroutine tz: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
+(shift())->[1] // $DR::DateTime::Defaults::TZ
l!l&&r!l&&!r
181200
MC/DC0%0/2
+(shift())->[1] // $DR::DateTime::Defaults::TZ
+(shift())->[1] $DR::DateTime::Defaults::TZ
Truth table66%2/3
A // B
A= +(shift())->[1]B= $DR::DateTime::Defaults::TZ
ABresult
1X1
011
000
166  
167 123 ▶sub strftime :method {
Subroutine strftime: called CC=5 SCAR=16.3
Pod documented
168 123 my ($self, $format) = @_;
169 123 ▶ croak 'Invalid format' unless $format;
Branch: 1 branch
BranchTrueFalseTotal
unless $format 0 123 123
170 123 my $offset = Time::Zone::tz_offset($self->tz, $self->epoch);
171 123 my $stamp = $self->epoch + $offset;
172 123 my $fstamp = $self->fepoch + $offset;
173  
174 123 state $patterns;
175 123 ▶ unless ($patterns) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($patterns) 7 116 123
176 $patterns = {
177 0 ▶ '%' => sub { '%' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
178 47 ▶ 'z' => sub { shift->tz },
Subroutine __ANON__: called CC=1 SCAR=0.0
179 0 ▶ 'Z' => sub { shift->tz },
Subroutine __ANON__: not called CC=1 SCAR=6.9
180 20 ▶ 'N' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
181 20 int(1_000_000_000 * abs($_[2] - $_[1])) }
182  
183 7 };
184 7 for my $sp (split //, 'aAbBcCdDeEFgGhHIjklmMnOpPrRsStTuUVwWxXyY') {
185 172 ▶ $patterns->{$sp} = sub { POSIX::strftime "%$sp", gmtime $_[1] }
Subroutine __ANON__: called CC=1 SCAR=0.0
186 280 }
187 }
188  
189 123 $format =~ s{%([a-zA-Z%])}
190 239 ▶ { $patterns->{$1} ? $patterns->{$1}->($self, $stamp, $fstamp) : "%$1" }sgex;
Branch: 1 branch
BranchTrueFalseTotal
$patterns->{$1} ? : 239 0 239
191  
192 123 $format;
193 }
194  
195  
196 7 ▶sub year { shift->strftime('%Y') }
Subroutine year: called CC=1 SCAR=0.0
Pod documented
197  
198 9 ▶sub month {
Subroutine month: called CC=2 SCAR=6.9
Pod documented
199 9 for my $m (shift->strftime('%m')) {
200 9 $m =~ s/^0//;
201 9 return $m;
202 }
203 }
204  
205 28 ▶sub day {
Subroutine day: called CC=2 SCAR=6.9
Pod documented
206 28 for my $d (shift->strftime('%d')) {
207 28 $d =~ s/^0//;
208 28 return $d;
209 }
210 }
211  
212 2 ▶sub day_of_week { shift->strftime('%u') }
Subroutine day_of_week: called CC=1 SCAR=0.0
Pod documented
213  
214 2 ▶sub quarter { POSIX::ceil(shift->month / 3) }
Subroutine quarter: called CC=1 SCAR=0.0
Pod undocumented
215  
216 11 ▶sub hour {
Subroutine hour: called CC=2 SCAR=6.9
Pod documented
217 11 for my $h (shift->strftime('%H')) {
218 11 $h =~ s/^0//;
219 11 return $h;
220 }
221 }
222  
223 6 ▶sub minute {
Subroutine minute: called CC=2 SCAR=6.9
Pod documented
224 6 for my $m (shift->strftime('%M')) {
225 6 $m =~ s/^0//;
226 6 return $m;
227 }
228 }
229 4 ▶sub second {
Subroutine second: called CC=2 SCAR=6.9
Pod documented
230 4 for my $s (shift->strftime('%S')) {
231 4 $s =~ s/^0//;
232 4 return $s;
233 }
234 }
235  
236 4 ▶sub nanosecond { shift->strftime('%N') }
Subroutine nanosecond: called CC=1 SCAR=0.0
Pod documented
237  
238 2 ▶sub hms {
Subroutine hms: called CC=3 SCAR=11.1
Pod undocumented
239 2 my ($self, $sep) = @_;
240 2 ▶ $sep //= ':';
Condition50%1/2
$sep //= ":"
l!l
20
MC/DC0%0/1
$sep //= ":"
$sep
Truth table50%1/2
A
A= $sep
Aresult
11
00
241 2 for ($sep) {
242 2 s/%/%%/g;
243 }
244 2 $self->strftime("%H$sep%M$sep%S");
245 }
246  
247 0 ▶sub datetime {
Subroutine datetime: not called CC=1 SCAR=6.9
Pod undocumented
248 0 my ($self) = @_;
249 0 return join 'T', $self->ymd, $self->hms;
250 }
251  
252 2 ▶sub ymd {
Subroutine ymd: called CC=3 SCAR=11.1
Pod undocumented
253 2 my ($self, $sep) = @_;
254 2 ▶ $sep //= ':';
Condition50%1/2
$sep //= ":"
l!l
20
MC/DC0%0/1
$sep //= ":"
$sep
Truth table50%1/2
A
A= $sep
Aresult
11
00
255 2 for ($sep) {
256 2 s/%/%%/g;
257 }
258 2 $self->strftime("%Y$sep%m$sep%d");
259 }
260  
261 2 ▶sub time_zone { goto \&tz }
Subroutine time_zone: called CC=1 SCAR=0.0
Pod documented
262 0 ▶sub hires_epoch { goto \&fepoch }
Subroutine hires_epoch: not called CC=1 SCAR=6.9
Pod documented
263 9 ▶sub _fix_date_after_arith_month {
Subroutine _fix_date_after_arith_month: called CC=3 SCAR=11.0
264 9 my ($self, $new) = @_;
265 9 ▶ return $new->fepoch if $self->day == $new->day;
Branch: 1 branch
BranchTrueFalseTotal
if $self->day == $new->day 7 2 9
266 2 ▶ if ($new->day < $self->day) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new->day < $self->day) 2 0 2
267 2 $new->[0] -= 86400;
268 }
269 2 $new->fepoch;
270 }
271 6 ▶sub add {
Subroutine add: called CC=18 SCAR=29.2
Pod documented
272 6 my ($self, %set) = @_;
273
274 6 for my $n (delete $set{nanosecond}) {
275 6 ▶ last unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 6 0 6
276 0 $self->[0] += $n / 1_000_000_000;
277 }
278  
279 6 for my $s (delete $set{second}) {
280 6 ▶ last unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 5 1 6
281 1 $self->[0] += $s;
282 }
283  
284 6 for my $m (delete $set{minute}) {
285 6 ▶ last unless defined $m;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $m 6 0 6
286 0 $self->[0] += $m * 60;
287 }
288
289 6 for my $h (delete $set{hour}) {
290 6 ▶ last unless defined $h;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h 5 1 6
291 1 $self->[0] += $h * 3600;
292 }
293  
294 6 for my $d (delete $set{day}) {
295 6 ▶ last unless defined $d;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $d 5 1 6
296 1 $self->[0] += $d * 86400;
297 }
298  
299 6 for my $m (delete $set{month}) {
300 6 ▶ last unless defined $m;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $m 2 4 6
301 4 my $nm = $self->month + $m;
302  
303 4 ▶ $set{year} //= 0;
Condition100%2/2
$set{"year"} //= 0
l!l
13
MC/DC100%1/1
$set{"year"} //= 0
$set{"year"}
Truth table100%2/2
A
A= $set{"year"}
Aresult
11
00
304 4 ▶ while ($nm > 12) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nm > 12) 1 4 5
305 1 $nm -= 12;
306 1 $set{year}++;
307 }
308  
309 4 ▶ while ($nm < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nm < 1) 0 4 4
310 0 $nm += 12;
311 0 $set{year}--;
312 }
313 4 my $str = $self->strftime('%F %T.%N %z');
314 4 $str =~ s/(\d{4})-\d{2}-/sprintf "%s-%02d-", $1, $nm/e;
315 4 $self->[0] =
316 $self->_fix_date_after_arith_month($self->parse($str, undef, 1));
317 }
318  
319 6 for my $y (delete $set{year}) {
320 6 ▶ last unless defined $y;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $y 1 5 6
321 5 $y += $self->year;
322 5 my $str = $self->strftime('%F %T.%N %z');
323 5 $str =~ s/^\d{4}/$y/;
324 5 $self->[0] =
325 $self->_fix_date_after_arith_month($self->parse($str, undef, 1));
326 }
327 6 $self;
328 }
329  
330 0 ▶sub subtract {
Subroutine subtract: not called CC=2 SCAR=17.9
Pod undocumented
331 0 my ($self, %set) = @_;
332  
333 0 my %sub;
334 0 ▶ while (my ($k, $v) = each %set) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %set) 0 0 0
335 0 $sub{$k} = -$v;
336 }
337 0 $self->add(%sub);
338 }
339  
340 6 ▶sub truncate {
Subroutine truncate: called CC=8 SCAR=20.8
Pod documented
341 6 my ($self, %opts) = @_;
342  
343 6 ▶ my $to = $opts{to} // 'second';
Condition50%1/2
$opts{"to"} // "second"
l!l
60
MC/DC0%0/1
$opts{"to"} // "second"
$opts{"to"}
Truth table50%1/2
A
A= $opts{"to"}
Aresult
11
00
344  
345 6 ▶ if ($to eq 'second') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq "second") 1 5 6
346 1 $self->[0] = $self->epoch;
347 1 return $self;
348 }
349  
350 5 my $str;
351 5 ▶ if ($to eq 'minute') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq "minute") 1 4 5
352 1 $str = $self->strftime('%F %H:%M:00%z');
353 1 goto PARSE;
354 }
355  
356 4 ▶ if ($to eq 'hour') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq "hour") 1 3 4
357 1 $str = $self->strftime('%F %H:00:00%z');
358 1 goto PARSE;
359 }
360
361 3 ▶ if ($to eq 'day') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq "day") 1 2 3
362 1 $str = $self->strftime('%F 00:00:00%z');
363 1 goto PARSE;
364 }
365  
366 2 ▶ if ($to eq 'month') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq "month") 1 1 2
367 1 $str = $self->strftime('%Y-%m-01 00:00:00%z');
368 1 goto PARSE;
369 }
370
371 1 ▶ if ($to eq 'year') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq "year") 1 0 1
372 1 $str = $self->strftime('%Y-01-01 00:00:00%z');
373 1 goto PARSE;
374 }
375  
376 0 croak "Can not truncate the datetime to '$to'";
377  
378 5 PARSE:
379 $self->[0] = $self->parse($str)->epoch;
380 5 $self;
381 }
382  
383 1 ▶sub clone {
Subroutine clone: called CC=2 SCAR=8.1
Pod documented
384 1 my ($self) = @_;
385 1 ▶ bless [ @$self ] => ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
386 }
387  
388 1 ▶sub set_time_zone {
Subroutine set_time_zone: called CC=5 SCAR=17.1
Pod documented
389 1 my ($self, $tz) = @_;
390 1 ▶ if (defined $tz) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tz) 1 0 1
391 1 for ($tz) {
392 1 s/^\d{1,4}$/+$&/;
393 1 s/^([+-])(\d)$/${1}0${2}00/;
394 1 s/^([+-]\d{2})$/${1}00/;
395 1 s/^([+-])(\d{3})$/${1}0$2/;
396 }
397  
398 1 ▶ if ($tz eq 'local') {
Branch: 2 branches
BranchTrueFalseTotal
if ($tz eq 'local') { } 0 1 1
elsif (not $tz =~ /^[+-]\d{4}$/) { } 0 1 1
399 0 $tz = undef;
400 } elsif ($tz !~ /^[+-]\d{4}$/) {
401 0 croak "Wrong time zone: '$tz'";
402 }
403 }
404 1 $self->[1] = $tz;
405 1 $self;
406 }
407  
408 1 ▶sub set_tz { goto \&set_time_zone }
Subroutine set_tz: called CC=1 SCAR=0.0
Pod undocumented
409  
410 7 1;
411  
412 __END__
↑ Summary blib/lib/DR/DateTime/MouseType.pm »