DateTimeX/Lite/TimeZone/Local/Unix.pm

filter: Statementstmt 14.1% 15 / 106 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 39 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 40.0% 6 / 15 Podpod 28.5% 2 / 7 totaltotal 9.4% 23 / 243 CC 42 SCAR 38.0
CC
42
Cov
8%
FromEtcLocaltime
110.0
__ANON__
56.0
FromEtcTIMEZONE
56.0
CRAP 44.8
« DateTimeX/Lite/OlsonDB.pm ↑ Summary DateTimeX/Lite/LeapSecond.pm »
1 package DateTimeX::Lite::TimeZone::Local::Unix;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use base 'DateTimeX::Lite::TimeZone::Local';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 sub Methods
10 539 ▶{
Subroutine Methods: called CC=1 SCAR=0.0
Pod documented
11 539 return qw( FromEnv
12 FromEtcLocaltime
13 FromEtcTimezone
14 FromEtcTIMEZONE
15 FromEtcSysconfigClock
16 FromEtcDefaultInit
17 );
18 }
19  
20 543 ▶sub EnvVars { return 'TZ' }
Subroutine EnvVars: called CC=1 SCAR=0.0
Pod documented
21  
22 sub FromEtcLocaltime
23 0 ▶{
Subroutine FromEtcLocaltime: not called CC=10 SCAR=47.0
Pod undocumented
24 0 my $class = shift;
25  
26 0 my $lt_file = '/etc/localtime';
27  
28 0 ▶ return unless -r $lt_file && -s _;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $lt_file and -s _ 0 0 0
Condition0%0/3
-r $lt_file and -s _
!ll&&!rl&&r
000
MC/DC0%0/2
-r $lt_file and -s _
-r $lt_file -s _
Truth table0%0/3
A and B
A= -r $lt_fileB= -s _
ABresult
0X0
100
111
29  
30 0 my $real_name;
31 0 ▶ if ( -l $lt_file )
Branch: 1 branch
BranchTrueFalseTotal
if (-l $lt_file) 0 0 0
32 {
33 # The _Readlink sub exists so the test suite can mock it.
34 0 $real_name = $class->_Readlink( $lt_file );
35 }
36  
37 0 ▶ $real_name ||= $class->_FindMatchingZoneinfoFile( $lt_file );
Condition0%0/3
$real_name ||= $class->_FindMatchingZoneinfoFile($lt_file)
l!l&&r!l&&!r
000
MC/DC0%0/2
$real_name ||= $class->_FindMatchingZoneinfoFile($lt_file)
$real_name $class->_FindMatchingZoneinfoFile($lt_file)
Truth table0%0/3
A ||= B
A= $real_nameB= $class->_FindMatchingZoneinfoFile($lt_file)
ABresult
1X1
011
000
38  
39 0 ▶ if ( defined $real_name )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $real_name) 0 0 0
40 {
41 0 my ( $vol, $dirs, $file ) = File::Spec->splitpath( $real_name );
42  
43 my @parts =
44 0 ▶ grep { defined && length } File::Spec->splitdir( $dirs ), $file;
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
45  
46 0 foreach my $x ( reverse 0..$#parts )
47 {
48 0 ▶ my $name =
Branch: 1 branch
BranchTrueFalseTotal
$x < $#parts ? : 0 0 0
49 ( $x < $#parts ?
50 join '/', @parts[$x..$#parts] :
51 $parts[$x]
52 );
53  
54 0 my $tz;
55 {
56 0 local $@;
57 0 $tz = eval { DateTimeX::Lite::TimeZone->load( name => $name ) };
58 }
59  
60 0 ▶ return $tz if $tz;
Branch: 1 branch
BranchTrueFalseTotal
if $tz 0 0 0
61 }
62 }
63 }
64  
65 sub _Readlink
66 1 ▶{
Subroutine _Readlink: called CC=1 SCAR=0.0
67 1 my $link = $_[1];
68  
69 1 require Cwd;
70 # Using abs_path will resolve multiple levels of link indirection,
71 # whereas readlink just follows the link to the next target.
72 1 return Cwd::abs_path($link);
73 }
74  
75 # for systems where /etc/localtime is a copy of a zoneinfo file
76 sub _FindMatchingZoneinfoFile
77 0 ▶{
Subroutine _FindMatchingZoneinfoFile: not called CC=5 SCAR=34.0
78 0 my $class = shift;
79 0 my $file_to_match = shift;
80  
81 0 ▶ return unless -d '/usr/share/zoneinfo';
Branch: 1 branch
BranchTrueFalseTotal
unless -d "/usr/share/zoneinfo" 0 0 0
82  
83 0 require File::Basename;
84 0 require File::Compare;
85 0 require File::Find;
86  
87 0 my $size = -s $file_to_match;
88  
89 0 my $real_name;
90 0 local $@;
91 0 local $_;
92 eval
93 0 {
94 0 local $SIG{__DIE__};
95 File::Find::find
96 ( { wanted =>
97 sub
98 0 ▶ {
Subroutine __ANON__: not called CC=7 SCAR=40.3
99 0 ▶ if ( ! defined $real_name
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $real_name and -f $_ and not -l $_ and $size == -s _ and File::Basename::basename($_) ne "posixrules" and File::Compare::compare($_, $file_to_match) == 0) 0 0 0
Condition0%0/15
not defined $real_name and -f $_ and not -l $_ and $size == -s _ and File::Basename::basename($_) ne "posixrules" and File::Compare::compare($_, $file_to_match) == 0
!ll&&!rl&&r
000
not defined $real_name and -f $_ and not -l $_ and $size == -s _ and File::Basename::basename($_) ne "posixrules"
!ll&&!rl&&r
000
not defined $real_name and -f $_ and not -l $_ and $size == -s _
!ll&&!rl&&r
000
not defined $real_name and -f $_ and not -l $_
!ll&&!rl&&r
000
not defined $real_name and -f $_
!ll&&!rl&&r
000
MC/DC0%0/6
not defined $real_name and -f $_ and not -l $_ and $size == -s _ and File::Basename::basename($_) ne "posixrules" and File::Compare::compare($_, $file_to_match) == 0
not defined $real_name -f $_ not -l $_ $size == -s _ File::Basename::basename($_) ne "posixrules" File::Compare::compare($_, $file_to_match) == 0
Truth table0%0/7
not(A) and B and not(C) and D and E and F
A= not defined $real_nameB= -f $_C= not -l $_D= $size == -s _E= File::Basename::basename($_) ne "posixrules"F= File::Compare::compare($_, $file_to_match) == 0
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
100 && -f $_
101 && ! -l $_
102 && $size == -s _
103 # This fixes RT 24026 - apparently such a
104 # file exists on FreeBSD and it can cause a
105 # false positive
106 && File::Basename::basename($_) ne 'posixrules'
107 && File::Compare::compare( $_, $file_to_match ) == 0
108 )
109 {
110 0 $real_name = $_;
111  
112 # File::Find has no mechanism for bailing in the
113 # middle of a find.
114 0 die { found => 1 };
115 }
116 },
117 0 no_chdir => 1,
118 },
119 '/usr/share/zoneinfo',
120 );
121 };
122  
123 0 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
124 {
125 0 ▶ return $real_name if ref $@ && $@->{found};
Branch: 1 branch
BranchTrueFalseTotal
if ref $@ and $@->{"found"} 0 0 0
Condition0%0/3
ref $@ and $@->{"found"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $@ and $@->{"found"}
ref $@ $@->{"found"}
Truth table0%0/3
A and B
A= ref $@B= $@->{"found"}
ABresult
0X0
100
111
126 0 die $@;
127 }
128 }
129  
130 sub FromEtcTimezone
131 0 ▶{
Subroutine FromEtcTimezone: not called CC=5 SCAR=34.0
Pod undocumented
132 0 my $class = shift;
133  
134 0 my $tz_file = '/etc/timezone';
135  
136 0 ▶ return unless -f $tz_file && -r _;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $tz_file and -r _ 0 0 0
Condition0%0/3
-f $tz_file and -r _
!ll&&!rl&&r
000
MC/DC0%0/2
-f $tz_file and -r _
-f $tz_file -r _
Truth table0%0/3
A and B
A= -f $tz_fileB= -r _
ABresult
0X0
100
111
137  
138 0 local *TZ;
139 0 ▶ open TZ, "<$tz_file"
Branch: 1 branch
BranchTrueFalseTotal
open TZ, "<$tz_file" or die "Cannot read ${tz_file}: $!" 0 0 0
140 or die "Cannot read $tz_file: $!";
141 0 my $name = join '', <TZ>;
142 0 close TZ;
143  
144 0 $name =~ s/^\s+|\s+$//g;
145  
146 0 ▶ return unless $class->_IsValidName($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $class->_IsValidName($name) 0 0 0
147  
148 0 local $@;
149 0 return eval { DateTimeX::Lite::TimeZone->load( name => $name ) };
150 }
151  
152 sub FromEtcTIMEZONE
153 0 ▶{
Subroutine FromEtcTIMEZONE: not called CC=7 SCAR=40.3
Pod undocumented
154 0 my $class = shift;
155  
156 0 my $tz_file = '/etc/TIMEZONE';
157  
158 0 ▶ return unless -f $tz_file && -r _;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $tz_file and -r _ 0 0 0
Condition0%0/3
-f $tz_file and -r _
!ll&&!rl&&r
000
MC/DC0%0/2
-f $tz_file and -r _
-f $tz_file -r _
Truth table0%0/3
A and B
A= -f $tz_fileB= -r _
ABresult
0X0
100
111
159  
160 0 local *TZ;
161 0 ▶ open TZ, "<$tz_file"
Branch: 1 branch
BranchTrueFalseTotal
open TZ, "<$tz_file" or die "Cannot read ${tz_file}: $!" 0 0 0
162 or die "Cannot read $tz_file: $!";
163  
164 0 my $name;
165 0 ▶ while ( defined( $name = <TZ> ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($name = readline TZ)) 0 0 0
166 {
167 0 ▶ if ( $name =~ /\A\s*TZ\s*=\s*(\S+)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\A\s*TZ\s*=\s*(\S+)/) 0 0 0
168 {
169 0 $name = $1;
170 0 last;
171 }
172 }
173  
174 0 close TZ;
175  
176 0 ▶ return unless $class->_IsValidName($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $class->_IsValidName($name) 0 0 0
177  
178 0 local $@;
179 0 return eval { DateTimeX::Lite::TimeZone->load( name => $name ) };
180 }
181  
182 # RedHat uses this
183 sub FromEtcSysconfigClock
184 0 ▶{
Subroutine FromEtcSysconfigClock: not called CC=4 SCAR=30.0
Pod undocumented
185 0 my $class = shift;
186  
187 0 ▶ return unless -r "/etc/sysconfig/clock" && -f _;
Branch: 1 branch
BranchTrueFalseTotal
unless -r "/etc/sysconfig/clock" and -f _ 0 0 0
Condition0%0/3
-r "/etc/sysconfig/clock" and -f _
!ll&&!rl&&r
000
MC/DC0%0/2
-r "/etc/sysconfig/clock" and -f _
-r "/etc/sysconfig/clock" -f _
Truth table0%0/3
A and B
A= -r "/etc/sysconfig/clock"B= -f _
ABresult
0X0
100
111
188  
189 0 my $name = $class->_ReadEtcSysconfigClock();
190  
191 0 ▶ return unless $class->_IsValidName($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $class->_IsValidName($name) 0 0 0
192  
193 0 local $@;
194 0 return eval { DateTimeX::Lite::TimeZone->load( name => $name ) };
195 }
196  
197 # this is a sparate function so that it can be overridden in the test
198 # suite
199 sub _ReadEtcSysconfigClock
200 0 ▶{
Subroutine _ReadEtcSysconfigClock: not called CC=4 SCAR=30.0
201 0 my $class = shift;
202  
203 0 local *CLOCK;
204 0 ▶ open CLOCK, '</etc/sysconfig/clock'
Branch: 1 branch
BranchTrueFalseTotal
open CLOCK, "</etc/sysconfig/clock" or die "Cannot read /etc/sysconfig/clock: $!" 0 0 0
205 or die "Cannot read /etc/sysconfig/clock: $!";
206  
207 0 local $_;
208 0 ▶ while (<CLOCK>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline CLOCK)) 0 0 0
209 {
210 0 ▶ return $1 if /^(?:TIME)?ZONE="([^"]+)"/;
Branch: 1 branch
BranchTrueFalseTotal
if /^(?:TIME)?ZONE="([^"]+)"/ 0 0 0
211 }
212 }
213  
214 sub FromEtcDefaultInit
215 0 ▶{
Subroutine FromEtcDefaultInit: not called CC=4 SCAR=30.0
Pod undocumented
216 0 my $class = shift;
217  
218 0 ▶ return unless -r "/etc/default/init" && -f _;
Branch: 1 branch
BranchTrueFalseTotal
unless -r "/etc/default/init" and -f _ 0 0 0
Condition0%0/3
-r "/etc/default/init" and -f _
!ll&&!rl&&r
000
MC/DC0%0/2
-r "/etc/default/init" and -f _
-r "/etc/default/init" -f _
Truth table0%0/3
A and B
A= -r "/etc/default/init"B= -f _
ABresult
0X0
100
111
219  
220 0 my $name = $class->_ReadEtcDefaultInit();
221  
222 0 ▶ return unless $class->_IsValidName($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $class->_IsValidName($name) 0 0 0
223  
224 0 local $@;
225 0 return eval { DateTimeX::Lite::TimeZone->load( name => $name ) };
226 }
227  
228 # this is a separate function so that it can be overridden in the test
229 # suite
230 sub _ReadEtcDefaultInit
231 0 ▶{
Subroutine _ReadEtcDefaultInit: not called CC=4 SCAR=30.0
232 0 my $class = shift;
233  
234 0 local *INIT;
235 0 ▶ open INIT, '</etc/default/init'
Branch: 1 branch
BranchTrueFalseTotal
open INIT, "</etc/default/init" or die "Cannot read /etc/default/init: $!" 0 0 0
236 or die "Cannot read /etc/default/init: $!";
237  
238 0 local $_;
239 0 ▶ while (<INIT>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline INIT)) 0 0 0
240 {
241 0 ▶ return $1 if /^TZ=(.+)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^TZ=(.+)/ 0 0 0
242 }
243 }
244  
245  
246 1 1;
247  
248 __END__
« DateTimeX/Lite/OlsonDB.pm ↑ Summary DateTimeX/Lite/LeapSecond.pm »