blib/lib/Bootylicious/Timestamp.pm

filter: Statementstmt 90.9% 40 / 44 Branchbran 75.0% 6 / 8 Conditioncond 77.7% 7 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 90.0% 9 / 10 Podpod 16.6% 1 / 6 totaltotal 80.4% 66 / 82 CC 9 SCAR 13.2
CC
9
Cov
87%
_to_epoch
7.3
new
2.0
strftime
2.0
CRAP 3.7
« blib/lib/Bootylicious/ArticleByQueryIterator.pm ↑ Summary blib/lib/Bootylicious/ArticleArchiveYearly.pm »
1 package Bootylicious::Timestamp;
2  
3 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 16 ▶use base 'Mojo::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 16 require Time::Local;
9 16 require Time::Piece;
10  
11 16 __PACKAGE__->attr('epoch');
12  
13 16 my $TIMESTAMP_RE = qr/(\d\d\d\d)(\d?\d)(\d?\d)(?:T(\d\d):?(\d\d):?(\d\d))?/;
14  
15 sub new {
16 231 ▶ my $self = shift->SUPER::new;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
17 231 my %params = @_;
18  
19 231 ▶ if (exists $params{epoch}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{'epoch'}) { } 167 64 231
20 167 $self->epoch($params{epoch});
21 }
22 else {
23 64 my $epoch = $self->_to_epoch($params{timestamp});
24 64 $self->epoch($epoch);
25 }
26  
27 231 return $self;
28 }
29  
30 sub _to_epoch {
31 64 ▶ my $self = shift;
Subroutine _to_epoch: called CC=7 SCAR=19.9
32 64 my $timestamp = shift;
33  
34 64 ▶ return unless $timestamp =~ qr/^$TIMESTAMP_RE$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $timestamp =~ qr/^$TIMESTAMP_RE$/ 0 64 64
35  
36 64 ▶ my ($year, $month, $day, $hour, $minute, $second) =
Condition100%6/6
$4 || 0
l!l
1351
$5 || 0
l!l
1351
$6 || 0
l!l
1351
MC/DC100%1/1
$4 || 0
$4
MC/DC100%1/1
$5 || 0
$5
MC/DC100%1/1
$6 || 0
$6
Truth table100%2/2
A
A= $4
Aresult
11
00
Truth table100%2/2
A
A= $5
Aresult
11
00
Truth table100%2/2
A
A= $6
Aresult
11
00
37 ($1, $2, $3, ($4 || 0), ($5 || 0), ($6 || 0));
38  
39 64 my $epoch = 0;
40 64 eval {
41 64 $epoch =
42 Time::Local::timegm($second, $minute, $hour, $day, $month - 1,
43 $year - 1900);
44 };
45  
46 64 ▶ return if $@ || $epoch < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $@ or $epoch < 0 0 64 64
Condition33%1/3
$@ or $epoch < 0
l!l&&r!l&&!r
0064
MC/DC0%0/2
$@ or $epoch < 0
$@ $epoch < 0
Truth table33%1/3
A or B
A= $@B= $epoch < 0
ABresult
1X1
011
000
47  
48 64 return $epoch;
49 }
50  
51 sub year {
52 20 ▶ my $self = shift;
Subroutine year: called CC=1 SCAR=0.0
Pod undocumented
53  
54 20 return Time::Piece->gmtime($self->epoch)->year;
55 }
56  
57 sub month {
58 15 ▶ my $self = shift;
Subroutine month: called CC=1 SCAR=0.0
Pod undocumented
59  
60 15 return Time::Piece->gmtime($self->epoch)->mon;
61 }
62  
63 sub timestamp {
64 10 ▶ my $self = shift;
Subroutine timestamp: called CC=1 SCAR=0.0
Pod undocumented
65  
66 10 my $t = Time::Piece->gmtime($self->epoch);
67  
68 10 return $t->strftime('%Y%m%dT%H:%M:%S');
69 }
70  
71 sub strftime {
72 0 ▶ my $self = shift;
Subroutine strftime: not called CC=1 SCAR=6.9
Pod undocumented
73 0 my $fmt = shift;
74  
75 0 my $t = Time::Piece->gmtime($self->epoch);
76  
77 0 return $t->strftime($fmt);
78 }
79  
80 sub is_timestamp {
81 2 ▶ my $self = shift;
Subroutine is_timestamp: called CC=2 SCAR=6.9
Pod undocumented
82 2 my $timestamp = shift;
83  
84 2 ▶ return $timestamp =~ qr/^$TIMESTAMP_RE$/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$timestamp =~ qr/^$TIMESTAMP_RE$/ ? : 1 1 2
85 }
86  
87 16 1;
« blib/lib/Bootylicious/ArticleByQueryIterator.pm ↑ Summary blib/lib/Bootylicious/ArticleArchiveYearly.pm »