blib/lib/Locale/Codes.pm

filter: Statementstmt 98.7% 375 / 384 (4 uncoverable) Branchbran 96.2% 229 / 240 (2 uncoverable) Conditioncond 89.4% 51 / 57 MC/DCmcdc 84.8% 28 / 33 Subroutinesub 96.1% 25 / 26 Podpod 100% 19 / 19 totaltotal 96.5% 727 / 759 (6 uncoverable) CC 147 SCAR 23.7
CC
147
Cov
97%
_code
22.0
delete_code
13.2
name2code
12.0
CRAP 10.7
↑ Summary lib/Locale/Codes/Currency.pm »
1 package Locale::Codes;
2 # Copyright (C) 2001 Canon Research Centre Europe (CRE).
3 # Copyright (C) 2002-2009 Neil Bowers
4 # Copyright (c) 2010-2026 Sullivan Beck
5 # This program is free software; you can redistribute it and/or modify it
6 # under the same terms as Perl itself.
7  
8 ###############################################################################
9  
10 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 19 require 5.006;
13  
14 19 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 19 ▶use if $] >= 5.027007, 'deprecate';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 19 ▶use Locale::Codes::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 19 our($VERSION);
19 19 $VERSION='3.91';
20  
21 19 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 19 our(@EXPORT_OK,%EXPORT_TAGS);
23 19 @EXPORT_OK = @Locale::Codes::Constants::CONSTANTS;
24 19 %EXPORT_TAGS = ( 'constants' => [ @EXPORT_OK ] );
25  
26 ###############################################################################
27 # GLOBAL DATA
28 ###############################################################################
29 # All of the data is stored in a couple global variables. They are filled
30 # in by requiring the appropriate TYPE_Codes and TYPE_Retired modules.
31  
32 19 our(%Data,%Retired);
33  
34 # $Data{ TYPE }{ code2id }{ CODESET } { CODE } = [ ID, I ]
35 # { id2code }{ CODESET } { ID } = CODE
36 # { id2names }{ ID } = [ NAME, NAME, ... ]
37 # { alias2id }{ NAME } = [ ID, I ]
38 # { id } = FIRST_UNUSED_ID
39 # { codealias }{ CODESET } { ALIAS } = CODE
40 #
41 # $Retired{ TYPE }{ CODESET }{ code }{ CODE } = NAME
42 # { name }{ lc(NAME) } = [CODE,NAME]
43  
44 ###############################################################################
45 # METHODS
46 ###############################################################################
47  
48 32 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
49 32 my($class,$type,$codeset,$show_errors) = @_;
50 32 ▶ my $self = { 'type' => '',
Branch: 1 branch
BranchTrueFalseTotal
defined $show_errors ? : 1 31 32
51 'codeset' => '',
52 'err' => (defined($show_errors) ? $show_errors : 1),
53 };
54  
55 32 bless $self,$class;
56  
57 32 ▶ $self->type($type) if ($type);
Branch: 1 branch
BranchTrueFalseTotal
if $type 19 13 32
58 32 ▶ $self->codeset($codeset) if ($codeset);
Branch: 1 branch
BranchTrueFalseTotal
if $codeset 1 31 32
59 32 return $self;
60 }
61  
62 65 ▶sub show_errors {
Subroutine show_errors: called CC=1 SCAR=0.0
Pod documented
63 65 my($self,$val) = @_;
64 65 $$self{'err'} = $val;
65 65 return $val;
66 }
67  
68 30 ▶sub type {
Subroutine type: called CC=5 SCAR=16.1
Pod documented
69 30 my($self,$type) = @_;
70  
71 30 ▶ if (! exists $ALL_CODESETS{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Locale::Codes::ALL_CODESETS{$type}) 2 28 30
72 2 ▶ carp "ERROR: type: invalid argument: $type\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
73 2 return 1;
74 }
75  
76 28 my $label = $ALL_CODESETS{$type}{'module'};
77 28 eval "require Locale::Codes::${label}_Codes";
78 # uncoverable branch true
79 28 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 28 28
80 # uncoverable statement
81 0 croak "ERROR: type: unable to load module: ${label}_Codes\n";
82 }
83 28 eval "require Locale::Codes::${label}_Retired";
84 # uncoverable branch true
85 28 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 28 28
86 # uncoverable statement
87 0 croak "ERROR: type: unable to load module: ${label}_Retired\n";
88 }
89  
90 28 $$self{'type'} = $type;
91 28 $$self{'codeset'} = $ALL_CODESETS{$type}{'default'};
92  
93 28 return 0;
94 }
95  
96 4 ▶sub codeset {
Subroutine codeset: called CC=3 SCAR=11.0
Pod documented
97 4 my($self,$codeset) = @_;
98  
99 4 my $type = $$self{'type'};
100 4 ▶ if (! exists $ALL_CODESETS{$type}{'codesets'}{$codeset}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Locale::Codes::ALL_CODESETS{$type}{"codesets"}{$codeset}) 2 2 4
101 2 ▶ carp "ERROR: codeset: invalid argument: $codeset\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
102 2 return 1;
103 }
104  
105 2 $$self{'codeset'} = $codeset;
106 2 return 0;
107 }
108  
109 0 ▶sub version {
Subroutine version: not called CC=1 SCAR=0.0
Pod documented
110 # uncoverable subroutine
111 # uncoverable statement
112 0 my($self) = @_;
113 # uncoverable statement
114 0 return $VERSION;
115 }
116  
117 ###############################################################################
118  
119 # This is used to validate a codeset and/or code. It will also format
120 # a code for that codeset.
121 #
122 # (ERR,RET_CODE,RET_CODESET) = $o->_code([CODE [,CODESET]])
123 #
124 # If CODE is empty/undef, only the codeset will be validated
125 # and RET_CODE will be empty.
126 #
127 # If CODE is passed in, it will be returned formatted correctly
128 # for the codeset.
129 #
130 # ERR will be 0 or 1.
131 #
132 # If $no_check_code is 1, then the code will not be validated (i.e.
133 # it doesn't already have to exist). This will be useful for adding
134 # a new code.
135 #
136 1267 ▶sub _code {
Subroutine _code: called CC=22 SCAR=30.9
137 1267 my($self,$code,$codeset,$no_check_code) = @_;
138 1267 ▶ $code = '' if (! defined($code));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 11 1256 1267
139 1267 ▶ $codeset = lc($codeset) if (defined($codeset));
Branch: 1 branch
BranchTrueFalseTotal
if defined $codeset 506 761 1267
140  
141 1267 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 1265 1267
142 carp "ERROR: _code: no type set for Locale::Codes object\n"
143 2 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
144 2 return (1);
145 }
146 1265 my $type = $$self{'type'};
147 1265 ▶ if ($codeset && ! exists $ALL_CODESETS{$type}{'codesets'}{$codeset}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($codeset and not exists $Locale::Codes::ALL_CODESETS{$type}{"codesets"}{$codeset}) 39 1226 1265
Condition100%3/3
$codeset and not exists $Locale::Codes::ALL_CODESETS{$type}{"codesets"}{$codeset}
!ll&&!rl&&r
77944739
MC/DC100%2/2
$codeset and not exists $Locale::Codes::ALL_CODESETS{$type}{"codesets"}{$codeset}
$codeset not exists $Locale::Codes::ALL_CODESETS{$type}{"codesets"}{$codeset}
Truth table100%3/3
A and not(B)
A= $codesetB= not exists $Locale::Codes::ALL_CODESETS{$type}{"codesets"}{$codeset}
ABresult
0X0
100
111
148 carp "ERROR: _code: invalid codeset provided: $codeset\n"
149 39 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 36 3 39
150 39 return (1);
151 }
152  
153 # If no codeset was passed in, return the codeset specified.
154  
155 1226 ▶ $codeset = $$self{'codeset'} if (! defined($codeset) || $codeset eq '');
Branch: 1 branch
BranchTrueFalseTotal
if not defined $codeset or $codeset eq "" 764 462 1226
Condition100%3/3
not defined $codeset or $codeset eq ""
l!l&&r!l&&!r
7595462
MC/DC100%2/2
not defined $codeset or $codeset eq ""
not defined $codeset $codeset eq ""
Truth table100%3/3
not(A) or B
A= not defined $codesetB= $codeset eq ""
ABresult
1X1
011
000
156 1226 ▶ return (0,'',$codeset) if ($code eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $code eq "" 424 802 1226
157  
158 # Determine the properties of the codeset
159  
160 802 my($op,@args) = @{ $ALL_CODESETS{$type}{'codesets'}{$codeset} };
161  
162 802 ▶ if ($op eq 'lc') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "lc") 665 137 802
163 665 $code = lc($code);
164 }
165  
166 802 ▶ if ($op eq 'uc') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "uc") 69 733 802
167 69 $code = uc($code);
168 }
169  
170 802 ▶ if ($op eq 'ucfirst') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "ucfirst") 30 772 802
171 30 $code = ucfirst(lc($code));
172 }
173  
174 802 ▶ if ($op eq 'numeric') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "numeric") 38 764 802
175 38 ▶ if ($code =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ /^\d+$/) { } 30 8 38
176 30 my $l = $args[0];
177 30 $code = sprintf("%.${l}d", $code);
178  
179 } else {
180 8 ▶ carp "ERROR: _code: invalid numeric code: $code\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 7 1 8
181 8 return (1);
182 }
183 }
184  
185 # Determine if the code is in the codeset.
186  
187 794 ▶ if (! $no_check_code &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($no_check_code or exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code} or exists $Locale::Codes::Retired{$type}{$codeset}{"code"}{$code} or exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$code}) 152 642 794
Condition100%9/9
$no_check_code or exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code} or exists $Locale::Codes::Retired{$type}{$codeset}{"code"}{$code} or exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$code}
l!l&&r!l&&!r
61824152
$no_check_code or exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code} or exists $Locale::Codes::Retired{$type}{$codeset}{"code"}{$code}
l!l&&r!l&&!r
59721176
$no_check_code or exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code}
l!l&&r!l&&!r
96501197
MC/DC100%4/4
$no_check_code or exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code} or exists $Locale::Codes::Retired{$type}{$codeset}{"code"}{$code} or exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$code}
$no_check_code exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code} exists $Locale::Codes::Retired{$type}{$codeset}{"code"}{$code} exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$code}
Truth table100%5/5
A or B or C or D
A= $no_check_codeB= exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code}C= exists $Locale::Codes::Retired{$type}{$codeset}{"code"}{$code}D= exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$code}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
188 ! exists $Data{$type}{'code2id'}{$codeset}{$code} &&
189 ! exists $Retired{$type}{$codeset}{'code'}{$code} &&
190 ! exists $Data{$type}{'codealias'}{$codeset}{$code}) {
191 carp "ERROR: _code: code not in codeset: $code [$codeset]\n"
192 152 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 145 7 152
193 152 return (1);
194 }
195  
196 642 return (0,$code,$codeset);
197 }
198  
199 ###############################################################################
200  
201 # $name = $o->code2name(CODE [,CODESET] [,'retired'])
202 # @name = $o->code2names(CODE, [,CODESET])
203 # $code = $o->name2code(NAME [,CODESET] [,'retired'])
204 #
205 # Returns the name associated with the CODE (or vice versa).
206 #
207 473 ▶sub code2name {
Subroutine code2name: called CC=12 SCAR=24.9
Pod documented
208 473 my($self,@args) = @_;
209 473 my $retired = 0;
210 473 ▶ if (@args && defined($args[$#args]) && lc($args[$#args]) eq 'retired') {
Branch: 1 branch
BranchTrueFalseTotal
if (@args and defined $args[$#args] and lc $args[$#args] eq "retired") 9 464 473
Condition100%6/6
@args and defined $args[$#args] and lc $args[$#args] eq "retired"
!ll&&!rl&&r
94559
@args and defined $args[$#args]
!ll&&!rl&&r
36464
MC/DC100%3/3
@args and defined $args[$#args] and lc $args[$#args] eq "retired"
@args defined $args[$#args] lc $args[$#args] eq "retired"
Truth table100%4/4
A and B and C
A= @argsB= defined $args[$#args]C= lc $args[$#args] eq "retired"
ABCresult
0XX0
10X0
1100
1111
211 9 pop(@args);
212 9 $retired = 1;
213 }
214  
215 473 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 471 473
216 2 ▶ carp "ERROR: code2name: no type set for Locale::Codes object\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
217 2 return undef;
218 }
219 471 my $type = $$self{'type'};
220  
221 471 my ($err,$code,$codeset) = $self->_code(@args);
222 471 ▶ return undef if ($err || ! $code);
Branch: 1 branch
BranchTrueFalseTotal
if $err or not $code 66 405 471
Condition100%3/3
$err or not $code
l!l&&r!l&&!r
5412405
MC/DC100%2/2
$err or not $code
$err not $code
Truth table100%3/3
A or not(B)
A= $errB= not $code
ABresult
1X1
011
000
223  
224 $code = $Data{$type}{'codealias'}{$codeset}{$code}
225 405 ▶ if (exists $Data{$type}{'codealias'}{$codeset}{$code});
Branch: 1 branch
BranchTrueFalseTotal
if exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$code} 18 387 405
226  
227 405 ▶ if (exists $Data{$type}{'code2id'}{$codeset}{$code}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $Locale::Codes::Data{$type}{'code2id'}{$codeset}{$code}) { } 384 21 405
elsif ($retired and exists $Locale::Codes::Retired{$type}{$codeset}{'code'}{$code}) { } 3 36 39
228 384 my ($id,$i) = @{ $Data{$type}{'code2id'}{$codeset}{$code} };
229 384 my $name = $Data{$type}{'id2names'}{$id}[$i];
230 384 return $name;
231  
232 ▶ } elsif ($retired && exists $Retired{$type}{$codeset}{'code'}{$code}) {
Condition66%2/3
$retired and exists $Locale::Codes::Retired{$type}{$codeset}{"code"}{$code}
!ll&&!rl&&r
1803
MC/DC50%1/2
$retired and exists $Locale::Codes::Retired{$type}{$codeset}{"code"}{$code}
$retired exists $Locale::Codes::Retired{$type}{$codeset}{"code"}{$code}
Truth table66%2/3
A and B
A= $retiredB= exists $Locale::Codes::Retired{$type}{$codeset}{"code"}{$code}
ABresult
0X0
100
111
233 3 return $Retired{$type}{$codeset}{'code'}{$code};
234 }
235  
236 18 return undef;
237 }
238  
239 320 ▶sub name2code {
Subroutine name2code: called CC=12 SCAR=24.9
Pod documented
240 320 my($self,$name,@args) = @_;
241 320 ▶ return undef if (! $name);
Branch: 1 branch
BranchTrueFalseTotal
unless $name 18 302 320
242 302 $name = lc($name);
243  
244 302 my $retired = 0;
245 302 ▶ if (@args && defined($args[$#args]) && lc($args[$#args]) eq 'retired') {
Branch: 1 branch
BranchTrueFalseTotal
if (@args and defined $args[$#args] and lc $args[$#args] eq "retired") 6 296 302
Condition83%5/6
@args and defined $args[$#args] and lc $args[$#args] eq "retired"
!ll&&!rl&&r
197996
@args and defined $args[$#args]
!ll&&!rl&&r
1970105
MC/DC66%2/3
@args and defined $args[$#args] and lc $args[$#args] eq "retired"
@args defined $args[$#args] lc $args[$#args] eq "retired"
Truth table75%3/4
A and B and C
A= @argsB= defined $args[$#args]C= lc $args[$#args] eq "retired"
ABCresult
0XX0
10X0
1100
1111
246 6 pop(@args);
247 6 $retired = 1;
248 }
249  
250 302 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 300 302
251 2 ▶ carp "ERROR: name2code: no type set for Locale::Codes object\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
252 2 return undef;
253 }
254 300 my $type = $$self{'type'};
255  
256 300 my ($err,$tmp,$codeset) = $self->_code('',@args);
257 300 ▶ return undef if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 3 297 300
258  
259 297 ▶ if (exists $Data{$type}{'alias2id'}{$name}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $Locale::Codes::Data{$type}{'alias2id'}{$name}) { } 264 33 297
elsif ($retired and exists $Locale::Codes::Retired{$type}{$codeset}{'name'}{$name}) { } 3 57 60
260 264 my $id = $Data{$type}{'alias2id'}{$name}[0];
261 264 ▶ if (exists $Data{$type}{'id2code'}{$codeset}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Locale::Codes::Data{$type}{"id2code"}{$codeset}{$id}) 252 12 264
262 252 return $Data{$type}{'id2code'}{$codeset}{$id};
263 }
264  
265 ▶ } elsif ($retired && exists $Retired{$type}{$codeset}{'name'}{$name}) {
Condition100%3/3
$retired and exists $Locale::Codes::Retired{$type}{$codeset}{"name"}{$name}
!ll&&!rl&&r
2733
MC/DC100%2/2
$retired and exists $Locale::Codes::Retired{$type}{$codeset}{"name"}{$name}
$retired exists $Locale::Codes::Retired{$type}{$codeset}{"name"}{$name}
Truth table100%3/3
A and B
A= $retiredB= exists $Locale::Codes::Retired{$type}{$codeset}{"name"}{$name}
ABresult
0X0
100
111
266 3 return $Retired{$type}{$codeset}{'name'}{$name}[0];
267 }
268  
269 42 return undef;
270 }
271  
272 # $code = $o->code2code(CODE,CODESET2)
273 # $code = $o->code2code(CODE,CODESET1,CODESET2)
274 #
275 # Changes the code in the CODESET1 (or the current codeset) to another
276 # codeset (CODESET2)
277 #
278 68 ▶sub code2code {
Subroutine code2code: called CC=8 SCAR=20.8
Pod documented
279 68 my($self,@args) = @_;
280  
281 68 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 66 68
282 carp "ERROR: code2code: no type set for Locale::Codes object\n"
283 2 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
284 2 return undef;
285 }
286 66 my $type = $$self{'type'};
287  
288 66 my($code,$codeset1,$codeset2,$err);
289  
290 66 ▶ if (@args == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (@args == 2) { } 3 63 66
elsif (@args == 3) { } 60 3 63
291 3 ($code,$codeset2) = @args;
292 3 ($err,$code,$codeset1) = $self->_code($code);
293 3 ▶ return undef if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 3 3
294  
295 } elsif (@args == 3) {
296 60 ($code,$codeset1,$codeset2) = @args;
297 60 ($err,$code) = $self->_code($code,$codeset1);
298 60 ▶ return undef if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 12 48 60
299 48 ($err) = $self->_code('',$codeset2);
300 48 ▶ return undef if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 48 48
301 }
302  
303 54 my $name = $self->code2name($code,$codeset1);
304 54 my $out = $self->name2code($name,$codeset2);
305 54 return $out;
306 }
307  
308 3 ▶sub code2names {
Subroutine code2names: called CC=6 SCAR=21.9
Pod documented
309 3 my($self,@args) = @_;
310  
311 3 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 0 3 3
312 carp "ERROR: code2named: no type set for Locale::Codes object\n"
313 0 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 0 0 0
314 0 return undef;
315 }
316 3 my $type = $$self{'type'};
317  
318 3 my ($err,$code,$codeset) = $self->_code(@args);
319 return undef if ($err ||
320 ! $code ||
321 3 ▶ ! exists $Data{$type}{'code2id'}{$codeset}{$code});
Branch: 1 branch
BranchTrueFalseTotal
if $err or not $code or not exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code} 0 3 3
Condition33%2/6
$err or not $code or not exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code}
l!l&&r!l&&!r
003
$err or not $code
l!l&&r!l&&!r
003
MC/DC0%0/3
$err or not $code or not exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code}
$err not $code not exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code}
Truth table25%1/4
A or not(B) or not(C)
A= $errB= not $codeC= not exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code}
ABCresult
1XX1
01X1
0011
0000
322  
323 3 my $id = $Data{$type}{'code2id'}{$codeset}{$code}[0];
324 3 my @name = @{ $Data{$type}{'id2names'}{$id} };
325 3 return @name;
326 }
327 ###############################################################################
328  
329 # @codes = $o->all_codes([CODESET] [,'retired']);
330 # @names = $o->all_names([CODESET] [,'retired']);
331 #
332 # Returns all codes/names in the specified codeset, including retired
333 # ones if the option is given.
334  
335 47 ▶sub all_codes {
Subroutine all_codes: called CC=7 SCAR=19.5
Pod documented
336 47 my($self,@args) = @_;
337 47 my $retired = 0;
338 47 ▶ if (@args && lc($args[$#args]) eq 'retired') {
Branch: 1 branch
BranchTrueFalseTotal
if (@args and lc $args[$#args] eq "retired") 3 44 47
Condition100%3/3
@args and lc $args[$#args] eq "retired"
!ll&&!rl&&r
20243
MC/DC100%2/2
@args and lc $args[$#args] eq "retired"
@args lc $args[$#args] eq "retired"
Truth table100%3/3
A and B
A= @argsB= lc $args[$#args] eq "retired"
ABresult
0X0
100
111
339 3 pop(@args);
340 3 $retired = 1;
341 }
342  
343 47 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 45 47
344 2 ▶ carp "ERROR: all_codes: no type set for Locale::Codes object\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
345 2 return ();
346 }
347 45 my $type = $$self{'type'};
348  
349 45 my ($err,$tmp,$codeset) = $self->_code('',@args);
350 45 ▶ return () if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 3 42 45
351  
352 42 my @codes = keys %{ $Data{$type}{'code2id'}{$codeset} };
353 42 ▶ push(@codes,keys %{ $Retired{$type}{$codeset}{'code'} }) if ($retired);
Branch: 1 branch
BranchTrueFalseTotal
if $retired 3 39 42
354 42 return (sort @codes);
355 }
356  
357 26 ▶sub all_names {
Subroutine all_names: called CC=9 SCAR=22.0
Pod documented
358 26 my($self,@args) = @_;
359 26 my $retired = 0;
360 26 ▶ if (@args && lc($args[$#args]) eq 'retired') {
Branch: 1 branch
BranchTrueFalseTotal
if (@args and lc $args[$#args] eq "retired") 3 23 26
Condition100%3/3
@args and lc $args[$#args] eq "retired"
!ll&&!rl&&r
2033
MC/DC100%2/2
@args and lc $args[$#args] eq "retired"
@args lc $args[$#args] eq "retired"
Truth table100%3/3
A and B
A= @argsB= lc $args[$#args] eq "retired"
ABresult
0X0
100
111
361 3 pop(@args);
362 3 $retired = 1;
363 }
364  
365 26 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 24 26
366 2 ▶ carp "ERROR: all_names: no type set for Locale::Codes object\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
367 2 return ();
368 }
369 24 my $type = $$self{'type'};
370  
371 24 my ($err,$tmp,$codeset) = $self->_code('',@args);
372 24 ▶ return () if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 3 21 24
373  
374 21 my @codes = $self->all_codes($codeset);
375 21 my @names;
376  
377 21 foreach my $code (@codes) {
378 4253 my($id,$i) = @{ $Data{$type}{'code2id'}{$codeset}{$code} };
379 4253 my $name = $Data{$type}{'id2names'}{$id}[$i];
380 4253 push(@names,$name);
381 }
382 21 ▶ if ($retired) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retired) 3 18 21
383 3 foreach my $lc (keys %{ $Retired{$type}{$codeset}{'name'} }) {
384 159 my $name = $Retired{$type}{$codeset}{'name'}{$lc}[1];
385 159 push @names,$name;
386 }
387 }
388 21 return (sort @names);
389 }
390  
391 ###############################################################################
392  
393 # $flag = $o->rename_code (CODE,NEW_NAME [,CODESET])
394 #
395 # Change the official name for a code. The original is retained
396 # as an alias, but the new name will be returned if you lookup the
397 # name from code.
398 #
399 # Returns 1 on success.
400 #
401 54 ▶sub rename_code {
Subroutine rename_code: called CC=8 SCAR=20.8
Pod documented
402 54 my($self,$code,$new_name,$codeset) = @_;
403  
404 54 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 52 54
405 2 ▶ carp "ERROR: rename_code: no type set for Locale::Codes object\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
406 2 return 0;
407 }
408 52 my $type = $$self{'type'};
409  
410 # Make sure $code/$codeset are both valid
411  
412 52 my($err,$c,$cs) = $self->_code($code,$codeset);
413 52 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 32 20 52
414 carp "ERROR: rename_code: unknown code/codeset: $code [$codeset]\n"
415 32 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 31 1 32
416 32 return 0;
417 }
418 20 ($code,$codeset) = ($c,$cs);
419  
420 # Cases:
421 # 1. Renaming to a name which exists with a different ID
422 # Error
423 #
424 # 2. Renaming to a name which exists with the same ID
425 # Just change code2id (I value)
426 #
427 # 3. Renaming to a new name
428 # Create a new alias
429 # Change code2id (I value)
430  
431 20 my $id = $Data{$type}{'code2id'}{$codeset}{$code}[0];
432  
433 20 ▶ if (exists $Data{$type}{'alias2id'}{lc($new_name)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Locale::Codes::Data{$type}{'alias2id'}{lc $new_name}) { } 11 9 20
434 # Existing name (case 1 and 2)
435  
436 11 my ($new_id,$i) = @{ $Data{$type}{'alias2id'}{lc($new_name)} };
437 11 ▶ if ($new_id != $id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_id != $id) 8 3 11
438 # Case 1
439 carp "ERROR: rename_code: rename to an existing name not allowed\n"
440 8 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 7 1 8
441 8 return 0;
442 }
443  
444 # Case 2
445  
446 3 $Data{$type}{'code2id'}{$codeset}{$code}[1] = $i;
447  
448 } else {
449  
450 # Case 3
451  
452 9 push @{ $Data{$type}{'id2names'}{$id} },$new_name;
453 9 my $i = $#{ $Data{$type}{'id2names'}{$id} };
454 9 $Data{$type}{'alias2id'}{lc($new_name)} = [ $id,$i ];
455 9 $Data{$type}{'code2id'}{$codeset}{$code}[1] = $i;
456 }
457  
458 12 return 1;
459 }
460  
461 ###############################################################################
462  
463 # $flag = $o->add_code (CODE,NAME [,CODESET])
464 #
465 # Add a new code to the codeset. Both CODE and NAME must be
466 # unused in the code set.
467 #
468 62 ▶sub add_code {
Subroutine add_code: called CC=11 SCAR=24.0
Pod documented
469 62 my($self,$code,$name,$codeset) = @_;
470  
471 62 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 60 62
472 2 ▶ carp "ERROR: add_code: no type set for Locale::Codes object\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
473 2 return 0;
474 }
475 60 my $type = $$self{'type'};
476  
477 # Make sure that $codeset is valid.
478  
479 60 my($err,$c,$cs) = $self->_code($code,$codeset,1);
480 60 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 5 55 60
481 5 ▶ carp "ERROR: add_code: unknown codeset: $codeset\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 4 1 5
482 5 return 0;
483 }
484 55 ($code,$codeset) = ($c,$cs);
485  
486 # Check that $code is unused.
487  
488 55 ▶ if (exists $Data{$type}{'code2id'}{$codeset}{$code} ||
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code} or exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$code}) 8 47 55
Condition100%3/3
exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code} or exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$code}
l!l&&r!l&&!r
3547
MC/DC100%2/2
exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code} or exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$code}
exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code} exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$code}
Truth table100%3/3
A or B
A= exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code}B= exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$code}
ABresult
1X1
011
000
489 exists $Data{$type}{'codealias'}{$codeset}{$code}) {
490 8 ▶ carp "ERROR: add_code: code already in use as alias: $code\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 7 1 8
491 8 return 0;
492 }
493  
494 # Check to see that $name is unused in this code set. If it is
495 # used (but not in this code set), we'll use that ID. Otherwise,
496 # we'll need to get the next available ID.
497  
498 47 my ($id,$i);
499 47 ▶ if (exists $Data{$type}{'alias2id'}{lc($name)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Locale::Codes::Data{$type}{'alias2id'}{lc $name}) { } 14 33 47
500 14 ($id,$i) = @{ $Data{$type}{'alias2id'}{lc($name)} };
501 14 ▶ if (exists $Data{$type}{'id2code'}{$codeset}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Locale::Codes::Data{$type}{"id2code"}{$codeset}{$id}) 5 9 14
502 5 ▶ carp "ERROR: add_code: name already in use: $name\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 4 1 5
503 5 return 0;
504 }
505  
506 } else {
507 33 $id = $Data{$type}{'id'}++;
508 33 $i = 0;
509 33 $Data{$type}{'alias2id'}{lc($name)} = [ $id,$i ];
510 33 $Data{$type}{'id2names'}{$id} = [ $name ];
511 }
512  
513 # Add the new code
514  
515 42 $Data{$type}{'code2id'}{$codeset}{$code} = [ $id,$i ];
516 42 $Data{$type}{'id2code'}{$codeset}{$id} = $code;
517  
518 42 return 1;
519 }
520  
521 ###############################################################################
522  
523 # $flag = $o->delete_code (CODE [,CODESET])
524 #
525 # Delete a code from the codeset.
526 #
527 34 ▶sub delete_code {
Subroutine delete_code: called CC=13 SCAR=25.8
Pod documented
528 34 my($self,$code,$codeset) = @_;
529  
530 34 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 32 34
531 2 ▶ carp "ERROR: delete_code: no type set for Locale::Codes object\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
532 2 return 0;
533 }
534 32 my $type = $$self{'type'};
535  
536 # Make sure $code/$codeset are both valid
537  
538 32 my($err,$c,$cs) = $self->_code($code,$codeset);
539 32 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 8 24 32
540 carp "ERROR: delete_code: Unknown code/codeset: $code [$codeset]\n"
541 8 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 7 1 8
542 8 return 0;
543 }
544 24 ($code,$codeset) = ($c,$cs);
545  
546 # Delete active codes
547  
548 24 ▶ if (exists $Data{$type}{'code2id'}{$codeset}{$code}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$code}) 24 0 24
549  
550 24 my $id = $Data{$type}{'code2id'}{$codeset}{$code}[0];
551 24 delete $Data{$type}{'code2id'}{$codeset}{$code};
552 24 delete $Data{$type}{'id2code'}{$codeset}{$id};
553  
554 # Delete any aliases that are linked to this code
555  
556 24 foreach my $alias (keys %{ $Data{$type}{'codealias'}{$codeset} }) {
557 12 ▶ next if ($Data{$type}{'codealias'}{$codeset}{$alias} ne $code);
Branch: 1 branch
BranchTrueFalseTotal
if $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$alias} ne $code 9 3 12
558 3 delete $Data{$type}{'codealias'}{$codeset}{$alias};
559 }
560  
561 # If this ID is used in any other codesets, we will leave all of the
562 # names in place. Otherwise, we'll delete them.
563  
564 24 my $inuse = 0;
565 24 foreach my $cs (keys %{ $Data{$type}{'id2code'} }) {
566 62 ▶ $inuse = 1, last if (exists $Data{$type}{'id2code'}{$cs}{$id});
Branch: 1 branch
BranchTrueFalseTotal
if exists $Locale::Codes::Data{$type}{"id2code"}{$cs}{$id} 6 56 62
567 }
568  
569 24 ▶ if (! $inuse) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($inuse) 18 6 24
570 18 my @names = @{ $Data{$type}{'id2names'}{$id} };
571 18 delete $Data{$type}{'id2names'}{$id};
572  
573 18 foreach my $name (@names) {
574 18 delete $Data{$type}{'alias2id'}{lc($name)};
575 }
576 }
577 }
578  
579 # Delete retired codes
580  
581 24 ▶ if (exists $Retired{$type}{$codeset}{'code'}{$code}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Locale::Codes::Retired{$type}{$codeset}{"code"}{$code}) 0 24 24
582 0 my $name = $Retired{$type}{$codeset}{'code'}{$code};
583 0 delete $Retired{$type}{$codeset}{'code'}{$code};
584 0 delete $Retired{$type}{$codeset}{'name'}{lc($name)};
585 }
586  
587 24 return 1;
588 }
589  
590 ###############################################################################
591  
592 # $flag = $o->add_alias (NAME,NEW_NAME)
593 #
594 # Add a new alias. NAME must exist, and NEW_NAME must be unused.
595 #
596 40 ▶sub add_alias {
Subroutine add_alias: called CC=7 SCAR=19.5
Pod documented
597 40 my($self,$name,$new_name) = @_;
598  
599 40 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 38 40
600 2 ▶ carp "ERROR: add_alias: no type set for Locale::Codes object\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
601 2 return 0;
602 }
603 38 my $type = $$self{'type'};
604  
605 # Check that $name is used and $new_name is new.
606  
607 38 my($id);
608 38 ▶ if (exists $Data{$type}{'alias2id'}{lc($name)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Locale::Codes::Data{$type}{'alias2id'}{lc $name}) { } 17 21 38
609 17 $id = $Data{$type}{'alias2id'}{lc($name)}[0];
610 } else {
611 21 ▶ carp "ERROR: add_alias: name does not exist: $name\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 19 2 21
612 21 return 0;
613 }
614  
615 17 ▶ if (exists $Data{$type}{'alias2id'}{lc($new_name)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Locale::Codes::Data{$type}{"alias2id"}{lc $new_name}) 4 13 17
616 4 ▶ carp "ERROR: add_alias: alias already in use: $new_name\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 4 0 4
617 4 return 0;
618 }
619  
620 # Add the new alias
621  
622 13 push @{ $Data{$type}{'id2names'}{$id} },$new_name;
623 13 my $i = $#{ $Data{$type}{'id2names'}{$id} };
624 13 $Data{$type}{'alias2id'}{lc($new_name)} = [ $id,$i ];
625  
626 13 return 1;
627 }
628  
629 ###############################################################################
630  
631 # $flag = $o->delete_alias (NAME)
632 #
633 # This deletes a name from the list of names used by an element.
634 # NAME must be used, but must NOT be the only name in the list.
635 #
636 # Any id2name that references this name will be changed to
637 # refer to the first name in the list.
638 #
639 39 ▶sub delete_alias {
Subroutine delete_alias: called CC=12 SCAR=24.8
Pod documented
640 39 my($self,$name) = @_;
641  
642 39 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 37 39
643 2 ▶ carp "ERROR: delete_alias: no type set for Locale::Codes object\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
644 2 return 0;
645 }
646 37 my $type = $$self{'type'};
647  
648 # Check that $name is used.
649  
650 37 my($id,$i);
651 37 ▶ if (exists $Data{$type}{'alias2id'}{lc($name)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Locale::Codes::Data{$type}{'alias2id'}{lc $name}) { } 17 20 37
652 17 ($id,$i) = @{ $Data{$type}{'alias2id'}{lc($name)} };
653 } else {
654 20 ▶ carp "ERROR: delete_alias: name does not exist: $name\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 19 1 20
655 20 return 0;
656 }
657  
658 17 my $n = $#{ $Data{$type}{'id2names'}{$id} } + 1;
659 17 ▶ if ($n == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 1) 5 12 17
660 carp "ERROR: delete_alias: only one name defined (use delete_code instead)\n"
661 5 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 4 1 5
662 5 return 0;
663 }
664  
665 # Delete the alias.
666  
667 12 splice (@{ $Data{$type}{'id2names'}{$id} },$i,1);
668 12 delete $Data{$type}{'alias2id'}{lc($name)};
669  
670 # Every element that refers to this ID:
671 # Ignore if I < $i
672 # Set to 0 if I = $i
673 # Decrement if I > $i
674  
675 12 foreach my $codeset (keys %{ $Data{$type}{'code2id'} }) {
676 108 foreach my $code (keys %{ $Data{$type}{'code2id'}{$codeset} }) {
677 28581 my($jd,$j) = @{ $Data{$type}{'code2id'}{$codeset}{$code} };
678 28581 ▶ next if ($jd ne $id ||
Branch: 1 branch
BranchTrueFalseTotal
if $jd ne $id or $j < $i 28569 12 28581
Condition100%3/3
$jd ne $id or $j < $i
l!l&&r!l&&!r
285393012
MC/DC100%2/2
$jd ne $id or $j < $i
$jd ne $id $j < $i
Truth table100%3/3
A or B
A= $jd ne $idB= $j < $i
ABresult
1X1
011
000
679 $j < $i);
680 12 ▶ if ($i == $j) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $j) { } 6 6 12
681 6 $Data{$type}{'code2id'}{$codeset}{$code}[1] = 0;
682 } else {
683 6 $Data{$type}{'code2id'}{$codeset}{$code}[1]--;
684 }
685 }
686 }
687  
688 12 return 1;
689 }
690  
691 ###############################################################################
692  
693 # $flag = $o->replace_code (CODE,NEW_CODE [,CODESET])
694 #
695 # Change the official code. The original is retained as an alias, but
696 # the new code will be returned if do a name2code lookup.
697 #
698 44 ▶sub replace_code {
Subroutine replace_code: called CC=10 SCAR=23.0
Pod documented
699 44 my($self,$code,$new_code,$codeset) = @_;
700  
701 44 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 42 44
702 2 ▶ carp "ERROR: replace_code: no type set for Locale::Codes object\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
703 2 return 0;
704 }
705 42 my $type = $$self{'type'};
706  
707 # Make sure $code/$codeset are both valid (and that $new_code is the
708 # correct format)
709  
710 42 my($err,$c,$cs) = $self->_code($code,$codeset);
711 42 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 23 19 42
712 carp "ERROR: replace_code: Unknown code/codeset: $code [$codeset]\n"
713 23 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 22 1 23
714 23 return 0;
715 }
716 19 ($code,$codeset) = ($c,$cs);
717  
718 19 ($err,$new_code,$codeset) = $self->_code($new_code,$codeset,1);
719  
720 # Cases:
721 # 1. Renaming code to an existing alias of this code:
722 # Make the alias real and the code an alias
723 #
724 # 2. Renaming code to some other existing alias:
725 # Error
726 #
727 # 3. Renaming code to some other code:
728 # Error (
729 #
730 # 4. Renaming code to a new code:
731 # Make code into an alias
732 # Replace code with new_code.
733  
734 19 ▶ if (exists $Data{$type}{'codealias'}{$codeset}{$new_code}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $Locale::Codes::Data{$type}{'codealias'}{$codeset}{$new_code}) { } 8 11 19
elsif (exists $Locale::Codes::Data{$type}{'code2id'}{$codeset}{$new_code}) { } 5 6 11
735 # Cases 1 and 2
736 8 ▶ if ($Data{$type}{'codealias'}{$codeset}{$new_code} eq $code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Locale::Codes::Data{$type}{'codealias'}{$codeset}{$new_code} eq $code) { } 3 5 8
737 # Case 1
738  
739 3 delete $Data{$type}{'codealias'}{$codeset}{$new_code};
740  
741 } else {
742 # Case 2
743 carp "ERROR: replace_code: new code already in use as alias: $new_code\n"
744 5 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 4 1 5
745 5 return 0;
746 }
747  
748 } elsif (exists $Data{$type}{'code2id'}{$codeset}{$new_code}) {
749 # Case 3
750 carp "ERROR: replace_code: new code already in use: $new_code\n"
751 5 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 4 1 5
752 5 return 0;
753 }
754  
755 # Cases 1 and 4
756  
757 9 $Data{$type}{'codealias'}{$codeset}{$code} = $new_code;
758  
759 9 my $id = $Data{$type}{'code2id'}{$codeset}{$code}[0];
760 $Data{$type}{'code2id'}{$codeset}{$new_code} =
761 9 $Data{$type}{'code2id'}{$codeset}{$code};
762 9 delete $Data{$type}{'code2id'}{$codeset}{$code};
763  
764 9 $Data{$type}{'id2code'}{$codeset}{$id} = $new_code;
765  
766 9 return 1;
767 }
768  
769 ###############################################################################
770  
771 # $flag = $o->add_code_alias (CODE,NEW_CODE [,CODESET])
772 #
773 # Adds an alias for the code.
774 #
775 44 ▶sub add_code_alias {
Subroutine add_code_alias: called CC=8 SCAR=20.8
Pod documented
776 44 my($self,$code,$new_code,$codeset) = @_;
777  
778 44 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 42 44
779 2 ▶ carp "ERROR: add_code_alias: no type set for Locale::Codes object\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
780 2 return 0;
781 }
782 42 my $type = $$self{'type'};
783  
784 # Make sure $code/$codeset are both valid and that the new code is
785 # properly formatted.
786  
787 42 my($err,$c,$cs) = $self->_code($code,$codeset);
788 42 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 23 19 42
789 carp "ERROR: add_code_alias: unknown code/codeset: $code [$codeset]\n"
790 23 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 22 1 23
791 23 return 0;
792 }
793 19 ($code,$codeset) = ($c,$cs);
794  
795 19 ($err,$new_code,$cs) = $self->_code($new_code,$codeset,1);
796  
797 # Check that $new_code does not exist.
798  
799 19 ▶ if (exists $Data{$type}{'code2id'}{$codeset}{$new_code} ||
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$new_code} or exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$new_code}) 8 11 19
Condition100%3/3
exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$new_code} or exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$new_code}
l!l&&r!l&&!r
5311
MC/DC100%2/2
exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$new_code} or exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$new_code}
exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$new_code} exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$new_code}
Truth table100%3/3
A or B
A= exists $Locale::Codes::Data{$type}{"code2id"}{$codeset}{$new_code}B= exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$new_code}
ABresult
1X1
011
000
800 exists $Data{$type}{'codealias'}{$codeset}{$new_code}) {
801 8 ▶ carp "ERROR: add_code_alias: code already in use: $new_code\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 7 1 8
802 8 return 0;
803 }
804  
805 # Add the alias
806  
807 11 $Data{$type}{'codealias'}{$codeset}{$new_code} = $code;
808  
809 11 return 1;
810 }
811  
812 ###############################################################################
813  
814 # $flag = $o->delete_code_alias (ALIAS [,CODESET])
815 #
816 # Deletes an alias for the code.
817 #
818 36 ▶sub delete_code_alias {
Subroutine delete_code_alias: called CC=7 SCAR=19.5
Pod documented
819 36 my($self,$code,$codeset) = @_;
820  
821 36 ▶ if (! $$self{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}) 2 34 36
822 2 ▶ carp "ERROR: delete_code_alias: no type set for Locale::Codes object\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 1 1 2
823 2 return 0;
824 }
825 34 my $type = $$self{'type'};
826  
827 # Make sure $code/$codeset are both valid
828  
829 34 my($err,$c,$cs) = $self->_code($code,$codeset);
830 34 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 23 11 34
831 carp "ERROR: delete_code_alias: unknown code/codeset: $code [$codeset]\n"
832 23 ▶ if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 22 1 23
833 23 return 0;
834 }
835 11 ($code,$codeset) = ($c,$cs);
836  
837 # Check that $code exists in the codeset as an alias.
838  
839 11 ▶ if (! exists $Data{$type}{'codealias'}{$codeset}{$code}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Locale::Codes::Data{$type}{"codealias"}{$codeset}{$code}) 5 6 11
840 5 ▶ carp "ERROR: delete_code_alias: no alias defined: $code\n" if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 4 1 5
841 5 return 0;
842 }
843  
844 # Delete the alias
845  
846 6 delete $Data{$type}{'codealias'}{$codeset}{$code};
847  
848 6 return 1;
849 }
850  
851 19 1;
852 # Local Variables:
853 # mode: cperl
854 # indent-tabs-mode: nil
855 # cperl-indent-level: 3
856 # cperl-continued-statement-offset: 2
857 # cperl-continued-brace-offset: 0
858 # cperl-brace-offset: 0
859 # cperl-brace-imaginary-offset: 0
860 # cperl-label-offset: 0
861 # End:
↑ Summary lib/Locale/Codes/Currency.pm »