| 1 | package Mo::utils::Language; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use List::Util 1.33 qw(none); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Locale::Language; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 4 | Readonly::Array our @EXPORT_OK => qw(check_language_639_1 check_language_639_2); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 4 | our $VERSION = 0.09; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 4 | ▶ | sub check_language_639_1 { | ||||||||||||||||||||||||||
|
Subroutine
check_language_639_1: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 4 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 4 | my $error = "Parameter '%s' doesn't contain valid ISO 639-1 code."; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | _check_language($self, $key, 'alpha-2', $error); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | return; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 4 | ▶ | sub check_language_639_2 { | ||||||||||||||||||||||||||
|
Subroutine
check_language_639_2: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 4 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 4 | my $error = "Parameter '%s' doesn't contain valid ISO 639-2 code."; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 4 | _check_language($self, $key, 'alpha-3', $error); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 3 | return; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 8 | ▶ | sub _check_key { | ||||||||||||||||||||||||||
|
Subroutine
_check_key: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 37 | 8 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 8 | ▶ | if (! exists $self->{$key} || ! defined $self->{$key}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $self->{$key} and defined $self->{$key}
MC/DC100%2/2
exists $self->{$key} and defined $self->{$key}
exists $self->{$key}
defined $self->{$key}
Truth table100%3/3
A and B
A= exists $self->{$key}B= defined $self->{$key}
| |||||||||||||||||||||||||||||
| 40 | 4 | return 1; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 4 | return 0; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 8 | ▶ | sub _check_language { | ||||||||||||||||||||||||||
|
Subroutine
_check_language: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 47 | 8 | my ($self, $key, $codeset, $error) = @_; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 8 | ▶ | _check_key($self, $key) && return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 4 | ▶ | if (none { $_ eq $self->{$key} } all_language_codes($codeset)) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 2 | my $err = sprintf($error, $key); | |||||||||||||||||||||||||||
| 53 | err $err, | ||||||||||||||||||||||||||||
| 54 | 'Codeset', $codeset, | ||||||||||||||||||||||||||||
| 55 | 2 | 'Value', $self->{$key}, | |||||||||||||||||||||||||||
| 56 | ; | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | return; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 4 | 1; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | __END__ | ||||||||||||||||||||||||||||