HPUX.pm

filter: Statementstmt 62.8% 49 / 78 Branchbran 36.8% 14 / 38 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 56.5% 73 / 129 CC 22 SCAR 25.4
CC
22
Cov
55%
new
20.0
_hpux_to_olson
17.4
_olson_from_java
13.3
CRAP 12.7
↑ Summary Local/hpux.pm »
1 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package DateTime::TimeZone::HPUX;
5  
6 5 ▶use Carp qw/carp croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 our $VERSION = '1.04';
9  
10 5 our @JAVA_HOMES = (
11 '/opt/java1.4',
12 );
13  
14 {
15 5 my $_java_bin;
16 sub _java_bin
17 2 ▶ {
Subroutine _java_bin: called CC=5 SCAR=17.0
18 2 ▶ return $_java_bin if defined $_java_bin;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_java_bin 1 1 2
19 1 $_java_bin = ''; # Default value: java not found (false)
20 1 foreach (
21 1 ▶ (map { ("$_/jre/bin/java", "$_/bin/java") }
Branch: 1 branch
BranchTrueFalseTotal
exists $ENV{'JAVA_HOME'} ? : 0 1 1
22 (exists $ENV{JAVA_HOME} ? ($ENV{JAVA_HOME}) : ()),
23 @JAVA_HOMES,
24 ),
25 10 (map { "$_/java" } split(/:/, $ENV{PATH}) ),
26 ) {
27 12 ▶ next unless -x "$_";
Branch: 1 branch
BranchTrueFalseTotal
unless -x "$_" 12 0 12
28 0 $_java_bin = $_;
29 0 last;
30 }
31 1 return $_java_bin;
32 }
33 }
34  
35  
36 {
37 5 my $_classes_dir;
38 sub _olson_from_java
39 2 ▶{
Subroutine _olson_from_java: called CC=8 SCAR=25.9
40 2 my $name;
41 2 my $java_bin = _java_bin();
42 2 ▶ if (@_ && $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and $_[0]) 1 1 2
Condition66%2/3
@_ and $_[0]
!ll&&!rl&&r
101
MC/DC50%1/2
@_ and $_[0]
@_ $_[0]
Truth table66%2/3
A and B
A= @_B= $_[0]
ABresult
0X0
100
111
43 1 $name = $_[0];
44 }
45  
46 # Set the Java environment
47 2 ▶ unless (defined $_classes_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_classes_dir) 1 1 2
48 1 my $pm = __PACKAGE__.".pm";
49 1 $pm =~ s!::!/!g;
50 1 $pm = $INC{$pm};
51 1 $_classes_dir = $pm;
52 1 $_classes_dir =~ s/\.pm$//;
53 }
54  
55 2 ▶ unless (-r "$_classes_dir/TZ.class") {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r "$_classes_dir/TZ.class") 0 2 2
56 0 carp "Java class '$_classes_dir/TZ.class' not found.";
57 0 return;
58 }
59 2 ▶ unless ($java_bin) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($java_bin) 2 0 2
60 2 carp "Java not found.";
61 2 return;
62 }
63  
64 0 my $olson;
65 # Run the JVM to extract the mapping
66 {
67 0 local $ENV{TZ};
68 0 ▶ $ENV{TZ} = $name if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 0 0
69 0 $olson = qx!"$java_bin" -cp "$_classes_dir" TZ!;
70 }
71 # Java returns "GMT" for unknown timezones
72 0 ▶ return undef unless $olson =~ m!/!;
Branch: 1 branch
BranchTrueFalseTotal
unless $olson =~ m[/] 0 0 0
73 0 chomp $olson;
74 0 return $olson;
75 }
76 }
77  
78  
79 # Returns undef on failure, no exception
80 sub _hpux_to_olson
81 5 ▶{
Subroutine _hpux_to_olson: called CC=8 SCAR=28.6
82 1 my $tz = shift;
83 1 local $@;
84 1 eval { require 'DateTime/TimeZone/HPUX/Map.pm' };
85 1 ▶ return undef if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
86 1 my $tz_name;
87 1 ▶ if (exists $DateTime::TimeZone::HPUX::Map::tz_map{$tz}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $DateTime::TimeZone::HPUX::Map::tz_map{$tz}) { } 0 1 1
88 0 $tz_name = $DateTime::TimeZone::HPUX::Map::tz_map{$tz};
89 } else {
90  
91 # Simple TZ without DST: we can extract reliably an offset
92 # This is less clean than what Java /may/ return, but much more faster!
93 1 ▶ if ($tz =~ /^([A-Z]{3,})(-?)([1-9]?\d(?::(\d{2}))?)(#\w+)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tz =~ /^([A-Z]{3,})(-?)([1-9]?\d(?::(\d{2}))?)(#\w+)?$/) { } 0 1 1
94 # Note that GMT+5 gives -0500 as it is how HP-UX handles it
95 0 my ($name, $sign, $offset) = ($1, $2, $3);
96 0 ▶ $offset = '0' . $offset if length $offset < 2;
Branch: 1 branch
BranchTrueFalseTotal
if length $offset < 2 0 0 0
97 0 ▶ $offset .= '00' if length $offset == 2;
Branch: 1 branch
BranchTrueFalseTotal
if length $offset == 2 0 0 0
98 # Build a TZ with DT::TZ::OffsetOnly
99 # Signs are reversed
100 0 ▶ $tz_name = ($sign eq '-' ? '+' : '-') . $offset;
Branch: 1 branch
BranchTrueFalseTotal
$sign eq '-' ? : 0 0 0
101 } else {
102 1 carp("unknown timezone '$tz', trying to resolve it with Java (SLOOOOOW...)");
103 1 $tz_name = _olson_from_java($tz);
104 }
105 1 ▶ if (defined $tz_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tz_name) { } 0 1 1
106 # Add to the cache
107 0 $DateTime::TimeZone::HPUX::Map::tz_map{$tz} = $tz_name;
108 } else {
109 1 return;
110 }
111 }
112  
113 # Build a DateTime::TimeZone object from a TZ name, catching exceptions
114 # Returns undef if failure.
115 0 local $@;
116 0 return eval { DateTime::TimeZone->new(name => $tz_name) };
117 }
118  
119  
120 # Raise an exception on failure, like DateTime::TimeZone
121 sub new
122 0 ▶{
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
123 0 my %options = @_;
124 0 ▶ croak("Missing 'name' argument") unless exists $options{name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $options{"name"} 0 0 0
125 0 my $name = $options{name};
126 0 ▶ if ($name eq 'local') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'local') { } 0 0 0
127 0 return DateTime::TimeZone->new(%options);
128 } else {
129 0 my $tz = _hpux_to_olson($name);
130 0 ▶ croak("unknown timezone '$tz'") unless defined $tz;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tz 0 0 0
131 0 return $tz;
132 }
133 }
134  
135  
136  
137 5 1;
138 __END__
↑ Summary Local/hpux.pm »