lib/Asterisk/LCR/Locale.pm

filter: Statementstmt 83.3% 70 / 84 Branchbran 64.7% 22 / 34 Conditioncond 50.0% 10 / 20 MC/DCmcdc 16.6% 2 / 12 Subroutinesub 85.7% 12 / 14 Podpod 0.0% 0 / 11 totaltotal 66.2% 116 / 175 CC 30 SCAR 17.0
CC
30
Cov
74%
local_to_global
9.1
global_to_local
8.4
parse
6.0
CRAP 5.5
« blib/lib/Asterisk/LCR/Comparer/Dummy.pm ↑ Summary blib/lib/Asterisk/LCR/Comparer/XERAND.pm »
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)
l!l
10
MC/DC0%0/1
$class->SUPER::new('id', @_) || (return)
$class->SUPER::new('id', @_)
Truth table50%1/2
A
A= $class->SUPER::new('id', @_)
Aresult
11
00
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 }
l!l&&r!l&&!r
0010
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 }
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$num =~ s/^_$prefix/_$val/ and return $prefix =~ /^\d*$/ ? $num : $self->global_to_local($num) 0 108 108
$prefix =~ /^\d*$/ ? : 0 0 0
37 108 ▶ $num =~ s/^$prefix/$map->{$prefix}/ and return ($prefix =~ /^\d*$/) ? $num : $self->global_to_local ($num);
Branch: 2 branches
BranchTrueFalseTotal
$num =~ s/^$prefix/$map->{$prefix}/ and return $prefix =~ /^\d*$/ ? $num : $self->global_to_local($num) 10 98 108
$prefix =~ /^\d*$/ ? : 7 3 10
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 }
l!l&&r!l&&!r
006
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 }
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$num =~ s/^_$prefix/_$val/ and return $prefix =~ /^\d*$/ ? $num : $self->local_to_global($num) 0 33 33
$prefix =~ /^\d*$/ ? : 0 0 0
59 33 ▶ $num =~ s/^$prefix/$map->{$prefix}/ and return ($prefix =~ /^\d*$/) ? $num : $self->local_to_global ($num);
Branch: 2 branches
BranchTrueFalseTotal
$num =~ s/^$prefix/$map->{$prefix}/ and return $prefix =~ /^\d*$/ ? $num : $self->local_to_global($num) 6 27 33
$prefix =~ /^\d*$/ ? : 6 0 6
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
BranchTrueFalseTotal
my $id = $self->id or do { die "asterisk/lcr/locale/id/undefined"; return 0 } 1 0 1
73 0 die "asterisk/lcr/locale/id/undefined";
74 0 return 0;
75 };
76
77 1 ▶ $self->path() or do {
Branch: 1 branch
BranchTrueFalseTotal
$self->path or do { die "asterisk/lcr/locale/id/no_path : $id"; return 0 } 1 0 1
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
BranchTrueFalseTotal
defined $local and defined $global or next 18 8 26
Condition66%2/3
defined $local and defined $global
!ll&&!rl&&r
8018
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
ABresult
0X0
100
111
112 18 ▶ $self->{global_to_local}->{$global} = $local if ($local =~ /^\d*$/);
Branch: 1 branch
BranchTrueFalseTotal
if $local =~ /^\d*$/ 18 0 18
113 18 ▶ $self->{local_to_global}->{$local} = $global if ($global =~ /^\d*$/);
Branch: 1 branch
BranchTrueFalseTotal
if $global =~ /^\d*$/ 10 8 18
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)
l!l
233
MC/DC100%1/1
shift() || (return)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
122 23 ▶ $line =~ /^\s*\#/ and return;
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /^\s*\#/ and return 5 18 23
123  
124 18 my ($one, $two) = $line =~ /\"(.*?)\".*\"(.*?)\"/;
125 18 ▶ return () unless (defined $one and defined $two);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $one and defined $two 0 18 18
Condition33%1/3
defined $one and defined $two
!ll&&!rl&&r
0018
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
ABresult
0X0
100
111
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 ())
l!l
10
MC/DC0%0/1
$self->path || (return ())
$self->path
Truth table50%1/2
A
A= $self->path
Aresult
11
00
136
137 1 ▶ open FP, "<$file" || die "Cannot read-open $file";
Condition50%1/2
"<$file" || die("Cannot read-open $file")
l!l
10
MC/DC0%0/1
"<$file" || die("Cannot read-open $file")
"<$file"
Truth table50%1/2
A
A= "<$file"
Aresult
11
00
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
BranchTrueFalseTotal
unless $path =~ m[/.*\.txt$] 2 0 2
151  
152 2 for ('.', @INC)
153 {
154 6 ▶ -e "$_/$path" and return "$_/$path";
Branch: 1 branch
BranchTrueFalseTotal
-e "$_/$path" and return "$_/$path" 2 4 6
155 }
156 0 return;
157 }
158  
159  
160 1 1;
161  
162  
163 __END__
« blib/lib/Asterisk/LCR/Comparer/Dummy.pm ↑ Summary blib/lib/Asterisk/LCR/Comparer/XERAND.pm »