| 1 | package Asterisk::LCR::Locale; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use base qw /Asterisk::LCR::Object/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | sub new | ||||||||||||||||||||||||||||
| 8 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 10 | 1 | ▶ | my $self = $class->SUPER::new (id => @_) || return; | ||||||||||||||||||||||||||
|
Condition50%1/2
$class->SUPER::new('id', @_) || (return)
MC/DC0%0/1
$class->SUPER::new('id', @_) || (return)
$class->SUPER::new('id', @_)
Truth table50%1/2
A
A= $class->SUPER::new('id', @_)
| |||||||||||||||||||||||||||||
| 11 | 1 | $self->parse(); | |||||||||||||||||||||||||||
| 12 | 1 | return $self; | |||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # does global => local => global ($prefix) conversion | ||||||||||||||||||||||||||||
| 17 | sub normalize | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
normalize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 20 | 0 | my $prefix = shift; | |||||||||||||||||||||||||||
| 21 | 0 | return $self->local_to_global ($self->global_to_local ($prefix)); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub global_to_local | ||||||||||||||||||||||||||||
| 26 | 10 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
global_to_local: called CC=7 SCAR=21.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 28 | 10 | my $num = shift; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 10 | ▶ | $self->{global_to_local_cache}->{$num} ||= do { | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"global_to_local_cache"}{$num} ||= do {
my $map = $self->{"global_to_local"};
foreach my $prefix (sort {length $b <=> length $a;} keys %{$map;}) {
my $val = $map->{$prefix};
$num =~ s/^_$prefix/_$val/ and return $prefix =~ /^\d*$/ ? $num : $self->global_to_local($num);
$num =~ s/^$prefix/$map->{$prefix}/ and return $prefix =~ /^\d*$/ ? $num : $self->global_to_local($num);
};
$num
}
MC/DC0%0/2
$self->{"global_to_local_cache"}{$num} ||= do {
my $map = $self->{"global_to_local"};
foreach my $prefix (sort {length $b <=> length $a;} keys %{$map;}) {
my $val = $map->{$prefix};
$num =~ s/^_$prefix/_$val/ and return $prefix =~ /^\d*$/ ? $num : $self->global_to_local($num);
$num =~ s/^$prefix/$map->{$prefix}/ and return $prefix =~ /^\d*$/ ? $num : $self->global_to_local($num);
};
$num
}
$self->{"global_to_local_cache"}{$num}
do {
my $map = $self->{"global_to_local"};
foreach my $prefix (sort {length $b <=> length $a;} keys %{$map;}) {
my $val = $map->{$prefix};
$num =~ s/^_$prefix/_$val/ and return $prefix =~ /^\d*$/ ? $num : $self->global_to_local($num);
$num =~ s/^$prefix/$map->{$prefix}/ and return $prefix =~ /^\d*$/ ? $num : $self->global_to_local($num);
};
$num
}
Truth table33%1/3
A ||= B
A= $self->{"global_to_local_cache"}{$num}B= do {
my $map = $self->{"global_to_local"};
foreach my $prefix (sort {length $b <=> length $a;} keys %{$map;}) {
my $val = $map->{$prefix};
$num =~ s/^_$prefix/_$val/ and return $prefix =~ /^\d*$/ ? $num : $self->global_to_local($num);
$num =~ s/^$prefix/$map->{$prefix}/ and return $prefix =~ /^\d*$/ ? $num : $self->global_to_local($num);
};
$num
}
| |||||||||||||||||||||||||||||
| 31 | 10 | my $map = $self->{global_to_local}; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 10 | foreach my $prefix ( sort { length ($b) <=> length ($a) } keys %{$map} ) | |||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | 108 | my $val = $map->{$prefix}; | |||||||||||||||||||||||||||
| 36 | 108 | ▶ | $num =~ s/^_$prefix/_$val/ and return ($prefix =~ /^\d*$/) ? $num : $self->global_to_local ($num); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 37 | 108 | ▶ | $num =~ s/^$prefix/$map->{$prefix}/ and return ($prefix =~ /^\d*$/) ? $num : $self->global_to_local ($num); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | $num; | |||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | return $self->{global_to_local_cache}->{$num}; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub local_to_global | ||||||||||||||||||||||||||||
| 48 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
local_to_global: called CC=7 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 50 | 6 | my $num = shift; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 6 | ▶ | $self->{local_to_global_cache}->{$num} ||= do { | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"local_to_global_cache"}{$num} ||= do {
my $map = $self->{"local_to_global"};
foreach my $prefix (sort {length $b <=> length $a;} keys %{$map;}) {
my $val = $map->{$prefix};
$num =~ s/^_$prefix/_$val/ and return $prefix =~ /^\d*$/ ? $num : $self->local_to_global($num);
$num =~ s/^$prefix/$map->{$prefix}/ and return $prefix =~ /^\d*$/ ? $num : $self->local_to_global($num);
};
$num
}
MC/DC0%0/2
$self->{"local_to_global_cache"}{$num} ||= do {
my $map = $self->{"local_to_global"};
foreach my $prefix (sort {length $b <=> length $a;} keys %{$map;}) {
my $val = $map->{$prefix};
$num =~ s/^_$prefix/_$val/ and return $prefix =~ /^\d*$/ ? $num : $self->local_to_global($num);
$num =~ s/^$prefix/$map->{$prefix}/ and return $prefix =~ /^\d*$/ ? $num : $self->local_to_global($num);
};
$num
}
$self->{"local_to_global_cache"}{$num}
do {
my $map = $self->{"local_to_global"};
foreach my $prefix (sort {length $b <=> length $a;} keys %{$map;}) {
my $val = $map->{$prefix};
$num =~ s/^_$prefix/_$val/ and return $prefix =~ /^\d*$/ ? $num : $self->local_to_global($num);
$num =~ s/^$prefix/$map->{$prefix}/ and return $prefix =~ /^\d*$/ ? $num : $self->local_to_global($num);
};
$num
}
Truth table33%1/3
A ||= B
A= $self->{"local_to_global_cache"}{$num}B= do {
my $map = $self->{"local_to_global"};
foreach my $prefix (sort {length $b <=> length $a;} keys %{$map;}) {
my $val = $map->{$prefix};
$num =~ s/^_$prefix/_$val/ and return $prefix =~ /^\d*$/ ? $num : $self->local_to_global($num);
$num =~ s/^$prefix/$map->{$prefix}/ and return $prefix =~ /^\d*$/ ? $num : $self->local_to_global($num);
};
$num
}
| |||||||||||||||||||||||||||||
| 53 | 6 | my $map = $self->{local_to_global}; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 6 | foreach my $prefix ( sort { length ($b) <=> length ($a) } keys %{$map} ) | |||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||
| 57 | 33 | my $val = $map->{$prefix}; | |||||||||||||||||||||||||||
| 58 | 33 | ▶ | $num =~ s/^_$prefix/_$val/ and return ($prefix =~ /^\d*$/) ? $num : $self->local_to_global ($num); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 59 | 33 | ▶ | $num =~ s/^$prefix/$map->{$prefix}/ and return ($prefix =~ /^\d*$/) ? $num : $self->local_to_global ($num); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | $num; | |||||||||||||||||||||||||||
| 63 | }; | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | return $self->{local_to_global_cache}->{$num}; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | sub validate | ||||||||||||||||||||||||||||
| 70 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=3 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 72 | 1 | ▶ | my $id = $self->id() or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | die "asterisk/lcr/locale/id/undefined"; | |||||||||||||||||||||||||||
| 74 | 0 | return 0; | |||||||||||||||||||||||||||
| 75 | }; | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | ▶ | $self->path() or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | die "asterisk/lcr/locale/id/no_path : $id"; | |||||||||||||||||||||||||||
| 79 | 0 | return 0; | |||||||||||||||||||||||||||
| 80 | }; | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | return 1; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub id | ||||||||||||||||||||||||||||
| 87 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 88 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 89 | 4 | return $self->{id}; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | sub set_id | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_id: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 95 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 96 | 0 | $self->{id} = shift; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | sub parse | ||||||||||||||||||||||||||||
| 101 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 103 | 1 | my @data = $self->get_lines(); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 1 | $self->{global_to_local} = {}; | |||||||||||||||||||||||||||
| 106 | 1 | $self->{local_to_global} = {}; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | foreach my $line (@data) | |||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||
| 110 | 26 | my ($local, $global) = $self->parse_line ($line); | |||||||||||||||||||||||||||
| 111 | 26 | ▶ | defined $local and defined $global or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $local and defined $global
MC/DC50%1/2
defined $local and defined $global
defined $local
defined $global
Truth table66%2/3
A and B
A= defined $localB= defined $global
| |||||||||||||||||||||||||||||
| 112 | 18 | ▶ | $self->{global_to_local}->{$global} = $local if ($local =~ /^\d*$/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 18 | ▶ | $self->{local_to_global}->{$local} = $global if ($global =~ /^\d*$/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | sub parse_line | ||||||||||||||||||||||||||||
| 119 | 26 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
parse_line: called CC=5 SCAR=16.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 120 | 26 | my $self = shift; | |||||||||||||||||||||||||||
| 121 | 26 | ▶ | my $line = shift || return; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || (return)
MC/DC100%1/1
shift() || (return)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 122 | 23 | ▶ | $line =~ /^\s*\#/ and return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 18 | my ($one, $two) = $line =~ /\"(.*?)\".*\"(.*?)\"/; | |||||||||||||||||||||||||||
| 125 | 18 | ▶ | return () unless (defined $one and defined $two); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $one and defined $two
MC/DC0%0/2
defined $one and defined $two
defined $one
defined $two
Truth table33%1/3
A and B
A= defined $oneB= defined $two
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 18 | return ($one, $two); | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | sub get_lines | ||||||||||||||||||||||||||||
| 132 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_lines: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 133 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 134 | 1 | my $id = $self->id(); | |||||||||||||||||||||||||||
| 135 | 1 | ▶ | my $file = $self->path() || return (); | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->path || (return ())
MC/DC0%0/1
$self->path || (return ())
$self->path
Truth table50%1/2
A
A= $self->path
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 1 | ▶ | open FP, "<$file" || die "Cannot read-open $file"; | ||||||||||||||||||||||||||
|
Condition50%1/2
"<$file" || die("Cannot read-open $file")
MC/DC0%0/1
"<$file" || die("Cannot read-open $file")
"<$file"
Truth table50%1/2
A
A= "<$file"
| |||||||||||||||||||||||||||||
| 138 | 1 | my @res = map { s/\r//g; s/\n//g; $_ } <FP>; | |||||||||||||||||||||||||||
| 139 | 1 | close FP; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 1 | return @res; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | sub path | ||||||||||||||||||||||||||||
| 146 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
path: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 147 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 2 | my $path = $self->id(); | |||||||||||||||||||||||||||
| 150 | 2 | ▶ | $path = "Asterisk/LCR/Locale/" . $path . ".txt" unless ($path =~ /\/.*\.txt$/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 2 | for ('.', @INC) | |||||||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||||||||
| 154 | 6 | ▶ | -e "$_/$path" and return "$_/$path"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | 0 | return; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 1 | 1; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | __END__ | ||||||||||||||||||||||||||||