Filename | /usr/share/perl5/DateTime/TimeZone/Local.pm |
Statements | Executed 19 statements in 1.52ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 29µs | 39µs | BEGIN@3 | DateTime::TimeZone::Local::
1 | 1 | 1 | 19µs | 56µs | BEGIN@4 | DateTime::TimeZone::Local::
1 | 1 | 1 | 18µs | 18µs | BEGIN@10 | DateTime::TimeZone::Local::
1 | 1 | 1 | 16µs | 81µs | BEGIN@6 | DateTime::TimeZone::Local::
1 | 1 | 1 | 11µs | 11µ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 | 53µs | 2 | 48µs | # spent 39µs (29+9) within DateTime::TimeZone::Local::BEGIN@3 which was called:
# once (29µs+9µs) by DateTime::TimeZone::BEGIN@12 at line 3 # spent 39µs making 1 call to DateTime::TimeZone::Local::BEGIN@3
# spent 9µs making 1 call to strict::import |
4 | 3 | 53µs | 2 | 92µs | # spent 56µs (19+36) within DateTime::TimeZone::Local::BEGIN@4 which was called:
# once (19µs+36µs) by DateTime::TimeZone::BEGIN@12 at line 4 # spent 56µs making 1 call to DateTime::TimeZone::Local::BEGIN@4
# spent 36µs making 1 call to warnings::import |
5 | |||||
6 | 3 | 107µs | 2 | 145µs | # spent 81µs (16+64) within DateTime::TimeZone::Local::BEGIN@6 which was called:
# once (16µs+64µs) by DateTime::TimeZone::BEGIN@12 at line 6 # spent 81µs making 1 call to DateTime::TimeZone::Local::BEGIN@6
# spent 64µs making 1 call to vars::import |
7 | 1 | 2µs | $VERSION = '0.01'; | ||
8 | |||||
9 | 3 | 47µs | 1 | 11µs | # spent 11µs within DateTime::TimeZone::Local::BEGIN@9 which was called:
# once (11µs+0s) by DateTime::TimeZone::BEGIN@12 at line 9 # spent 11µs making 1 call to DateTime::TimeZone::Local::BEGIN@9 |
10 | 3 | 701µs | 1 | 18µs | # spent 18µs within DateTime::TimeZone::Local::BEGIN@10 which was called:
# once (18µs+0s) by DateTime::TimeZone::BEGIN@12 at line 10 # spent 18µ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 | 549µ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 | 12µs | 1; | ||
98 | |||||
99 | __END__ |