| 1 | package DateTime::Languages; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | |||||||||||||||
| 4 | BEGIN | ||||||||||||||
| 5 | 1 | ▶ | { | ||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use Class::Factory::Util; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 1 | ▶ | use Params::Validate qw( validate SCALAR ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use vars qw ( %ISOMap $VERSION ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 1 | $VERSION = "0.05"; | |||||||||||||
| 13 | |||||||||||||||
| 14 | 1 | foreach my $set ( [ 'aa', 'aar' => 'Afar' ], | |||||||||||||
| 15 | [ 'am', 'amh' => 'Amharic' ], | ||||||||||||||
| 16 | [ 'cz', 'ces', 'cze' => 'Czech' ], | ||||||||||||||
| 17 | [ 'de', 'deu', 'ger' => 'German' ], | ||||||||||||||
| 18 | [ 'de-at', 'deu-at', 'ger-at' => 'Austrian' ], | ||||||||||||||
| 19 | [ 'dk', 'dan' => 'Danish' ], | ||||||||||||||
| 20 | [ 'en', 'eng' => 'English' ], | ||||||||||||||
| 21 | [ 'es', 'esl', 'spa' => 'Spanish' ], | ||||||||||||||
| 22 | [ 'fr', 'fra', 'fre' => 'French' ], | ||||||||||||||
| 23 | [ 'x-drs', 'sil-drs' => 'Gedeo' ], | ||||||||||||||
| 24 | [ 'it', 'ita' => 'Italian' ], | ||||||||||||||
| 25 | [ 'nl', 'dut', 'nla' => 'Dutch' ], | ||||||||||||||
| 26 | [ 'no', 'nor' => 'Norwegian' ], | ||||||||||||||
| 27 | [ 'om', 'orm' => 'Oromo' ], | ||||||||||||||
| 28 | # not quite right, but better than failing | ||||||||||||||
| 29 | [ 'pt', 'por' => 'Brazilian' ], | ||||||||||||||
| 30 | [ 'pt-br', 'por-br' => 'Brazilian' ], | ||||||||||||||
| 31 | [ 'sid' => 'Sidama' ], | ||||||||||||||
| 32 | [ 'so', 'som' => 'Somali' ], | ||||||||||||||
| 33 | [ 'sv', 'sve', 'swe' => 'Swedish' ], | ||||||||||||||
| 34 | [ 'ti-et', 'tig-et' => 'TigrinyaEthiopian' ], | ||||||||||||||
| 35 | [ 'ti-er', 'tig-er' => 'TigrinyaEritrean' ], | ||||||||||||||
| 36 | ) | ||||||||||||||
| 37 | { | ||||||||||||||
| 38 | 21 | my $module = pop @$set; | |||||||||||||
| 39 | 21 | @ISOMap{ @$set } = ($module) x @$set; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | # print "ISOMap: $ISOMap{sid}\n"; | ||||||||||||||
| 44 | |||||||||||||||
| 45 | sub new | ||||||||||||||
| 46 | 2 | ▶ | { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 47 | 2 | my $class = shift; | |||||||||||||
| 48 | 2 | my %p = validate( @_, | |||||||||||||
| 49 | { language => { type => SCALAR } }, | ||||||||||||||
| 50 | ); | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 2 | my $real_class = $class->load( $p{language} ); | |||||||||||||
| 53 | |||||||||||||||
| 54 | 2 | my $obj = bless {}, $real_class; | |||||||||||||
| 55 | |||||||||||||||
| 56 | 2 | $obj->_init; | |||||||||||||
| 57 | |||||||||||||||
| 58 | 2 | return $obj; | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | |||||||||||||||
| 61 | 0 | ▶ | sub languages { $_[0]->subclasses } | ||||||||||||
|
Subroutine
languages: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 62 | 0 | ▶ | sub iso_codes { keys %ISOMap } | ||||||||||||
|
Subroutine
iso_codes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 63 | |||||||||||||||
| 64 | sub class_base | ||||||||||||||
| 65 | 0 | ▶ | { | ||||||||||||
|
Subroutine
class_base: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 66 | 0 | "DateTime::Languages"; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | |||||||||||||||
| 69 | |||||||||||||||
| 70 | sub load | ||||||||||||||
| 71 | 2 | ▶ | { | ||||||||||||
|
Subroutine
load: called CC=6 SCAR=18.9
Pod
documented
| |||||||||||||||
| 72 | 2 | my $class = shift; | |||||||||||||
| 73 | 2 | my $lang = shift; | |||||||||||||
| 74 | |||||||||||||||
| 75 | 2 | my $real_lang; | |||||||||||||
| 76 | 2 | ▶ | if ( $lang =~ /^((?:x-)?\w\w\w?)(?:-\w\w\w?)?$/ ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 77 | { | ||||||||||||||
| 78 | $real_lang = | ||||||||||||||
| 79 | ( exists $ISOMap{$lang} ? | ||||||||||||||
| 80 | $ISOMap{$lang} : | ||||||||||||||
| 81 | $1 ? | ||||||||||||||
| 82 | 2 | ▶ | $ISOMap{$1} : | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 83 | undef | ||||||||||||||
| 84 | ); | ||||||||||||||
| 85 | |||||||||||||||
| 86 | 2 | ▶ | die "Unsupported or invalid ISO language code, $lang" | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 87 | unless defined $real_lang; | ||||||||||||||
| 88 | } | ||||||||||||||
| 89 | else | ||||||||||||||
| 90 | { | ||||||||||||||
| 91 | 0 | $real_lang = $lang; | |||||||||||||
| 92 | } | ||||||||||||||
| 93 | |||||||||||||||
| 94 | 2 | my $real_class = $class->class_base."::$real_lang"; | |||||||||||||
| 95 | 1 | ▶ | eval "use $real_class"; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 96 | 2 | ▶ | die $@ if $@; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 97 | |||||||||||||||
| 98 | # print "XLoading $real_class\n"; | ||||||||||||||
| 99 | 2 | return $real_class; | |||||||||||||
| 100 | } | ||||||||||||||
| 101 | |||||||||||||||
| 102 | sub _init | ||||||||||||||
| 103 | 2 | ▶ | { | ||||||||||||
|
Subroutine
_init: called CC=4 SCAR=13.9
| |||||||||||||||
| 104 | 2 | my $self = shift; | |||||||||||||
| 105 | 2 | my $class = ref $self; | |||||||||||||
| 106 | |||||||||||||||
| 107 | 2 | foreach my $key ( qw( day_names day_abbreviations month_names | |||||||||||||
| 108 | month_abbreviations am_pm ordinal_suffixes | ||||||||||||||
| 109 | month_numbers day_numbers | ||||||||||||||
| 110 | ) | ||||||||||||||
| 111 | ) | ||||||||||||||
| 112 | { | ||||||||||||||
| 113 | 16 | my $var_name = join '', map { ucfirst } split /_/, $key; | |||||||||||||
| 114 | 16 | ▶ | $var_name = 'AMPM' if $var_name eq 'AmPm'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 115 | |||||||||||||||
| 116 | 1 | ▶ | no strict 'refs'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 117 | 16 | ▶ | if ( $key =~ /numbers$/ ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 118 | { | ||||||||||||||
| 119 | 4 | $self->{$key} = \%{"$class\::$var_name"}; | |||||||||||||
| 120 | } | ||||||||||||||
| 121 | else | ||||||||||||||
| 122 | { | ||||||||||||||
| 123 | 12 | $self->{$key} = \@{"$class\::$var_name"}; | |||||||||||||
| 124 | } | ||||||||||||||
| 125 | } | ||||||||||||||
| 126 | } | ||||||||||||||
| 127 | |||||||||||||||
| 128 | 0 | ▶ | sub month_names { $_[0]->{month_names} } | ||||||||||||
|
Subroutine
month_names: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 129 | |||||||||||||||
| 130 | 0 | ▶ | sub month_name { $_[0]->{month_names}[ $_[1]->month_0 ] } | ||||||||||||
|
Subroutine
month_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 131 | |||||||||||||||
| 132 | 0 | ▶ | sub day_names { $_[0]->{day_names} } | ||||||||||||
|
Subroutine
day_names: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 133 | |||||||||||||||
| 134 | 0 | ▶ | sub day_name { $_[0]->{day_names}[ $_[1]->day_of_week_0 ] } | ||||||||||||
|
Subroutine
day_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 135 | |||||||||||||||
| 136 | 0 | ▶ | sub month_abbreviations { $_[0]->{month_abbreviations} } | ||||||||||||
|
Subroutine
month_abbreviations: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 137 | |||||||||||||||
| 138 | 0 | ▶ | sub month_abbreviation { $_[0]->{month_abbreviations}[ $_[1]->month_0 ] } | ||||||||||||
|
Subroutine
month_abbreviation: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 139 | |||||||||||||||
| 140 | 0 | ▶ | sub day_abbreviations { $_[0]->{day_abbreviations} } | ||||||||||||
|
Subroutine
day_abbreviations: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 141 | |||||||||||||||
| 142 | 0 | ▶ | sub day_abbreviation { $_[0]->{day_abbreviations}[ $_[1]->day_of_week_0 ] } | ||||||||||||
|
Subroutine
day_abbreviation: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 143 | |||||||||||||||
| 144 | 0 | ▶ | sub am_pm_list { $_[0]->{am_pm} } | ||||||||||||
|
Subroutine
am_pm_list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 145 | |||||||||||||||
| 146 | 0 | ▶ | sub am_pm { $_[0]->{am_pm}[ $_[1]->hour < 12 ? 0 : 1 ] } | ||||||||||||
|
Subroutine
am_pm: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||
| 147 | |||||||||||||||
| 148 | #sub preferred_datetime_format { '%m/%d/%y %H:%M:%S' } | ||||||||||||||
| 149 | #sub preferred_date_format { '%m/%d/%y' } | ||||||||||||||
| 150 | #sub preferred_time_format { '%H:%M:%S' } | ||||||||||||||
| 151 | |||||||||||||||
| 152 | 1 | 1; | |||||||||||||
| 153 | |||||||||||||||
| 154 | __END__ | ||||||||||||||