| 1 | package DateTimeX::Lite::TimeZone::Local; | ||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||
| 3 | 56 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 4 | 56 | ▶ | use warnings; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||
| 6 | 56 | ▶ | use DateTimeX::Lite::TimeZone; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 7 | 56 | ▶ | use File::Spec; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | sub TimeZone | ||||||||||||||||||||||||
| 11 | 539 | ▶ | { | ||||||||||||||||||||||
|
Subroutine
TimeZone: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||
| 12 | 539 | my $class = shift; | |||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||
| 14 | 539 | my $subclass = $class->_load_subclass(); | |||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||
| 16 | 539 | for my $meth ( $subclass->Methods() ) | |||||||||||||||||||||||
| 17 | { | ||||||||||||||||||||||||
| 18 | 539 | my $tz = $subclass->$meth(); | |||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||
| 20 | 539 | ▶ | return $tz if $tz; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||
| 23 | 0 | 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 | 56 | my %subclass = ( MSWin32 => 'Win32', | |||||||||||||||||||||||
| 31 | VMS => 'VMS', | ||||||||||||||||||||||||
| 32 | MacOS => 'Mac', | ||||||||||||||||||||||||
| 33 | os2 => 'OS2', | ||||||||||||||||||||||||
| 34 | epoc => 'Epoc', | ||||||||||||||||||||||||
| 35 | NetWare => 'Win32', | ||||||||||||||||||||||||
| 36 | symbian => 'Win32', | ||||||||||||||||||||||||
| 37 | dos => 'OS2', | ||||||||||||||||||||||||
| 38 | cygwin => 'Unix', | ||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||
| 41 | sub _load_subclass | ||||||||||||||||||||||||
| 42 | 540 | ▶ | { | ||||||||||||||||||||||
|
Subroutine
_load_subclass: called CC=7 SCAR=33.2
| |||||||||||||||||||||||||
| 43 | 540 | my $class = shift; | |||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||
| 45 | 540 | ▶ | my $subclass = $class . '::' . ( shift || $subclass{ $^O } || 'Unix' ); | ||||||||||||||||||||||
|
Condition40%2/5
shift() || $subclass{$^O} || 'Unix'
shift() or $subclass{$^O}
MC/DC0%0/2
shift() || $subclass{$^O} || 'Unix'
shift()
$subclass{$^O}
Truth table33%1/3
A or B
A= shift()B= $subclass{$^O}
| |||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||
| 47 | 540 | ▶ | return $subclass if $subclass->can('Methods'); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||
| 49 | 0 | eval "use $subclass"; | |||||||||||||||||||||||
| 50 | 0 | ▶ | if ( my $e = $@ ) | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||
| 52 | 0 | ▶ | if ( $e =~ /locate/ ) | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||
| 54 | 0 | $subclass = $class . '::' . 'Unix'; | |||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||
| 56 | 0 | eval "use $subclass"; | |||||||||||||||||||||||
| 57 | 0 | ▶ | die $@ if $@; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||
| 59 | else | ||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||
| 61 | 0 | die $e; | |||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||
| 65 | 0 | return $subclass; | |||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||
| 69 | sub FromEnv | ||||||||||||||||||||||||
| 70 | 56 | ▶ | { | ||||||||||||||||||||||
|
Subroutine
FromEnv: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||
| 71 | 543 | my $class = shift; | |||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||
| 73 | 543 | foreach my $var ( $class->EnvVars() ) | |||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||
| 75 | 543 | ▶ | if ( $class->_IsValidName( $ENV{$var} ) ) | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||
| 77 | 542 | my $tz; | |||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||
| 79 | 542 | local $@; | |||||||||||||||||||||||
| 80 | 542 | $tz = eval { DateTimeX::Lite::TimeZone->load( name => $ENV{$var} ) }; | |||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||
| 82 | 542 | ▶ | return $tz if $tz; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||
| 86 | 3 | return; | |||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||
| 89 | sub _IsValidName | ||||||||||||||||||||||||
| 90 | 543 | ▶ | { | ||||||||||||||||||||||
|
Subroutine
_IsValidName: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||
| 91 | 543 | shift; | |||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||
| 93 | 543 | ▶ | return 0 unless defined $_[0]; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 94 | 543 | ▶ | return 0 if $_[0] eq 'local'; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||
| 96 | 543 | return $_[0] =~ m{^[\w/\-\+]+$}; | |||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||
| 101 | 56 | 1; | |||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||