blib/lib/Time/Moment.pm

filter: Statementstmt 71.1% 32 / 45 Branchbran 50.0% 7 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 64.7% 11 / 17 Podpod 28.5% 2 / 7 totaltotal 60.2% 53 / 88 CC 9 SCAR 11.8
CC
9
Cov
65%
BEGIN
6.8
__as_Time_Moment
6.0
STORABLE_thaw
5.3
CRAP 3.2
« blib/lib/Time/Moment/Adjusters.pm ↑ Summary src/dt_arithmetic.c »
1 package Time::Moment;
2 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 24 ▶use Carp qw[];
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 24 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 24 our $VERSION = '0.46';
9 24 require XSLoader; XSLoader::load(__PACKAGE__, $VERSION);
10 }
11  
12 24 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=19.2
13 24 ▶ unless (exists &Time::Moment::now) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists &Time::Moment::now) 0 24 24
14 0 require Time::HiRes;
15 0 eval sprintf <<'EOC', __FILE__;
16 # line 17 %s
17  
18 # expects normalized tm values; algorithm is only valid for tm year's [1, 199]
19 sub timegm {
20 my ($y, $d, $h, $m, $s) = @_[5,7,2,1,0];
21 return ((1461 * --$y >> 2) + $d - 25202) * 86400 + $h * 3600 + $m * 60 + $s;
22 }
23  
24 sub now {
25 @_ == 1 || Carp::croak(q/Usage: Time::Moment->now()/);
26 my ($class) = @_;
27  
28 my ($sec, $usec) = Time::HiRes::gettimeofday();
29 my $offset = int((timegm(localtime($sec)) - $sec) / 60);
30 return $class->from_epoch($sec, $usec * 1000)
31 ->with_offset_same_instant($offset);
32 }
33  
34 sub now_utc {
35 @_ == 1 || Carp::croak(q/Usage: Time::Moment->now_utc()/);
36 my ($class) = @_;
37  
38 my ($sec, $usec) = Time::HiRes::gettimeofday();
39 return $class->from_epoch($sec, $usec * 1000);
40 }
41 EOC
42 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
43 }
44 }
45  
46 24 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
47 24 delete @Time::Moment::{qw(timegm)};
48 }
49  
50 0 ▶sub __as_DateTime {
Subroutine __as_DateTime: not called CC=1 SCAR=6.9
51 0 my ($tm) = @_;
52 0 return DateTime->from_epoch(
53 epoch => $tm->epoch,
54 time_zone => $tm->strftime('%Z'),
55 )->set_nanosecond($tm->nanosecond);
56 }
57  
58 0 ▶sub __as_Time_Piece {
Subroutine __as_Time_Piece: not called CC=1 SCAR=6.9
59 0 my ($tm) = @_;
60 0 return scalar Time::Piece::gmtime($tm->epoch);
61 }
62  
63 0 ▶sub DateTime::__as_Time_Moment {
Subroutine __as_Time_Moment: not called CC=2 SCAR=17.9
64 0 my ($dt) = @_;
65  
66 0 ▶ (!$dt->time_zone->is_floating)
Branch: 1 branch
BranchTrueFalseTotal
$dt->time_zone->is_floating and Carp::croak("Cannot coerce an instance of DateTime in the 'floating' time zone to an instance of Time::Moment") 0 0 0
67 or Carp::croak(q/Cannot coerce an instance of DateTime in the 'floating' /
68 .q/time zone to an instance of Time::Moment/);
69  
70 0 return Time::Moment->from_epoch($dt->epoch, $dt->nanosecond)
71 ->with_offset_same_instant(int($dt->offset / 60));
72 }
73  
74 2 ▶sub Time::Piece::__as_Time_Moment {
Subroutine __as_Time_Moment: called CC=1 SCAR=0.0
75 2 my ($tp) = @_;
76 2 return Time::Moment->from_epoch($tp->epoch)
77 ->with_offset_same_instant(int($tp->tzoffset / 60));
78 }
79  
80 3 ▶sub STORABLE_freeze {
Subroutine STORABLE_freeze: called CC=2 SCAR=6.9
Pod undocumented
81 3 my ($self, $cloning) = @_;
82 3 ▶ return if $cloning;
Branch: 1 branch
BranchTrueFalseTotal
if $cloning 1 2 3
83 2 return pack 'nnNNN', 0x544D, $self->offset, $self->utc_rd_values;
84 }
85  
86 2 ▶sub STORABLE_thaw {
Subroutine STORABLE_thaw: called CC=5 SCAR=16.7
Pod undocumented
87 2 my ($self, $cloning, $packed) = @_;
88 2 ▶ return if $cloning;
Branch: 1 branch
BranchTrueFalseTotal
if $cloning 0 2 2
89 2 ▶ (length($packed) == 16 && vec($packed, 0, 16) == 0x544D) # TM
Branch: 1 branch
BranchTrueFalseTotal
length $packed == 16 and vec($packed, 0, 16) == 21581 or die "Cannot deserialize corrupted data" 2 0 2
Condition33%1/3
length $packed == 16 and vec($packed, 0, 16) == 21581
!ll&&!rl&&r
002
MC/DC0%0/2
length $packed == 16 and vec($packed, 0, 16) == 21581
length $packed == 16 vec($packed, 0, 16) == 21581
Truth table33%1/3
A and B
A= length $packed == 16B= vec($packed, 0, 16) == 21581
ABresult
0X0
100
111
90 or die(q/Cannot deserialize corrupted data/); # Don't replace die with Carp!
91 2 my ($offset, $rdn, $sod, $nos) = unpack 'xxnNNN', $packed;
92 2 ▶ $offset = ($offset & 0x7FFF) - 0x8000 if ($offset & 0x8000);
Branch: 1 branch
BranchTrueFalseTotal
if $offset & 32768 1 1 2
93 2 my $seconds = ($rdn - 719163) * 86400 + $sod;
94 2 $$self = ${ ref($self)->from_epoch($seconds, $nos)
95 ->with_offset_same_instant($offset) };
96 }
97  
98 0 ▶sub TO_JSON {
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
99 0 return $_[0]->to_string;
100 }
101  
102 0 ▶sub TO_CBOR {
Subroutine TO_CBOR: not called CC=1 SCAR=6.9
Pod undocumented
103 # Use the standard tag for date/time string; see RFC 7049 Section 2.4.1
104 0 return CBOR::XS::tag(0, $_[0]->to_string);
105 }
106  
107 2 ▶sub FREEZE {
Subroutine FREEZE: called CC=1 SCAR=0.0
Pod documented
108 2 return $_[0]->to_string;
109 }
110  
111 2 ▶sub THAW {
Subroutine THAW: called CC=1 SCAR=0.0
Pod documented
112 2 my ($class, undef, $string) = @_;
113 2 return $class->from_string($string);
114 }
115  
116 # Alias
117 24 *with_offset = \&with_offset_same_instant;
118  
119 # used by DateTime::TimeZone
120 0 ▶sub utc_year {
Subroutine utc_year: not called CC=1 SCAR=6.9
Pod undocumented
121 0 return $_[0]->with_offset_same_instant(0)->year;
122 }
123  
124 24 1;
125  
« blib/lib/Time/Moment/Adjusters.pm ↑ Summary src/dt_arithmetic.c »