line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
54397
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
161
|
|
2
|
4
|
|
|
4
|
|
25
|
use warnings; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
186
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package DateTime::TimeZone::HPUX; |
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
25
|
use Carp qw/carp croak/; |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
4070
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.04'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @JAVA_HOMES = ( |
11
|
|
|
|
|
|
|
'/opt/java1.4', |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
{ |
15
|
|
|
|
|
|
|
my $_java_bin; |
16
|
|
|
|
|
|
|
sub _java_bin |
17
|
|
|
|
|
|
|
{ |
18
|
2
|
100
|
|
2
|
|
28
|
return $_java_bin if defined $_java_bin; |
19
|
1
|
|
|
|
|
2
|
$_java_bin = ''; # Default value: java not found (false) |
20
|
1
|
50
|
|
|
|
5
|
foreach ( |
21
|
1
|
|
|
|
|
24
|
(map { ("$_/jre/bin/java", "$_/bin/java") } |
|
7
|
|
|
|
|
15
|
|
22
|
|
|
|
|
|
|
(exists $ENV{JAVA_HOME} ? ($ENV{JAVA_HOME}) : ()), |
23
|
|
|
|
|
|
|
@JAVA_HOMES, |
24
|
|
|
|
|
|
|
), |
25
|
|
|
|
|
|
|
(map { "$_/java" } split(/:/, $ENV{PATH}) ), |
26
|
|
|
|
|
|
|
) { |
27
|
9
|
50
|
|
|
|
157
|
next unless -x "$_"; |
28
|
0
|
|
|
|
|
0
|
$_java_bin = $_; |
29
|
0
|
|
|
|
|
0
|
last; |
30
|
|
|
|
|
|
|
} |
31
|
1
|
|
|
|
|
4
|
return $_java_bin; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
{ |
37
|
|
|
|
|
|
|
my $_classes_dir; |
38
|
|
|
|
|
|
|
sub _olson_from_java |
39
|
|
|
|
|
|
|
{ |
40
|
2
|
|
|
2
|
|
4
|
my $name; |
41
|
2
|
|
|
|
|
6
|
my $java_bin = _java_bin(); |
42
|
2
|
50
|
66
|
|
|
10
|
if (@_ && $_[0]) { |
43
|
1
|
|
|
|
|
2
|
$name = $_[0]; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Set the Java environment |
47
|
2
|
100
|
|
|
|
5
|
unless (defined $_classes_dir) { |
48
|
1
|
|
|
|
|
2
|
my $pm = __PACKAGE__.".pm"; |
49
|
1
|
|
|
|
|
4
|
$pm =~ s!::!/!g; |
50
|
1
|
|
|
|
|
3
|
$pm = $INC{$pm}; |
51
|
1
|
|
|
|
|
1
|
$_classes_dir = $pm; |
52
|
1
|
|
|
|
|
6
|
$_classes_dir =~ s/\.pm$//; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
2
|
50
|
|
|
|
60
|
unless (-r "$_classes_dir/TZ.class") { |
56
|
0
|
|
|
|
|
0
|
carp "Java class '$_classes_dir/TZ.class' not found."; |
57
|
0
|
|
|
|
|
0
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
2
|
50
|
|
|
|
6
|
unless ($java_bin) { |
60
|
2
|
|
|
|
|
343
|
carp "Java not found."; |
61
|
2
|
|
|
|
|
8
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
my $olson; |
65
|
|
|
|
|
|
|
# Run the JVM to extract the mapping |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
|
|
0
|
local $ENV{TZ}; |
|
0
|
|
|
|
|
0
|
|
68
|
0
|
0
|
|
|
|
0
|
$ENV{TZ} = $name if defined $name; |
69
|
0
|
|
|
|
|
0
|
$olson = qx!"$java_bin" -cp "$_classes_dir" TZ!; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
# Java returns "GMT" for unknown timezones |
72
|
0
|
0
|
|
|
|
0
|
return undef unless $olson =~ m!/!; |
73
|
0
|
|
|
|
|
0
|
chomp $olson; |
74
|
0
|
|
|
|
|
0
|
return $olson; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Returns undef on failure, no exception |
80
|
|
|
|
|
|
|
sub _hpux_to_olson |
81
|
|
|
|
|
|
|
{ |
82
|
1
|
|
|
1
|
|
3
|
my $tz = shift; |
83
|
1
|
|
|
|
|
1
|
local $@; |
84
|
1
|
|
|
|
|
2
|
eval { require 'DateTime/TimeZone/HPUX/Map.pm' }; |
|
1
|
|
|
|
|
835
|
|
85
|
1
|
50
|
|
|
|
5
|
return undef if $@; |
86
|
1
|
|
|
|
|
1
|
my $tz_name; |
87
|
1
|
50
|
|
|
|
4
|
if (exists $DateTime::TimeZone::HPUX::Map::tz_map{$tz}) { |
88
|
0
|
|
|
|
|
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
|
50
|
|
|
|
8
|
if ($tz =~ /^([A-Z]{3,})(-?)([1-9]?\d(?::(\d{2}))?)(#\w+)?$/) { |
94
|
|
|
|
|
|
|
# Note that GMT+5 gives -0500 as it is how HP-UX handles it |
95
|
0
|
|
|
|
|
0
|
my ($name, $sign, $offset) = ($1, $2, $3); |
96
|
0
|
0
|
|
|
|
0
|
$offset = '0' . $offset if length $offset < 2; |
97
|
0
|
0
|
|
|
|
0
|
$offset .= '00' if length $offset == 2; |
98
|
|
|
|
|
|
|
# Build a TZ with DT::TZ::OffsetOnly |
99
|
|
|
|
|
|
|
# Signs are reversed |
100
|
0
|
0
|
|
|
|
0
|
$tz_name = ($sign eq '-' ? '+' : '-') . $offset; |
101
|
|
|
|
|
|
|
} else { |
102
|
1
|
|
|
|
|
349
|
carp("unknown timezone '$tz', trying to resolve it with Java (SLOOOOOW...)"); |
103
|
1
|
|
|
|
|
5
|
$tz_name = _olson_from_java($tz); |
104
|
|
|
|
|
|
|
} |
105
|
1
|
50
|
|
|
|
4
|
if (defined $tz_name) { |
106
|
|
|
|
|
|
|
# Add to the cache |
107
|
0
|
|
|
|
|
0
|
$DateTime::TimeZone::HPUX::Map::tz_map{$tz} = $tz_name; |
108
|
|
|
|
|
|
|
} else { |
109
|
1
|
|
|
|
|
4
|
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) }; |
|
0
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Raise an exception on failure, like DateTime::TimeZone |
121
|
|
|
|
|
|
|
sub new |
122
|
|
|
|
|
|
|
{ |
123
|
0
|
|
|
0
|
1
|
|
my %options = @_; |
124
|
0
|
0
|
|
|
|
|
croak("Missing 'name' argument") unless exists $options{name}; |
125
|
0
|
|
|
|
|
|
my $name = $options{name}; |
126
|
0
|
0
|
|
|
|
|
if ($name eq 'local') { |
127
|
0
|
|
|
|
|
|
return DateTime::TimeZone->new(%options); |
128
|
|
|
|
|
|
|
} else { |
129
|
0
|
|
|
|
|
|
my $tz = _hpux_to_olson($name); |
130
|
0
|
0
|
|
|
|
|
croak("unknown timezone '$tz'") unless defined $tz; |
131
|
0
|
|
|
|
|
|
return $tz; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
__END__ |