line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::ZoneInfo; |
2
|
1
|
|
|
1
|
|
5796
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
3
|
1
|
|
|
1
|
|
5
|
use vars qw/$VERSION/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
4
|
|
|
|
|
|
|
$VERSION = '0.3'; |
5
|
1
|
|
|
1
|
|
924
|
use IO::File; |
|
1
|
|
|
|
|
12368
|
|
|
1
|
|
|
|
|
804
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$Time::ZoneInfo::ERROR = ""; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
1
|
|
|
1
|
1
|
81
|
my ($class, @params) = @_; |
11
|
1
|
|
33
|
|
|
9
|
my $this = bless {}, ref($class) || $class; |
12
|
1
|
50
|
|
|
|
5
|
return undef unless ($this->init(@params)); |
13
|
1
|
|
|
|
|
9
|
return $this; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub init { |
17
|
1
|
|
|
1
|
0
|
4
|
my ($this, %params) = @_; |
18
|
|
|
|
|
|
|
# Read in and process the /usr/share/zoneinfo/zone.tab file |
19
|
|
|
|
|
|
|
# Create a REGIONS array (only region part) and ZONES (full part) |
20
|
1
|
|
|
|
|
2
|
my (@zones, %regions, $zone); |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
50
|
|
|
7
|
my $filename = $params{zonetab} || "/usr/share/zoneinfo/zone.tab"; |
23
|
1
|
|
|
|
|
11
|
my $fh = new IO::File; |
24
|
1
|
|
|
|
|
52
|
$fh->open($filename); |
25
|
1
|
50
|
|
|
|
85
|
if (!defined($fh)) { |
26
|
0
|
|
|
|
|
0
|
$Time::ZoneInfo::ERROR = "Can't find file ($filename) - $!"; |
27
|
0
|
|
|
|
|
0
|
return 0; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
33
|
while(my $line = <$fh>) { |
31
|
452
|
|
|
|
|
497
|
chomp $line; |
32
|
452
|
100
|
|
|
|
1045
|
next if ($line =~ /^\s*#/); |
33
|
416
|
50
|
|
|
|
1014
|
next if ($line =~ /^\s*$/); |
34
|
416
|
|
|
|
|
492
|
$line =~ s/#.*$//; |
35
|
416
|
50
|
|
|
|
1810
|
if ($line =~ /^[^#](\S+)\s*\t\s*(\S+)\s*\t\s*(\S+)\s*(\t|$)/) { |
36
|
416
|
|
|
|
|
783
|
$zone = $3; |
37
|
416
|
50
|
|
|
|
1478
|
if ($zone =~ m|^(.+?)/(.+)$|) { |
38
|
416
|
|
|
|
|
717
|
$regions{$1}++; |
39
|
|
|
|
|
|
|
} |
40
|
416
|
|
|
|
|
1545
|
push @zones, $zone; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
1
|
|
|
|
|
41
|
$this->{REGIONS} = [keys %regions]; |
44
|
1
|
|
|
|
|
7
|
$this->{ZONES} = \@zones; |
45
|
1
|
|
|
|
|
34
|
return 1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub regions { |
49
|
1
|
|
|
1
|
1
|
717
|
my ($this) = @_; |
50
|
1
|
50
|
|
|
|
5
|
return wantarray ? @{$this->{REGIONS}} : $this->{REGIONS}; |
|
1
|
|
|
|
|
11
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub zones { |
54
|
11
|
|
|
11
|
1
|
575
|
my ($this, $region) = @_; |
55
|
11
|
100
|
|
|
|
33
|
return $this->_zones if (!defined($region)); |
56
|
|
|
|
|
|
|
|
57
|
10
|
|
|
|
|
15
|
my @ret = (); |
58
|
10
|
|
|
|
|
23
|
foreach my $zone ($this->_zones) { |
59
|
4160
|
100
|
|
|
|
18248
|
if ($zone =~ m|^$region/|) { |
60
|
416
|
|
|
|
|
725
|
push @ret, $zone; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
10
|
50
|
|
|
|
453
|
return wantarray ? @ret : \@ret; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _zones { |
67
|
11
|
|
|
11
|
|
14
|
my ($this) = @_; |
68
|
11
|
50
|
|
|
|
21
|
return wantarray ? @{$this->{ZONES}} : $this->{ZONES}; |
|
11
|
|
|
|
|
501
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |