| 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 792µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 16µs | 18µs | DateTime::TimeZone::Local::BEGIN@3 |
| 1 | 1 | 1 | 10µs | 10µs | DateTime::TimeZone::Local::BEGIN@7 |
| 1 | 1 | 1 | 9µs | 26µs | DateTime::TimeZone::Local::BEGIN@8 |
| 1 | 1 | 1 | 9µs | 41µs | DateTime::TimeZone::Local::BEGIN@9 |
| 1 | 1 | 1 | 7µs | 12µs | DateTime::TimeZone::Local::BEGIN@4 |
| 1 | 1 | 1 | 6µs | 6µ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 | 600ns | $DateTime::TimeZone::Local::VERSION = '1.98'; | ||
| 3 | 2 | 22µs | 2 | 20µs | # spent 18µs (16+2) within DateTime::TimeZone::Local::BEGIN@3 which was called:
# once (16µs+2µs) by DateTime::TimeZone::BEGIN@10 at line 3 # spent 18µs making 1 call to DateTime::TimeZone::Local::BEGIN@3
# spent 2µs making 1 call to strict::import |
| 4 | 2 | 22µs | 2 | 16µs | # spent 12µs (7+4) within DateTime::TimeZone::Local::BEGIN@4 which was called:
# once (7µs+4µs) by DateTime::TimeZone::BEGIN@10 at line 4 # spent 12µs making 1 call to DateTime::TimeZone::Local::BEGIN@4
# spent 4µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 2 | 22µs | 1 | 6µs | # spent 6µs within DateTime::TimeZone::Local::BEGIN@6 which was called:
# once (6µs+0s) by DateTime::TimeZone::BEGIN@10 at line 6 # spent 6µs making 1 call to DateTime::TimeZone::Local::BEGIN@6 |
| 7 | 2 | 28µs | 1 | 10µs | # spent 10µs within DateTime::TimeZone::Local::BEGIN@7 which was called:
# once (10µs+0s) by DateTime::TimeZone::BEGIN@10 at line 7 # spent 10µs making 1 call to DateTime::TimeZone::Local::BEGIN@7 |
| 8 | 2 | 24µs | 2 | 42µs | # spent 26µs (9+17) within DateTime::TimeZone::Local::BEGIN@8 which was called:
# once (9µs+17µs) by DateTime::TimeZone::BEGIN@10 at line 8 # spent 26µs making 1 call to DateTime::TimeZone::Local::BEGIN@8
# spent 17µs making 1 call to Module::Runtime::import |
| 9 | 2 | 662µs | 2 | 72µs | # spent 41µs (9+32) within DateTime::TimeZone::Local::BEGIN@9 which was called:
# once (9µs+32µs) by DateTime::TimeZone::BEGIN@10 at line 9 # spent 41µs making 1 call to DateTime::TimeZone::Local::BEGIN@9
# spent 32µ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 | 6µ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 | 300ns | 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 | 5µs | 1; | ||
| 90 | |||||
| 91 | # ABSTRACT: Determine the local system's time zone | ||||
| 92 | |||||
| 93 | __END__ |