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