| 1 | package DateTime::TimeZone::Local; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | our $VERSION = '2.72'; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 3 | ▶ | use DateTime::TimeZone; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 3 | ▶ | use File::Spec; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 3 | ▶ | use Module::Runtime qw( require_module ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 3 | ▶ | use Try::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | ▶ | sub TimeZone { | ||||||||||||||||||
|
Subroutine
TimeZone: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||
| 15 | 1 | my $class = shift; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 1 | my $subclass = $class->_load_subclass(); | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 1 | for my $meth ( $subclass->Methods() ) { | |||||||||||||||||||
| 20 | 1 | my $tz = $subclass->$meth(); | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 1 | ▶ | return $tz if $tz; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 0 | die "Cannot determine local time zone\n"; | |||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | { | ||||||||||||||||||||
| 29 | # Stolen from File::Spec. My theory is that other folks can write | ||||||||||||||||||||
| 30 | # the non-existent modules if they feel a need, and release them | ||||||||||||||||||||
| 31 | # to CPAN separately. | ||||||||||||||||||||
| 32 | 3 | my %subclass = ( | |||||||||||||||||||
| 33 | android => 'Android', | ||||||||||||||||||||
| 34 | cygwin => 'Unix', | ||||||||||||||||||||
| 35 | dos => 'OS2', | ||||||||||||||||||||
| 36 | epoc => 'Epoc', | ||||||||||||||||||||
| 37 | MacOS => 'Mac', | ||||||||||||||||||||
| 38 | MSWin32 => 'Win32', | ||||||||||||||||||||
| 39 | NetWare => 'Win32', | ||||||||||||||||||||
| 40 | os2 => 'OS2', | ||||||||||||||||||||
| 41 | symbian => 'Win32', | ||||||||||||||||||||
| 42 | VMS => 'VMS', | ||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 1 | ▶ | sub _load_subclass { | ||||||||||||||||||
|
Subroutine
_load_subclass: called CC=4 SCAR=21.2
| |||||||||||||||||||||
| 46 | 1 | my $class = shift; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 1 | ▶ | my $os_name = $subclass{$^O} || $^O; | ||||||||||||||||||
|
Condition33%1/3
$subclass{$^O} || $^O
MC/DC0%0/2
$subclass{$^O} || $^O
$subclass{$^O}
$^O
Truth table33%1/3
A || B
A= $subclass{$^O}B= $^O
| |||||||||||||||||||||
| 49 | 1 | my $subclass = $class . '::' . $os_name; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 1 | ▶ | return $subclass if $subclass->can('Methods'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | ▶ | return $subclass if try { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 54 | ## no critic (Variables::RequireInitializationForLocalVars) | ||||||||||||||||||||
| 55 | 0 | local $SIG{__DIE__}; | |||||||||||||||||||
| 56 | 0 | require_module($subclass); | |||||||||||||||||||
| 57 | 0 | ▶ | }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | $subclass = $class . '::Unix'; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | require_module($subclass); | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | return $subclass; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 3 | ▶ | sub FromEnv { | ||||||||||||||||||
|
Subroutine
FromEnv: not called CC=4 SCAR=28.1
Pod
documented
| |||||||||||||||||||||
| 68 | 0 | my $class = shift; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | foreach my $var ( $class->EnvVars() ) { | |||||||||||||||||||
| 71 | 0 | ▶ | if ( $class->_IsValidName( $ENV{$var} ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 0 | ▶ | my $tz = try { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 73 | ## no critic (Variables::RequireInitializationForLocalVars) | ||||||||||||||||||||
| 74 | 0 | local $SIG{__DIE__}; | |||||||||||||||||||
| 75 | 0 | DateTime::TimeZone->new( name => $ENV{$var} ); | |||||||||||||||||||
| 76 | 0 | }; | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 0 | ▶ | return $tz if $tz; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 0 | return; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | ▶ | sub _IsValidName { | ||||||||||||||||||
|
Subroutine
_IsValidName: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 86 | 0 | shift; | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | ▶ | return 0 unless defined $_[0]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | 0 | ▶ | return 0 if $_[0] eq 'local'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | return $_[0] =~ m{^[\w/\-\+]+$}; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 3 | 1; | |||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | # ABSTRACT: Determine the local system's time zone | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||