Atompub/DateTime.pm

filter: Statementstmt 54.0% 40 / 74 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 52.1% 12 / 23 Podpod 100% 10 / 10 totaltotal 42.7% 62 / 145 CC 14 SCAR 23.5
CC
14
Cov
38%
init
42.0
tz
12.0
new
6.0
CRAP 10.5
« Atompub/Server.pm ↑ Summary Atompub/Util.pm »
1 package Atompub::DateTime;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Atompub;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use DateTime::Format::W3CDTF;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use DateTime::TimeZone;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use HTTP::Date qw(str2time time2isoz time2str);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Perl6::Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 ▶use base qw(Class::Accessor::Fast Class::Data::Inheritable);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 5 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 q{""} => \&w3c,
18 q{0+} => \&epoch,
19 fallback => 1,
20 5 );
21  
22 5 my $tz;
23 0 ▶sub tz {
Subroutine tz: not called CC=3 SCAR=24.8
Pod documented
24 0 ▶ unless ($tz) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tz) 0 0 0
25 0 eval { $tz = DateTime::TimeZone->new(name => 'local') };
26 0 ▶ if ($@) { $tz = DateTime::TimeZone->new(name => 'UTC' ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
27 }
28 0 $tz;
29 }
30  
31 5 __PACKAGE__->mk_classdata(fmt => DateTime::Format::W3CDTF->new);
32 5 __PACKAGE__->mk_accessors(qw(dt));
33  
34 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
35 0 my($class, @args) = @_;
36 0 my $self = bless {}, $class;
37 0 ▶ $self->init(@args) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->init(@args) or return 0 0 0
38 0 $self;
39 }
40  
41 0 ▶sub init {
Subroutine init: not called CC=6 SCAR=37.4
Pod documented
42 0 my($self, $arg) = @_;
43  
44 0 ▶ my $epoch = !$arg ? time
Branch: 4 branches
BranchTrueFalseTotal
!$arg ? : 0 0 0
UNIVERSAL::can($arg, 'epoch') ? : 0 0 0
$arg =~ qr/^\d{1,13}$/ ? : 0 0 0
$arg =~ qr/^\d{14}$/ ? : 0 0 0
45 : UNIVERSAL::can($arg, 'epoch') ? $arg->epoch
46 : $arg =~ qr{^\d{1,13}$} ? $arg
47 : $arg =~ qr{^\d{14}$} ? _parse_timestamp($arg)
48 : str2time $arg;
49  
50 0 ▶ return unless defined $epoch;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $epoch 0 0 0
51  
52 0 $self->dt(DateTime->from_epoch(
53 epoch => $epoch,
54 time_zone => $self->tz,
55 formatter => $self->fmt,
56 ));
57  
58 0 $self;
59 }
60  
61 0 ▶sub datetime :Export { __PACKAGE__->new(@_) }
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine datetime: not called CC=1 SCAR=0.2
Pod documented
62  
63 0 ▶sub _parse_timestamp {
Subroutine _parse_timestamp: not called CC=1 SCAR=6.9
64 0 my @a = $_[0] =~ /(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/;
65 0 $a[1]--; # month
66 0 timelocal reverse @a;
67 }
68  
69 0 ▶sub epoch { $_[0]->dt->epoch }
Subroutine epoch: not called CC=1 SCAR=6.9
Pod documented
70  
71 0 ▶sub iso {
Subroutine iso: not called CC=2 SCAR=17.9
Pod documented
72 0 my($self) = @_;
73 0 ▶ $self->{iso} ||= sprintf '%s %s', $self->dt->ymd, $self->dt->hms;
Condition0%0/3
$self->{"iso"} ||= sprintf("%s %s", $self->dt->ymd, $self->dt->hms)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"iso"} ||= sprintf("%s %s", $self->dt->ymd, $self->dt->hms)
$self->{"iso"} sprintf("%s %s", $self->dt->ymd, $self->dt->hms)
Truth table0%0/3
A ||= B
A= $self->{"iso"}B= sprintf("%s %s", $self->dt->ymd, $self->dt->hms)
ABresult
1X1
011
000
74 }
75  
76 0 ▶sub isoz {
Subroutine isoz: not called CC=2 SCAR=17.9
Pod documented
77 0 my($self) = @_;
78 0 ▶ $self->{isoz} ||= time2isoz $self->epoch;
Condition0%0/3
$self->{"isoz"} ||= &time2isoz(scalar $self->epoch)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"isoz"} ||= &time2isoz(scalar $self->epoch)
$self->{"isoz"} &time2isoz(scalar $self->epoch)
Truth table0%0/3
A ||= B
A= $self->{"isoz"}B= &time2isoz(scalar $self->epoch)
ABresult
1X1
011
000
79 }
80  
81 0 ▶sub w3c {
Subroutine w3c: not called CC=2 SCAR=17.9
Pod documented
82 0 my($self) = @_;
83 0 ▶ $self->{w3c} ||= '' . $self->dt;
Condition0%0/3
$self->{"w3c"} ||= '' . $self->dt
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"w3c"} ||= '' . $self->dt
$self->{"w3c"} '' . $self->dt
Truth table0%0/3
A ||= B
A= $self->{"w3c"}B= '' . $self->dt
ABresult
1X1
011
000
84 }
85  
86 0 ▶sub w3cz {
Subroutine w3cz: not called CC=2 SCAR=17.9
Pod documented
87 0 my($self) = @_;
88 0 ▶ unless ($self->{w3cz}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"w3cz"}) 0 0 0
89 0 my $w3cz = time2isoz $self->epoch;
90 0 $w3cz =~ s/ /T/;
91 0 $self->{w3cz} = $w3cz;
92 }
93 0 $self->{w3cz};
94 }
95  
96 0 ▶sub str {
Subroutine str: not called CC=2 SCAR=17.9
Pod documented
97 0 my($self) = @_;
98 0 ▶ $self->{str} ||= time2str $self->epoch;
Condition0%0/3
$self->{"str"} ||= &time2str(scalar $self->epoch)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"str"} ||= &time2str(scalar $self->epoch)
$self->{"str"} &time2str(scalar $self->epoch)
Truth table0%0/3
A ||= B
A= $self->{"str"}B= &time2str(scalar $self->epoch)
ABresult
1X1
011
000
99 }
100  
101 5 1;
102 __END__
« Atompub/Server.pm ↑ Summary Atompub/Util.pm »