| 1 | package DateTime::TimeZone::Alias; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use DateTime::TimeZone::Catalog; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 10 | $VERSION = 0.06; | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||
| 11 | 13 | ▶ | sub import { | ||||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 12 | 13 | my $class = shift; | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | 13 | ▶ | return unless @_; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | 5 | $class->set( @_ ); | |||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | 144 | ▶ | sub set { | ||||||||||||||||||||||||||||
|
Subroutine
set: called CC=12 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 20 | 144 | my $class = shift; | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | 144 | ▶ | croak "Can't be called without any parameters" unless @_; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||
| 24 | 143 | my %p = @_; | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | 143 | foreach my $key ( keys %p ) { | |||||||||||||||||||||||||||||
| 27 | 147 | ▶ | if ( $class->is_alias( $p{ $key } ) ) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 28 | $DateTime::TimeZone::Catalog::LINKS{ $key } = | ||||||||||||||||||||||||||||||
| 29 | 3 | $DateTime::TimeZone::Catalog::LINKS{ $p{ $key } }; | |||||||||||||||||||||||||||||
| 30 | } elsif ( $class->is_timezone( $p{ $key } ) ) { | ||||||||||||||||||||||||||||||
| 31 | 8 | $DateTime::TimeZone::Catalog::LINKS{ $key } = $p{ $key }; | |||||||||||||||||||||||||||||
| 32 | } elsif ( $p{ $key } eq 'floating' ) { | ||||||||||||||||||||||||||||||
| 33 | 1 | $DateTime::TimeZone::Catalog::LINKS{ $key } = 'floating'; | |||||||||||||||||||||||||||||
| 34 | } elsif ( $p{ $key } eq 'local' ) { | ||||||||||||||||||||||||||||||
| 35 | 1 | $DateTime::TimeZone::Catalog::LINKS{ $key } = 'local'; | |||||||||||||||||||||||||||||
| 36 | ▶ | } elsif ( $p{ $key } eq 'UTC' || $p{ $key } eq 'Z' ) { | |||||||||||||||||||||||||||||
|
Condition33%1/3
$p{$key} eq "UTC" or $p{$key} eq "Z"
MC/DC0%0/2
$p{$key} eq "UTC" or $p{$key} eq "Z"
$p{$key} eq "UTC"
$p{$key} eq "Z"
Truth table33%1/3
A or B
A= $p{$key} eq "UTC"B= $p{$key} eq "Z"
| |||||||||||||||||||||||||||||||
| 37 | 0 | $DateTime::TimeZone::Catalog::LINKS{ $key } = 'UTC'; | |||||||||||||||||||||||||||||
| 38 | } elsif ( $p{ $key } =~ /^ ([\+\-])? (\d\d?) :? (\d\d) (?::?(\d\d))? $/x ) { | ||||||||||||||||||||||||||||||
| 39 | 25 | ▶ | my $sign = $1 || '+'; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$1 || '+'
MC/DC100%1/1
$1 || '+'
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||||
| 40 | 25 | my $hours = $2; | |||||||||||||||||||||||||||||
| 41 | 25 | my $minutes = $3; | |||||||||||||||||||||||||||||
| 42 | 25 | ▶ | my $seconds = sprintf( "%02d", $4 || 0 ); | ||||||||||||||||||||||||||||
|
Condition100%2/2
$4 || 0
MC/DC100%1/1
$4 || 0
$4
Truth table100%2/2
A
A= $4
| |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||
| 44 | 25 | $DateTime::TimeZone::Catalog::LINKS{ $key } = "$sign$hours:$minutes:$seconds"; | |||||||||||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||||||||||||
| 46 | 109 | croak "Aliases must point to a valid timezone or offset"; | |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | 4 | ▶ | sub add { | ||||||||||||||||||||||||||||
|
Subroutine
add: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 52 | 4 | my $class = shift; | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | 4 | ▶ | croak "Can't be called without any parameters" unless @_; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | 3 | my %p = @_; | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | 3 | foreach my $key ( keys %p ) { | |||||||||||||||||||||||||||||
| 59 | 3 | ▶ | if ( ! $class->is_defined( $key )) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 60 | 1 | $class->set( %p ); | |||||||||||||||||||||||||||||
| 61 | } else { | ||||||||||||||||||||||||||||||
| 62 | 2 | croak "Attempt to redefine an alias or timezone"; | |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | sub remove { | ||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 68 | 2 | my $class = shift; | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | return unless @_; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||
| 72 | 2 | foreach my $key ( @_ ) { | |||||||||||||||||||||||||||||
| 73 | 2 | ▶ | if ( ! $class->is_alias( $key ) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 74 | 1 | croak "Attempt to delete a nonexistant alias"; | |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||
| 77 | 1 | delete $DateTime::TimeZone::Catalog::LINKS{ $key }; | |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||
| 81 | 598 | ▶ | sub value { | ||||||||||||||||||||||||||||
|
Subroutine
value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 82 | 598 | my( $class, $key ) = @_; | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||
| 84 | 598 | ▶ | if ( $class->is_alias( $key ) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 85 | 281 | return $DateTime::TimeZone::Catalog::LINKS{ $key }; | |||||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||||
| 87 | 317 | return undef; | |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | 576 | ▶ | sub is_defined { | ||||||||||||||||||||||||||||
|
Subroutine
is_defined: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 92 | 576 | my( $class, $def_candidate ) = @_; | |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | 576 | ▶ | if ( | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$class->is_timezone($def_candidate) or $class->is_alias($def_candidate)
MC/DC100%2/2
$class->is_timezone($def_candidate) or $class->is_alias($def_candidate)
$class->is_timezone($def_candidate)
$class->is_alias($def_candidate)
Truth table100%3/3
A or B
A= $class->is_timezone($def_candidate)B= $class->is_alias($def_candidate)
| |||||||||||||||||||||||||||||||
| 95 | $class->is_timezone( $def_candidate ) | ||||||||||||||||||||||||||||||
| 96 | || $class->is_alias( $def_candidate ) | ||||||||||||||||||||||||||||||
| 97 | ) { | ||||||||||||||||||||||||||||||
| 98 | 575 | return 1; | |||||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||||
| 100 | 1 | return undef; | |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||
| 104 | 1579 | ▶ | sub is_alias { | ||||||||||||||||||||||||||||
|
Subroutine
is_alias: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 105 | 1579 | my( $class, $alias_candidate ) = @_; | |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||
| 107 | 1579 | ▶ | if ( exists $DateTime::TimeZone::Catalog::LINKS{ $alias_candidate } ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 108 | 799 | return 1; | |||||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||||
| 110 | 780 | return undef; | |||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||
| 114 | 1293 | ▶ | sub is_timezone { | ||||||||||||||||||||||||||||
|
Subroutine
is_timezone: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 115 | 1293 | my( $class, $tz_candidate ) = @_; | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||
| 117 | 1293 | ▶ | if ( grep( /^\Q${tz_candidate}\E$/, @DateTime::TimeZone::Catalog::ALL ) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 118 | 642 | return 1; | |||||||||||||||||||||||||||||
| 119 | } else { | ||||||||||||||||||||||||||||||
| 120 | 651 | return undef; | |||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | sub aliases { | ||||||||||||||||||||||||||||
|
Subroutine
aliases: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||||
| 125 | 1 | my $class = shift; | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||
| 127 | 1 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | if ( wantarray ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 130 | 0 | return %DateTime::TimeZone::Catalog::LINKS; | |||||||||||||||||||||||||||||
| 131 | } else { | ||||||||||||||||||||||||||||||
| 132 | 1 | my %dttz_links_copy = %DateTime::TimeZone::Catalog::LINKS; | |||||||||||||||||||||||||||||
| 133 | 1 | return \%dttz_links_copy; | |||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||
| 137 | 1 | ▶ | sub timezones { | ||||||||||||||||||||||||||||
|
Subroutine
timezones: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||||
| 138 | 1 | my $class = shift; | |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||
| 140 | 1 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||
| 142 | 1 | ▶ | if ( wantarray ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 143 | 0 | return @DateTime::TimeZone::Catalog::ALL; | |||||||||||||||||||||||||||||
| 144 | } else { | ||||||||||||||||||||||||||||||
| 145 | 1 | my @dttz_all_copy = @DateTime::TimeZone::Catalog::ALL; | |||||||||||||||||||||||||||||
| 146 | 1 | return \@dttz_all_copy; | |||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||
| 150 | 10 | 1; | |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||
| 152 | __END__ | ||||||||||||||||||||||||||||||