Filename | /usr/share/perl5/DateTime/TimeZone/Local.pm |
Statements | Executed 14 statements in 2.00ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 3.84ms | 4.69ms | BEGIN@8 | DateTime::TimeZone::Local::
1 | 1 | 1 | 1.76ms | 20.4ms | BEGIN@6 | DateTime::TimeZone::Local::
1 | 1 | 1 | 12µs | 24µs | BEGIN@3 | DateTime::TimeZone::Local::
1 | 1 | 1 | 8µs | 8µs | BEGIN@7 | DateTime::TimeZone::Local::
1 | 1 | 1 | 7µs | 11µs | BEGIN@4 | DateTime::TimeZone::Local::
0 | 0 | 0 | 0s | 0s | FromEnv | DateTime::TimeZone::Local::
0 | 0 | 0 | 0s | 0s | TimeZone | DateTime::TimeZone::Local::
0 | 0 | 0 | 0s | 0s | _IsValidName | DateTime::TimeZone::Local::
0 | 0 | 0 | 0s | 0s | _load_subclass | DateTime::TimeZone::Local::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package DateTime::TimeZone::Local; | ||||
2 | 1 | 500ns | $DateTime::TimeZone::Local::VERSION = '1.75'; | ||
3 | 2 | 25µs | 2 | 36µs | # spent 24µs (12+12) within DateTime::TimeZone::Local::BEGIN@3 which was called:
# once (12µs+12µs) by DateTime::TimeZone::BEGIN@12 at line 3 # spent 24µs making 1 call to DateTime::TimeZone::Local::BEGIN@3
# spent 12µs making 1 call to strict::import |
4 | 2 | 26µs | 2 | 16µs | # spent 11µs (7+4) within DateTime::TimeZone::Local::BEGIN@4 which was called:
# once (7µs+4µs) by DateTime::TimeZone::BEGIN@12 at line 4 # spent 11µs making 1 call to DateTime::TimeZone::Local::BEGIN@4
# spent 4µs making 1 call to warnings::import |
5 | |||||
6 | 2 | 740µs | 2 | 20.5ms | # spent 20.4ms (1.76+18.7) within DateTime::TimeZone::Local::BEGIN@6 which was called:
# once (1.76ms+18.7ms) by DateTime::TimeZone::BEGIN@12 at line 6 # spent 20.4ms making 1 call to DateTime::TimeZone::Local::BEGIN@6
# spent 37µs making 1 call to Exporter::import |
7 | 2 | 23µs | 1 | 8µs | # spent 8µs within DateTime::TimeZone::Local::BEGIN@7 which was called:
# once (8µs+0s) by DateTime::TimeZone::BEGIN@12 at line 7 # spent 8µs making 1 call to DateTime::TimeZone::Local::BEGIN@7 |
8 | 2 | 1.18ms | 1 | 4.69ms | # spent 4.69ms (3.84+849µs) within DateTime::TimeZone::Local::BEGIN@8 which was called:
# once (3.84ms+849µs) by DateTime::TimeZone::BEGIN@12 at line 8 # spent 4.69ms making 1 call to DateTime::TimeZone::Local::BEGIN@8 |
9 | |||||
10 | sub TimeZone { | ||||
11 | my $class = shift; | ||||
12 | |||||
13 | my $subclass = $class->_load_subclass(); | ||||
14 | |||||
15 | for my $meth ( $subclass->Methods() ) { | ||||
16 | my $tz = $subclass->$meth(); | ||||
17 | |||||
18 | return $tz if $tz; | ||||
19 | } | ||||
20 | |||||
21 | die "Cannot determine local time zone\n"; | ||||
22 | } | ||||
23 | |||||
24 | { | ||||
25 | # Stolen from File::Spec. My theory is that other folks can write | ||||
26 | # the non-existent modules if they feel a need, and release them | ||||
27 | # to CPAN separately. | ||||
28 | 2 | 5µs | my %subclass = ( | ||
29 | MSWin32 => 'Win32', | ||||
30 | VMS => 'VMS', | ||||
31 | MacOS => 'Mac', | ||||
32 | os2 => 'OS2', | ||||
33 | epoc => 'Epoc', | ||||
34 | NetWare => 'Win32', | ||||
35 | symbian => 'Win32', | ||||
36 | dos => 'OS2', | ||||
37 | android => 'Android', | ||||
38 | cygwin => 'Unix', | ||||
39 | ); | ||||
40 | |||||
41 | sub _load_subclass { | ||||
42 | my $class = shift; | ||||
43 | |||||
44 | my $os_name = $subclass{$^O} || $^O; | ||||
45 | my $subclass = $class . '::' . $os_name; | ||||
46 | |||||
47 | return $subclass if is_class_loaded($subclass); | ||||
48 | |||||
49 | return $subclass if try_load_class($subclass); | ||||
50 | |||||
51 | $subclass = $class . '::Unix'; | ||||
52 | |||||
53 | load_class($subclass); | ||||
54 | |||||
55 | return $subclass; | ||||
56 | } | ||||
57 | } | ||||
58 | |||||
59 | sub FromEnv { | ||||
60 | my $class = shift; | ||||
61 | |||||
62 | foreach my $var ( $class->EnvVars() ) { | ||||
63 | if ( $class->_IsValidName( $ENV{$var} ) ) { | ||||
64 | my $tz; | ||||
65 | { | ||||
66 | local $@; | ||||
67 | local $SIG{__DIE__}; | ||||
68 | $tz = eval { DateTime::TimeZone->new( name => $ENV{$var} ) }; | ||||
69 | } | ||||
70 | return $tz if $tz; | ||||
71 | } | ||||
72 | } | ||||
73 | |||||
74 | return; | ||||
75 | } | ||||
76 | |||||
77 | sub _IsValidName { | ||||
78 | shift; | ||||
79 | |||||
80 | return 0 unless defined $_[0]; | ||||
81 | return 0 if $_[0] eq 'local'; | ||||
82 | |||||
83 | return $_[0] =~ m{^[\w/\-\+]+$}; | ||||
84 | } | ||||
85 | |||||
86 | 1 | 4µs | 1; | ||
87 | |||||
88 | # ABSTRACT: Determine the local system's time zone | ||||
89 | |||||
90 | __END__ |