blib/lib/POSIX/1003/Time.pm

filter: Statementstmt 77.4% 48 / 62 Branchbran 41.6% 5 / 12 Conditioncond 11.1% 2 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 78.5% 11 / 14 Podpod 100% 3 / 3 totaltotal 58.4% 69 / 118 CC 15 SCAR 28.9
CC
15
Cov
60%
_tm_flatten
56.0
mktime
12.0
strftime
10.5
CRAP 18.0
« blib/lib/POSIX/1003/Limit.pm ↑ Summary blib/lib/POSIX/1003/FS.pm »
1 # Copyrights 2011-2020 by [Mark Overmeer].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution POSIX-1003. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package POSIX::1003::Time;
10 5 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 $VERSION = '1.02';
12  
13 5 ▶use base 'POSIX::1003::Module';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 ▶use POSIX::1003::Locale qw(setlocale LC_TIME);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use Encode qw(find_encoding is_utf8 decode);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 5 our @IN_CORE = qw/gmtime localtime/;
22  
23 5 my @constants;
24 5 my @functions = qw/
25 asctime ctime strftime
26 clock difftime mktime
27 tzset tzname strptime/;
28 5 push @functions, @IN_CORE;
29  
30 5 our %EXPORT_TAGS =
31 ( constants => \@constants
32 , functions => \@functions
33 , tables => [ '%time' ]
34 );
35  
36 5 my $time;
37 5 our %time;
38  
39 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
40 5 $time = time_table;
41 5 push @constants, keys %$time;
42 5 tie %time, 'POSIX::1003::ReadOnlyTable', $time;
43 }
44  
45  
46 sub _tm_flatten($)
47 0 ▶{ my $tm = shift;
Subroutine _tm_flatten: not called CC=7 SCAR=40.3
48 ( $tm->{sec} // 0, $tm->{min} // 0, $tm->{hour} // 0
49 , $tm->{day}-1, $tm->{month}-1, $tm->{year}-1900
50 0 ▶ , $tm->{wday} // -1, $tm->{yday} // -1, $tm->{is_dst} // -1
Condition0%0/12
$tm->{"sec"} // 0
l!l
00
$tm->{"min"} // 0
l!l
00
$tm->{"hour"} // 0
l!l
00
$tm->{"wday"} // -1
l!l
00
$tm->{"yday"} // -1
l!l
00
$tm->{"is_dst"} // -1
l!l
00
MC/DC0%0/1
$tm->{"sec"} // 0
$tm->{"sec"}
MC/DC0%0/1
$tm->{"min"} // 0
$tm->{"min"}
MC/DC0%0/1
$tm->{"hour"} // 0
$tm->{"hour"}
MC/DC0%0/1
$tm->{"wday"} // -1
$tm->{"wday"}
MC/DC0%0/1
$tm->{"yday"} // -1
$tm->{"yday"}
MC/DC0%0/1
$tm->{"is_dst"} // -1
$tm->{"is_dst"}
Truth table0%0/2
A
A= $tm->{"sec"}
Aresult
11
00
Truth table0%0/2
A
A= $tm->{"min"}
Aresult
11
00
Truth table0%0/2
A
A= $tm->{"hour"}
Aresult
11
00
Truth table0%0/2
A
A= $tm->{"wday"}
Aresult
11
00
Truth table0%0/2
A
A= $tm->{"yday"}
Aresult
11
00
Truth table0%0/2
A
A= $tm->{"is_dst"}
Aresult
11
00
51 );
52 }
53  
54 sub _tm_build($@)
55 1 ▶{ my $tm = shift;
Subroutine _tm_build: called CC=1 SCAR=0.0
56 1 @{$tm}{qw/sec min hour day month year wday yday isdst/} = @_;
57 1 $tm->{month}++;
58 1 $tm->{year} += 1900;
59 1 $tm;
60 }
61  
62 sub mktime(@)
63 0 ▶{ my @p;
Subroutine mktime: not called CC=3 SCAR=24.8
Pod documented
64  
65 my $time;
66 0 ▶ if(@_==1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
67 0 { my $tm = shift;
68 0 ($time, my @t) = _mktime _tm_flatten $tm;
69 0 ▶ _tm_build $tm, @t if defined $time; # All fields may have changed
Branch: 1 branch
BranchTrueFalseTotal
if defined $time 0 0 0
70 }
71 else
72 0 { ($time) = _mktime @_;
73 }
74  
75 0 $time;
76 }
77  
78  
79 sub strftime($@)
80 1 ▶{ my $fmt = shift;
Subroutine strftime: called CC=6 SCAR=23.5
Pod documented
81 1 ▶ local @_ = _tm_flatten $_[0] if @_==1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 1 1
82  
83 #XXX See https://github.com/abeltje/lc_time for the correct implementation,
84 # using nl_langinfo(CODESET)
85  
86 1 my $lc = setlocale LC_TIME;
87 1 ▶ if($lc && $lc =~ m/\.([\w-]+)/ && (my $enc = find_encoding $1))
Branch: 1 branch
BranchTrueFalseTotal
if ($lc and $lc =~ /\.([\w-]+)/ and my $enc = &find_encoding($1)) 0 1 1
Condition33%2/6
$lc and $lc =~ /\.([\w-]+)/ and my $enc = &find_encoding($1)
!ll&&!rl&&r
100
$lc and $lc =~ /\.([\w-]+)/
!ll&&!rl&&r
010
MC/DC0%0/3
$lc and $lc =~ /\.([\w-]+)/ and my $enc = &find_encoding($1)
$lc $lc =~ /\.([\w-]+)/ my $enc = &find_encoding($1)
Truth table25%1/4
A and B and C
A= $lcB= $lc =~ /\.([\w-]+)/C= my $enc = &find_encoding($1)
ABCresult
0XX0
10X0
1100
1111
88 { # enforce the format string (may contain any text) to the same
89 # charset as the locale is using.
90 0 my $rawfmt = $enc->encode($fmt);
91 0 return $enc->decode(_strftime($rawfmt, @_));
92 }
93  
94 1 ▶ if(is_utf8($fmt))
Branch: 1 branch
BranchTrueFalseTotal
if (&is_utf8($fmt)) 0 1 1
95 { # no charset in locale, hence ascii inserts
96 0 my $out = _strftime(encode($fmt, 'utf8'), @_);
97 0 return decode $out, 'utf8';
98 }
99  
100 # don't know about the charset
101 1 _strftime($fmt, @_);
102 }
103  
104  
105  
106 sub strptime($$)
107 2 ▶{ return _strptime @_
Subroutine strptime: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 1 1 2
108 if wantarray;
109  
110 1 my $tm = {};
111 1 _tm_build $tm, _strptime @_;
112 }
113  
114  
115 sub _create_constant($)
116 1 ▶{ my ($class, $name) = @_;
Subroutine _create_constant: called CC=1 SCAR=0.2
117 1 my $val = $time->{$name};
118 0 ▶ sub () {$val};
Subroutine __ANON__: not called CC=1 SCAR=1.2
119 }
120  
121 5 1;
« blib/lib/POSIX/1003/Limit.pm ↑ Summary blib/lib/POSIX/1003/FS.pm »