| Filename | /home/s1/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/DateTime/TimeZone/Local.pm |
| Statements | Executed 16 statements in 1.48ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 3.19ms | 4.19ms | DateTime::TimeZone::Local::BEGIN@7 |
| 1 | 1 | 1 | 31µs | 35µs | DateTime::TimeZone::Local::BEGIN@3 |
| 1 | 1 | 1 | 14µs | 22µs | DateTime::TimeZone::Local::BEGIN@4 |
| 1 | 1 | 1 | 14µs | 34µs | DateTime::TimeZone::Local::BEGIN@8 |
| 1 | 1 | 1 | 12µs | 56µs | DateTime::TimeZone::Local::BEGIN@9 |
| 1 | 1 | 1 | 8µs | 8µs | DateTime::TimeZone::Local::BEGIN@6 |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::FromEnv |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::TimeZone |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::_IsValidName |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::__ANON__[:53] |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::__ANON__[:71] |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::_load_subclass |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DateTime::TimeZone::Local; | ||||
| 2 | 1 | 1µs | $DateTime::TimeZone::Local::VERSION = '1.98'; | ||
| 3 | 2 | 38µs | 2 | 39µs | # spent 35µs (31+4) within DateTime::TimeZone::Local::BEGIN@3 which was called:
# once (31µs+4µs) by DateTime::TimeZone::BEGIN@10 at line 3 # spent 35µs making 1 call to DateTime::TimeZone::Local::BEGIN@3
# spent 4µs making 1 call to strict::import |
| 4 | 2 | 32µs | 2 | 29µs | # spent 22µs (14+8) within DateTime::TimeZone::Local::BEGIN@4 which was called:
# once (14µs+8µs) by DateTime::TimeZone::BEGIN@10 at line 4 # spent 22µs making 1 call to DateTime::TimeZone::Local::BEGIN@4
# spent 8µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 2 | 30µs | 1 | 8µs | # spent 8µs within DateTime::TimeZone::Local::BEGIN@6 which was called:
# once (8µs+0s) by DateTime::TimeZone::BEGIN@10 at line 6 # spent 8µs making 1 call to DateTime::TimeZone::Local::BEGIN@6 |
| 7 | 2 | 445µs | 1 | 4.19ms | # spent 4.19ms (3.19+1.00) within DateTime::TimeZone::Local::BEGIN@7 which was called:
# once (3.19ms+1.00ms) by DateTime::TimeZone::BEGIN@10 at line 7 # spent 4.19ms making 1 call to DateTime::TimeZone::Local::BEGIN@7 |
| 8 | 2 | 36µs | 2 | 55µs | # spent 34µs (14+21) within DateTime::TimeZone::Local::BEGIN@8 which was called:
# once (14µs+21µs) by DateTime::TimeZone::BEGIN@10 at line 8 # spent 34µs making 1 call to DateTime::TimeZone::Local::BEGIN@8
# spent 20µs making 1 call to Module::Runtime::import |
| 9 | 2 | 886µs | 2 | 100µs | # spent 56µs (12+44) within DateTime::TimeZone::Local::BEGIN@9 which was called:
# once (12µs+44µs) by DateTime::TimeZone::BEGIN@10 at line 9 # spent 56µs making 1 call to DateTime::TimeZone::Local::BEGIN@9
# spent 44µs making 1 call to Exporter::import |
| 10 | |||||
| 11 | sub TimeZone { | ||||
| 12 | my $class = shift; | ||||
| 13 | |||||
| 14 | my $subclass = $class->_load_subclass(); | ||||
| 15 | |||||
| 16 | for my $meth ( $subclass->Methods() ) { | ||||
| 17 | my $tz = $subclass->$meth(); | ||||
| 18 | |||||
| 19 | return $tz if $tz; | ||||
| 20 | } | ||||
| 21 | |||||
| 22 | die "Cannot determine local time zone\n"; | ||||
| 23 | } | ||||
| 24 | |||||
| 25 | { | ||||
| 26 | # Stolen from File::Spec. My theory is that other folks can write | ||||
| 27 | # the non-existent modules if they feel a need, and release them | ||||
| 28 | # to CPAN separately. | ||||
| 29 | 1 | 8µs | my %subclass = ( | ||
| 30 | MSWin32 => 'Win32', | ||||
| 31 | VMS => 'VMS', | ||||
| 32 | MacOS => 'Mac', | ||||
| 33 | os2 => 'OS2', | ||||
| 34 | epoc => 'Epoc', | ||||
| 35 | NetWare => 'Win32', | ||||
| 36 | symbian => 'Win32', | ||||
| 37 | dos => 'OS2', | ||||
| 38 | android => 'Android', | ||||
| 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 | return $subclass if try { | ||||
| 51 | local $SIG{__DIE__}; | ||||
| 52 | require_module($subclass); | ||||
| 53 | }; | ||||
| 54 | |||||
| 55 | $subclass = $class . '::Unix'; | ||||
| 56 | |||||
| 57 | require_module($subclass); | ||||
| 58 | |||||
| 59 | return $subclass; | ||||
| 60 | } | ||||
| 61 | } | ||||
| 62 | |||||
| 63 | 1 | 600ns | sub FromEnv { | ||
| 64 | my $class = shift; | ||||
| 65 | |||||
| 66 | foreach my $var ( $class->EnvVars() ) { | ||||
| 67 | if ( $class->_IsValidName( $ENV{$var} ) ) { | ||||
| 68 | my $tz = try { | ||||
| 69 | local $SIG{__DIE__}; | ||||
| 70 | DateTime::TimeZone->new( name => $ENV{$var} ); | ||||
| 71 | }; | ||||
| 72 | |||||
| 73 | return $tz if $tz; | ||||
| 74 | } | ||||
| 75 | } | ||||
| 76 | |||||
| 77 | return; | ||||
| 78 | } | ||||
| 79 | |||||
| 80 | sub _IsValidName { | ||||
| 81 | shift; | ||||
| 82 | |||||
| 83 | return 0 unless defined $_[0]; | ||||
| 84 | return 0 if $_[0] eq 'local'; | ||||
| 85 | |||||
| 86 | return $_[0] =~ m{^[\w/\-\+]+$}; | ||||
| 87 | } | ||||
| 88 | |||||
| 89 | 1 | 6µs | 1; | ||
| 90 | |||||
| 91 | # ABSTRACT: Determine the local system's time zone | ||||
| 92 | |||||
| 93 | __END__ |