blib/lib/URI/tel.pm

filter: Statementstmt 74.3% 301 / 405 Branchbran 65.6% 134 / 204 Conditioncond 52.1% 37 / 71 MC/DCmcdc 39.1% 18 / 46 Subroutinesub 70.0% 28 / 40 Podpod 65.3% 17 / 26 totaltotal 67.5% 535 / 792 SCAR 65.1
CC
137
Cov
69%
_obj_eq
129.1
error
56.0
private
40.8
CRAP 674.2
↑ Summary
1 ##----------------------------------------------------------------------------
2 ## URI::tel - ~/lib/URI/tel.pm
3 ## Version v0.800.1
4 ## Copyright(c) 2019 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <@sitael.tokyo.deguest.jp>
6 ## Created 2016/02/12
7 ## Modified 2019/08/30
8 ##
9 ##----------------------------------------------------------------------------
10 package URI::tel;
11 BEGIN
12 {
13 3 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶ use parent 'URI';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶ our( $VERSION, $VERBOSE, $DEBUG, $ERROR );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 our( $RESERVED, $MARK, $UNRESERVED, $PCT_ENCODED, $URIC, $ALPHA, $DIGIT, $ALPHANUM, $HEXDIG );
17 3 our( $PARAM_UNRESERVED, $VISUAL_SEPARATOR, $PHONEDIGIT, $GLOBAL_NUMBER_DIGITS, $PARAMCHAR, $DOMAINLABEL, $TOPLABEL, $DOMAINNAME, $DESCRIPTOR, $PNAME, $PVALUE, $PARAMETER, $EXTENSION, $ISDN_SUBADDRESS, $CONTEXT, $PAR, $PHONEDIGIT_HEX, $GLOBAL_NUMBER, $LOCAL_NUMBER, $OTHER, $TEL_SUBSCRIBER, $TEL_URI );
18 3 our( $COUNTRIES, $IDD_RE );
19 3 $VERSION = 'v0.800.1';
20 use overload ('""' => 'as_string',
21 0 ▶ '==' => sub { _obj_eq(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 ▶ '!=' => sub { !_obj_eq(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 3 fallback => 1,
24 3 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 };
26  
27 {
28 #$RESERVED = qr{[\[\;\/\?\:\@\&\=\+\$\,\[\]]+};
29 3 $RESERVED = q{[;/?:@&=+$,[]+};
30 3 $MARK = q{-_.!~*'()}; #'; emacs
31 3 $UNRESERVED = qq{A-Za-z0-9\Q$MARK\E};
32 ## "%" HEXDIG HEXDIG
33 3 $PCT_ENCODED = qr{\%[0-9A-Fa-f]{2}};
34 #$URIC = quotemeta( $RESERVED ) . $UNRESERVED . "%";
35 3 $URIC = qr{(?:[\Q$RESERVED\E]+|[$UNRESERVED]+|(?:$PCT_ENCODED)+)};
36 # $ALPHA = qr{A-Za-z};
37 # $DIGIT = qr{\d};
38 3 $ALPHA = qr{A-Za-z};
39 3 $DIGIT = qq{0-9};
40 # $ALPHANUM = qr{A-Za-z\d};
41 3 $ALPHANUM = qq{A-Za-z0-9};
42 # $HEXDIG = qr{\dA-F};
43 3 $HEXDIG = qr{\dA-F};
44 # $PARAM_UNRESERVED = qr{[\[\]\/\:\&\+\$]+};
45 3 $PARAM_UNRESERVED = q{[]/:&+$};
46 3 $VISUAL_SEPARATOR = q(-.());
47 ## DIGIT / [ visual-separator ]
48 # $PHONEDIGIT = qr{$DIGIT\Q$VISUAL_SEPARATOR\E};
49 3 $PHONEDIGIT = qq{$DIGIT\Q$VISUAL_SEPARATOR\E};
50 ## "+" *phonedigit DIGIT *phonedigit
51 3 $GLOBAL_NUMBER_DIGITS = qr{\+[$PHONEDIGIT]*[$DIGIT]+[$PHONEDIGIT]*};
52 ## param-unreserved / unreserved / pct-encoded
53 3 $PARAMCHAR = qr{(?:[\Q$PARAM_UNRESERVED\E]+|[$UNRESERVED]+|(?:$PCT_ENCODED)+)};
54 ## alphanum / alphanum *( alphanum / "-" ) alphanum
55 3 $DOMAINLABEL = qr{(?:[$ALPHANUM]+|[$ALPHANUM]+(?:[$ALPHANUM\-]+)*[$ALPHANUM]+)};
56 ## ALPHA / ALPHA *( alphanum / "-" ) alphanum
57 3 $TOPLABEL = qr{(?:[$ALPHA]+|[$ALPHA]+[$ALPHANUM\-]*[$ALPHANUM]+)};
58 ## *( domainlabel "." ) toplabel [ "." ]
59 3 $DOMAINNAME = qr{(?:$DOMAINLABEL\.)*(?:$TOPLABEL\.?)+};
60 ## domainname / global-number-digits
61 3 $DESCRIPTOR = qr{(?:$DOMAINNAME|$GLOBAL_NUMBER_DIGITS)};
62 ## 1*( alphanum / "-" )
63 3 $PNAME = qr{[$ALPHANUM\-]+};
64 ## 1*paramchar
65 3 $PVALUE = qr{(?:$PARAMCHAR)};
66 ## ";" pname ["=" pvalue ]
67 3 $PARAMETER = qr{\;$PNAME=$PVALUE};
68 ## ";ext=" 1*phonedigit
69 ##$EXTENSION = qr{\;ext=[$PHONEDIGIT]+}msxi;
70 ## Tweaking the rfc regular expression to add often used extension format
71 ## See: https://discussions.apple.com/thread/1635858?start=0&tstart=0
72 ## or
73 ## http://stackoverflow.com/questions/2403767/string-format-phone-numbers-with-extension
74 3 $EXTENSION = qr{(?:[\;\,]?ext[\=\.]?|x)[$PHONEDIGIT]+}msxi;
75 ## ";isub=" 1*uric
76 3 $ISDN_SUBADDRESS = qr{\;isub=$URIC}msxi;
77 ## ";phone-context=" descriptor
78 3 $CONTEXT = qr{\;phone-context=$DESCRIPTOR}msxi;
79 ## parameter / extension / isdn-subaddress
80 3 $PAR = qr{(?:(?:($PARAMETER)|($EXTENSION)|($ISDN_SUBADDRESS)))+};
81 ## HEXDIG / "*" / "#" / [ visual-separator ]
82 3 $PHONEDIGIT_HEX = qr{[$HEXDIG\*\#$VISUAL_SEPARATOR]+};
83 ## *phonedigit-hex (HEXDIG / "*" / "#")*phonedigit-hex
84 3 $LOCAL_NUMBER_DIGITS = qr{(?:$PHONEDIGIT_HEX)?[$HEXDIG\*\#]+(?:$PHONEDIGIT_HEX)?};
85 ## global-number-digits *par => "+" *phonedigit DIGIT *phonedigit
86 3 $GLOBAL_NUMBER = qr{($GLOBAL_NUMBER_DIGITS)($PAR)*};
87 ## local-number-digits *par context *par
88 3 $LOCAL_NUMBER = qr{($LOCAL_NUMBER_DIGITS)($PAR)*($CONTEXT)($PAR)*};
89 ## This is a non-rfc standard requirement, but a necessity to catch local number with no context
90 ## such as 03-1234-5678 plain and simple
91 3 $OTHER = qr{(\+?[$PHONEDIGIT]*[$DIGIT]+[$PHONEDIGIT]*)($PAR)*};
92 ## Like +1-800-LAWYR-UP => +1-800-52997-87
93 3 $VANITY = qr{(\+?[$PHONEDIGIT]*[A-Z0-9\Q$VISUAL_SEPARATOR\E]+[$PHONEDIGIT]*)};
94 3 $TEL_SUBSCRIBER = qr{(?:$VANITY|$GLOBAL_NUMBER|$LOCAL_NUMBER|$OTHER)}xs;
95 ##$TEL_SUBSCRIBER = qr{(?:$GLOBAL_NUMBER)};
96 3 $TEL_URI = qr{(?:tel\:)?$TEL_SUBSCRIBER};
97 # https://tools.ietf.org/search/rfc3966#section-3
98
99 3 $COUNTRIES = {};
100 }
101  
102 sub _init
103 {
104 0 ▶ my $class = shift( @_ );
Subroutine _init: not called CC=3 SCAR=24.8
105 0 my( $str, $scheme ) = @_;
106 # find all funny characters and encode the bytes.
107 0 $str = $class->_uric_escape( $str );
108 0 ▶ $str = "$scheme:$str" unless $str =~ /^[a-zA-Z][a-zA-Z0-9.+\-]*:/o ||
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ /^[a-zA-Z][a-zA-Z0-9.+\-]*:/o or $class->_no_scheme_ok 0 0 0
Condition0%0/3
$str =~ /^[a-zA-Z][a-zA-Z0-9.+\-]*:/o or $class->_no_scheme_ok
l!l&&r!l&&!r
000
MC/DC0%0/2
$str =~ /^[a-zA-Z][a-zA-Z0-9.+\-]*:/o or $class->_no_scheme_ok
$str =~ /^[a-zA-Z][a-zA-Z0-9.+\-]*:/o $class->_no_scheme_ok
Truth table0%0/3
A or B
A= $str =~ /^[a-zA-Z][a-zA-Z0-9.+\-]*:/oB= $class->_no_scheme_ok
ABresult
1X1
011
000
109 $class->_no_scheme_ok;
110 #my $self = bless \$str, $class;
111 #$self;
112 0 return( $class->new( $str ) );
113 }
114  
115 sub new
116 {
117 290 ▶ my $this = shift( @_ );
Subroutine new: called CC=32 SCAR=34.7
Pod documented
118 290 my $str = shift( @_ );
119 290 ▶ my $class = ref( $this ) || $this;
Condition66%2/3
ref $this || $this
l!l&&r!l&&!r
212690
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table66%2/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
120 290 my $orig = $str;
121 290 $str =~ s/[[:blank:]]+//gs;
122 290 my $temp = {};
123 290 my @matches = ();
124 290 my @names = ();
125 290 ▶ if( @matches = $str =~ /^((?:tel\:)?$GLOBAL_NUMBER)$/ )
Branch: 4 branches
BranchTrueFalseTotal
if (@matches = $str =~ /^((?:tel\:)?$GLOBAL_NUMBER)$/) { } 262 28 290
elsif (@matches = $str =~ /^((?:tel\:)?$LOCAL_NUMBER)$/) { } 5 23 28
elsif (@matches = $str =~ /^((?:tel\:)?$OTHER)$/) { } 19 4 23
elsif (@matches = $str =~ /^((?:tel\:)?$VANITY)$/) { } 2 2 4
126 {
127 262 @names = qw( all subscriber params last_param );
128 262 $temp->{ 'type' } = 'global';
129 }
130 elsif( @matches = $str =~ /^((?:tel\:)?$LOCAL_NUMBER)$/ )
131 {
132 5 $temp->{ 'type' } = 'local';
133 5 @names = qw( all subscriber params1 last_param1 ignore5 ignore6 context params2 last_param2 ignore10 ignore11 );
134 5 ▶ $temp->{ '_has_context_param' } = 1 if( length( $matches[6] ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $matches[6] 5 0 5
135 5 $temp->{ 'local_number' } = $str;
136 5 $temp->{ 'local_number' } =~ s/^tel\://;
137 }
138 ## e.g. 911, 110 or just ordinary local phones like 03-1234-5678
139 elsif( @matches = $str =~ /^((?:tel\:)?$OTHER)$/ )
140 {
141 19 $temp->{ 'type' } = 'other';
142 19 @names = qw( all subscriber params ignore4 last_param );
143 }
144 ## e.g. +1-800-LAWYR-UP
145 elsif( @matches = $str =~ /^((?:tel\:)?$VANITY)$/ )
146 {
147 2 $temp->{ 'type' } = 'vanity';
148 2 @names = qw( all subscriber );
149 }
150 else
151 {
152 2 $ERROR = "Unknown telephone number '$str'.";
153 2 warn( $ERROR );
154 }
155
156 ## The component name for each match
157 290 @$temp{ @names } = @matches;
158
159 290 ▶ $temp->{ 'params' } = $temp->{ 'params1' } ? $temp->{ 'params1' } : $temp->{ 'params2' } if( !length( $temp->{ 'params' } ) );
Branch: 2 branches
BranchTrueFalseTotal
unless length $temp->{"params"} 282 8 290
$temp->{'params1'} ? : 1 281 282
160 290 $temp->{ 'context' } =~ s/;[^=]+=(.*?)$/$1/gs;
161
162 290 ▶ if( $str =~ /^(?:tel\:)?\+/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($str =~ /^(?:tel\:)?\+/) { } 263 27 290
elsif ($temp->{'context'} and not $temp->{'context'} =~ /^[a-zA-Z]/ and substr($temp->{'context'}, 0, 1) eq '+') { } 2 50 52
163 {
164 263 $temp->{ 'intl_code' } = $this->_extract_intl_code( $str );
165 }
166 ▶ elsif( $temp->{ 'context' } &&
Condition83%5/6
$temp->{"context"} and not $temp->{"context"} =~ /^[a-zA-Z]/ and substr($temp->{"context"}, 0, 1) eq "+"
!ll&&!rl&&r
2502
$temp->{"context"} and not $temp->{"context"} =~ /^[a-zA-Z]/
!ll&&!rl&&r
2232
MC/DC66%2/3
$temp->{"context"} and not $temp->{"context"} =~ /^[a-zA-Z]/ and substr($temp->{"context"}, 0, 1) eq "+"
$temp->{"context"} not $temp->{"context"} =~ /^[a-zA-Z]/ substr($temp->{"context"}, 0, 1) eq "+"
Truth table75%3/4
A and not(B) and C
A= $temp->{"context"}B= not $temp->{"context"} =~ /^[a-zA-Z]/C= substr($temp->{"context"}, 0, 1) eq "+"
ABCresult
0XX0
10X0
1100
1111
167 $temp->{ 'context' } !~ /^[a-zA-Z]/ &&
168 substr( $temp->{ 'context' }, 0, 1 ) eq '+' )
169 {
170 2 $temp->{ 'intl_code' } = $this->_extract_intl_code( $temp->{ 'context' } );
171 ## We flag it as extracted from context, because we do not want to prepend the subscriber number with it.
172 ## It's just too dangerous as we cannot tell the subscriber number is actually a proper number that can be dialed from outside e.g. 911 or 110 are emergency number who may heva a context with international code
173 ## However, if the international code was provided by the user then that's his responsibility
174 ## If the user wants to just provide some context, then better to use context() instead.
175 ## Knowing the international code helps getting some other useful information, but it should not necessarily affect the format of the number
176 2 $temp->{ '_intl_code_from_context' } = 1;
177 }
178 290 ▶ $temp->{ 'context' } = '+' . $temp->{ 'intl_code' } if( !length( $temp->{ 'context' } ) && length( $temp->{ 'intl_code' } ) );
Branch: 1 branch
BranchTrueFalseTotal
if not length $temp->{"context"} and length $temp->{"intl_code"} 263 27 290
Condition100%3/3
not length $temp->{"context"} and length $temp->{"intl_code"}
!ll&&!rl&&r
522263
MC/DC100%2/2
not length $temp->{"context"} and length $temp->{"intl_code"}
not length $temp->{"context"} length $temp->{"intl_code"}
Truth table100%3/3
not(A) and B
A= not length $temp->{"context"}B= length $temp->{"intl_code"}
ABresult
0X0
100
111
179
180 290 ▶ if( $temp->{ 'type' } eq 'global' && $temp->{ 'intl_code' } )
Branch: 1 branch
BranchTrueFalseTotal
if ($temp->{"type"} eq "global" and $temp->{"intl_code"}) 262 28 290
Condition66%2/3
$temp->{"type"} eq "global" and $temp->{"intl_code"}
!ll&&!rl&&r
280262
MC/DC50%1/2
$temp->{"type"} eq "global" and $temp->{"intl_code"}
$temp->{"type"} eq "global" $temp->{"intl_code"}
Truth table66%2/3
A and B
A= $temp->{"type"} eq "global"B= $temp->{"intl_code"}
ABresult
0X0
100
111
181 {
182 262 $temp->{ 'local_number' } = $this->_extract_local_number( $temp->{ 'intl_code' }, $temp->{ 'subscriber' } );
183 }
184
185 my $hash = {
186 'original' => ( $orig ne $str ) ? $orig : $temp->{ 'all' },
187 'is_global' => $temp->{ 'type' } eq 'global' ? 1 : 0,
188 'is_local' => ( $temp->{ 'type' } eq 'local' or $temp->{ 'type' } eq 'other' ) ? 1 : 0,
189 'is_other' => $temp->{ 'type' } eq 'other' ? 1 : 0,
190 'is_vanity' => $temp->{ 'type' } eq 'vanity' ? 1 : 0,
191 'subscriber' => $temp->{ 'subscriber' },
192 'params' => $temp->{ 'params' },
193 'last_param' => $temp->{ 'last_param' } ? $temp->{ 'last_param' } : $temp->{ 'last_param1' } ? $temp->{ 'last_param1' } : $temp->{ 'last_param2' },
194 'context' => $temp->{ 'context' },
195 'intl_code' => $temp->{ 'intl_code' },
196 '_intl_code_from_context' => $temp->{ '_intl_code_from_context' },
197 290 ▶ 'local_number' => $temp->{ 'local_number' },
Branch: 7 branches
BranchTrueFalseTotal
$orig ne $str ? : 3 287 290
$temp->{'type'} eq 'global' ? : 262 28 290
$temp->{'type'} eq 'local' || $temp->{'type'} eq 'other' ? : 24 266 290
$temp->{'type'} eq 'other' ? : 19 271 290
$temp->{'type'} eq 'vanity' ? : 2 288 290
$temp->{'last_param'} ? : 8 282 290
$temp->{'last_param1'} ? : 1 281 282
Condition100%3/3
$temp->{"type"} eq "local" or $temp->{"type"} eq "other"
l!l&&r!l&&!r
519266
MC/DC100%2/2
$temp->{"type"} eq "local" or $temp->{"type"} eq "other"
$temp->{"type"} eq "local" $temp->{"type"} eq "other"
Truth table100%3/3
A or B
A= $temp->{"type"} eq "local"B= $temp->{"type"} eq "other"
ABresult
1X1
011
000
198 };
199 290 my $self = bless( $hash, $class );
200 290 my $prams = [];
201 290 ▶ if( length( $temp->{ 'params' } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $temp->{"params"}) 10 280 290
202 {
203 10 my $pram_str = $temp->{ 'params' };
204 10 $pram_str =~ s/^[\.\,\#\;]//;
205 10 $prams = [ $self->split_str( $pram_str ) ];
206 }
207 ## Private parameters
208 290 my $priv = {};
209 290 foreach my $this ( @$prams )
210 {
211 16 $this =~ s/^(x|ext)\.?(\d+)$/ext=$2/i;
212 16 my( $p, $v ) = split( /=/, $this, 2 );
213 16 $p =~ s/\-/\_/gs;
214 16 ▶ if( lc( $p ) =~ /^(ext|isdn_subaddress)$/ )
Branch: 2 branches
BranchTrueFalseTotal
if (lc($p) =~ /^(ext|isdn_subaddress)$/) { } 10 6 16
elsif (lc $p eq 'phone_context') { } 2 4 6
215 {
216 10 $hash->{ lc( $p ) } = $v;
217 }
218 elsif( lc( $p ) eq 'phone_context' )
219 {
220 2 $hash->{ 'context' } = $v;
221 2 $temp->{ '_has_context_param' } = 1;
222 }
223 else
224 {
225 4 $priv->{ lc( $p ) } = $v;
226 }
227 }
228 290 $self->{ 'private' } = $priv;
229 290 ▶ $self->{ 'ext' } = $temp->{ 'ext' } if( !length( $hash->{ 'ext' } ) && !$self->{ 'is_vanity' } );
Branch: 1 branch
BranchTrueFalseTotal
unless length $hash->{"ext"} or $self->{"is_vanity"} 278 12 290
Condition100%3/3
length $hash->{"ext"} or $self->{"is_vanity"}
l!l&&r!l&&!r
102278
MC/DC100%2/2
length $hash->{"ext"} or $self->{"is_vanity"}
length $hash->{"ext"} $self->{"is_vanity"}
Truth table100%3/3
A or B
A= length $hash->{"ext"}B= $self->{"is_vanity"}
ABresult
1X1
011
000
230 290 $self->{ 'ext' } =~ s/\D//gs;
231 ## Because a context may be +81 or it could be a domain name example.com
232 ## if we had it as a parameter at instantiation, we remember it and honour it when we stringify
233 290 ▶ $self->{ '_prepend_context' } = $temp->{ '_has_context_param' } ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$temp->{'_has_context_param'} ? : 7 283 290
234 290 return( $self );
235 }
236  
237 sub as_string
238 {
239 49 ▶ my $self = shift( @_ );
Subroutine as_string: called CC=16 SCAR=28.2
Pod documented
240 49 ▶ return( $self->{ 'cache' } ) if( length( $self->{ 'cache' } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"cache"} 2 47 49
241 47 ▶ my @uri = ( 'tel:' . $self->{ 'subscriber' } ) if( length( $self->{ 'subscriber' } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"subscriber"} 45 2 47
242 47 my @params = ();
243 47 ▶ push( @params, sprintf( "ext=%s", $self->{ 'ext' } ) ) if( length( $self->{ 'ext' } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"ext"} 21 26 47
244 47 ▶ push( @params, sprintf( "isub=%s", $self->{ 'isdn_subaddress' } ) ) if( length( $self->{ 'isdn_subaddress' } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"isdn_subaddress"} 0 47 47
245 47 ▶ if( length( $self->{ 'context' } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"context"}) 31 16 47
246 {
247 31 ▶ if( !$self->{ '_prepend_context' } )
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->{'_prepend_context'}) { } 15 16 31
elsif (not $self->{'subscriber'} =~ /^\+\d+/ || $self->{'context'} =~ /[a-zA-Z]+/) { } 1 15 16
248 {
249 15 push( @params, sprintf( "phone-context=%s", $self->{ 'context' } ) );
250 }
251 ## Context is not some domain name
252 ▶ elsif( $self->{ 'subscriber' } !~ /^\+\d+/ && $self->{ 'context' } !~ /[a-zA-Z]+/ )
Condition66%2/3
$self->{'subscriber'} =~ /^\+\d+/ || $self->{'context'} =~ /[a-zA-Z]+/
l!l&&r!l&&!r
1501
MC/DC50%1/2
$self->{'subscriber'} =~ /^\+\d+/ || $self->{'context'} =~ /[a-zA-Z]+/
$self->{'subscriber'} =~ /^\+\d+/ $self->{'context'} =~ /[a-zA-Z]+/
Truth table66%2/3
A || B
A= $self->{'subscriber'} =~ /^\+\d+/B= $self->{'context'} =~ /[a-zA-Z]+/
ABresult
1X1
011
000
253 {
254 1 @uri = ( 'tel:' . $self->{ 'context' } . '-' . $self->{ 'subscriber' } );
255 }
256 }
257 47 ▶ if( length( $self->{ 'intl_code' } ) && !$self->{ '_intl_code_from_context' } )
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"intl_code"} and not $self->{"_intl_code_from_context"}) 19 28 47
Condition100%3/3
length $self->{"intl_code"} and not $self->{"_intl_code_from_context"}
!ll&&!rl&&r
22619
MC/DC100%2/2
length $self->{"intl_code"} and not $self->{"_intl_code_from_context"}
length $self->{"intl_code"} not $self->{"_intl_code_from_context"}
Truth table100%3/3
A and not(B)
A= length $self->{"intl_code"}B= not $self->{"_intl_code_from_context"}
ABresult
0X0
100
111
258 {
259 19 ▶ if( $self->{ 'subscriber' } !~ /^\+\d+/ && $uri[0] !~ /^tel\:\+/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"subscriber"} =~ /^\+\d+/ or $uri[0] =~ /^tel\:\+/) 0 19 19
Condition33%1/3
$self->{"subscriber"} =~ /^\+\d+/ or $uri[0] =~ /^tel\:\+/
l!l&&r!l&&!r
1900
MC/DC0%0/2
$self->{"subscriber"} =~ /^\+\d+/ or $uri[0] =~ /^tel\:\+/
$self->{"subscriber"} =~ /^\+\d+/ $uri[0] =~ /^tel\:\+/
Truth table33%1/3
A or B
A= $self->{"subscriber"} =~ /^\+\d+/B= $uri[0] =~ /^tel\:\+/
ABresult
1X1
011
000
260 {
261 0 @uri = ( 'tel:' . '+' . $self->{ 'intl_code' } . '-' . $self->{ 'subscriber' } );
262 }
263 }
264 47 my $priv = $self->{ 'private' };
265 47 foreach my $k ( sort( keys( %$priv ) ) )
266 {
267 8 ▶ push( @params, sprintf( "$k=%s", $priv->{ $k } ) ) if( length( $priv->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $priv->{$k} 8 0 8
268 }
269 47 ▶ push( @uri, join( ';', @params ) ) if( scalar( @params ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @params 28 19 47
270 47 $self->{ 'cache' } = join( ';', @uri );
271 47 return( $self->{ 'cache' } );
272 }
273  
274 3 *letters2digits = \&aton;
275  
276 sub aton
277 {
278 21 ▶ my $self = shift( @_ );
Subroutine aton: called CC=6 SCAR=18.0
Pod documented
279 21 ▶ my $str = shift( @_ ) || $self->{ 'subscriber' };
Condition66%2/3
shift @_ || $self->{'subscriber'}
l!l&&r!l&&!r
0201
MC/DC50%1/2
shift @_ || $self->{'subscriber'}
shift @_ $self->{'subscriber'}
Truth table66%2/3
A || B
A= shift @_B= $self->{'subscriber'}
ABresult
1X1
011
000
280 21 my $letters = 'abcdefghijklmnopqrstuvwxyz';
281 21 my $digits = '22233344455566677778889999';
282 21 ▶ return( $str ) if( $str !~ /[a-zA-Z]+/ || !$self->is_vanity );
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ /[a-zA-Z]+/ and $self->is_vanity 19 2 21
Condition66%2/3
$str =~ /[a-zA-Z]+/ and $self->is_vanity
!ll&&!rl&&r
1902
MC/DC50%1/2
$str =~ /[a-zA-Z]+/ and $self->is_vanity
$str =~ /[a-zA-Z]+/ $self->is_vanity
Truth table66%2/3
A and B
A= $str =~ /[a-zA-Z]+/B= $self->is_vanity
ABresult
0X0
100
111
283 2 $str = lc( $str );
284 2 my $res = '';
285 2 ▶ for( my $i = 0; $i < length( $str ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $str) 26 2 28
286 {
287 26 my $c = substr( $str, $i, 1 );
288 26 my $p = index( $letters, $c );
289 26 ▶ $res .= $p != -1 ? substr( $digits, $p, 1 ) : $c;
Branch: 1 branch
BranchTrueFalseTotal
$p != -1 ? : 14 12 26
290 }
291 2 return( $res );
292 }
293  
294 sub canonical
295 {
296 21 ▶ my $self = shift( @_ );
Subroutine canonical: called CC=5 SCAR=16.1
Pod documented
297 21 my $tel = $self->aton;
298 21 $tel =~ s/[\Q$VISUAL_SEPARATOR\E]+//gs;
299 21 my $uri = $self->new( "tel:$tel" );
300 21 ▶ $uri->ext( $self->{ 'ext' } ) if( length( $self->{ 'ext' } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"ext"} 10 11 21
301 21 ▶ $uri->isub( $self->{ 'isdn_subaddress' } ) if( length( $self->{ 'isdn_subaddress' } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"isdn_subaddress"} 0 21 21
302 21 ▶ $uri->context( $self->{ 'context' } ) if( length( $self->{ 'context' } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"context"} 13 8 21
303 21 ▶ $uri->international_code( $self->{ 'intl_code' } ) if( length( $self->{ 'intl_code' } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"intl_code"} 10 11 21
304 21 $uri->{ '_has_context_param' } = $self->{ '_has_context_param' };
305 21 $uri->{ '_prepend_context' } = $self->{ '_prepend_context' };
306 21 $uri->{ '_intl_code_from_context' } = $self->{ '_intl_code_from_context' };
307 21 $uri->{ 'local_number' } = $self->{ 'local_number' };
308 21 my $priv = $self->{ 'private' };
309 21 %{$uri->{ 'private' }} = %$priv;
310 21 return( $uri );
311 }
312  
313 sub cc2context
314 {
315 1 ▶ my $self = shift( @_ );
Subroutine cc2context: called CC=5 SCAR=16.2
Pod undocumented
316 1 my $cc = uc( shift( @_ ) );
317 1 ▶ return( $self->error( "No country code provided." ) ) if( !length( $cc ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $cc 0 1 1
318 1 $self->_load_countries;
319 1 my $hash = $COUNTRIES;
320 1 foreach my $k ( sort( keys( %$hash ) ) )
321 {
322 ## array ref
323 205 my $ref = $hash->{ $k };
324 205 foreach my $this ( @$ref )
325 {
326 217 ▶ if( $this->{ 'cc' } eq $cc )
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"cc"} eq $cc) 1 216 217
327 {
328 1 return( '+' . $k );
329 }
330 }
331 }
332 ## Nothing found
333 0 return( '' );
334 }
335  
336 sub clone
337 {
338 0 ▶ my $self = shift( @_ );
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
339 0 my $class = ref( $self );
340 0 my $hash = {};
341 0 my @keys = keys( %$self );
342 0 @$hash{ @keys } = @$self{ @keys };
343 0 delete( $hash->{ 'cache' } );
344 0 return( bless( $hash, $class ) );
345 }
346  
347 sub context
348 {
349 280 ▶ my $self = shift( @_ );
Subroutine context: called CC=5 SCAR=16.2
Pod documented
350 280 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 266 280
351 {
352 14 my $str = shift( @_ );
353 14 ▶ if( $str !~ /^$DESCRIPTOR$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($str =~ /^$DESCRIPTOR$/) 0 14 14
354 {
355 0 warn( "'$str' is not a valid context\n" );
356 0 return( undef() );
357 }
358 14 delete( $self->{ 'cache' } );
359 14 $self->{ '_has_context_param' } = 1;
360 14 $self->{ '_prepend_context' } = 0;
361 14 $self->{ 'context' } = $str;
362 ## We found an international country code in the prefix provided, so let's set it
363 14 ▶ if( !length( $self->{ 'intl_code' } ) && ( my $code = $self->_extract_intl_code( $str ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not length $self->{"intl_code"} and my $code = $self->_extract_intl_code($str)) 3 11 14
Condition100%3/3
not length $self->{"intl_code"} and my $code = $self->_extract_intl_code($str)
!ll&&!rl&&r
833
MC/DC100%2/2
not length $self->{"intl_code"} and my $code = $self->_extract_intl_code($str)
not length $self->{"intl_code"} my $code = $self->_extract_intl_code($str)
Truth table100%3/3
not(A) and B
A= not length $self->{"intl_code"}B= my $code = $self->_extract_intl_code($str)
ABresult
0X0
100
111
364 {
365 3 $self->{ '_intl_code_from_context' } = 1;
366 3 $self->{ 'intl_code' } = $code;
367 }
368 }
369 280 return( $self->{ 'context' } );
370 }
371  
372 sub country
373 {
374 266 ▶ my $self = shift( @_ );
Subroutine country: called CC=7 SCAR=20.7
Pod documented
375 3 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
376 266 $self->_load_countries;
377 266 my $hash = $COUNTRIES;
378 266 my $code = $self->international_code;
379 266 ▶ return( wantarray() ? () : [] ) if( !length( $code ) );
Branch: 2 branches
BranchTrueFalseTotal
unless length $code 11 255 266
wantarray ? : 0 11 11
380 255 $code =~ s/[\Q$VISUAL_SEPARATOR\E]+//g;
381 255 ▶ if( $code =~ /^\+($IDD_RE)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ /^\+($IDD_RE)/) 0 255 255
382 {
383 0 $code = $1;
384 }
385 255 ▶ return( wantarray() ? () : [] ) if( !exists( $hash->{ $code } ) );
Branch: 2 branches
BranchTrueFalseTotal
unless exists $hash->{$code} 0 255 255
wantarray ? : 0 0 0
386 255 my $ref = $hash->{ $code };
387 255 ▶ return( wantarray() ? @$ref : \@$ref );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 255 255
388 }
389  
390 sub country_code
391 {
392 245 ▶ my $self = shift( @_ );
Subroutine country_code: called CC=2 SCAR=7.0
Pod undocumented
393 245 my $ref = $self->country_codes;
394 245 ▶ return( '' ) if( ref( $ref ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref ne "ARRAY" 0 245 245
395 245 return( $ref->[0] );
396 }
397  
398 sub country_codes
399 {
400 245 ▶ my $self = shift( @_ );
Subroutine country_codes: called CC=3 SCAR=11.3
Pod undocumented
401 245 my $ref = $self->country;
402 245 ▶ return( '' ) if( ref( $ref ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref ne "ARRAY" 0 245 245
403 245 my @codes = map( $_->{cc}, @$ref );
404 245 ▶ return( wantarray() ? @codes : \@codes );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 245 245
405 }
406  
407 sub country_name
408 {
409 0 ▶ my $self = shift( @_ );
Subroutine country_name: not called CC=2 SCAR=17.9
Pod undocumented
410 0 my $ref = $self->country_names;
411 0 ▶ return( '' ) if( ref( $ref ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref ne "ARRAY" 0 0 0
412 0 return( $ref->[0] );
413 }
414  
415 sub country_names
416 {
417 0 ▶ my $self = shift( @_ );
Subroutine country_names: not called CC=3 SCAR=24.8
Pod undocumented
418 0 my $ref = $self->country;
419 0 ▶ return( '' ) if( ref( $ref ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref ne "ARRAY" 0 0 0
420 0 my @names = map( $_->{name}, @$ref );
421 0 ▶ return( wantarray() ? @names : \@names );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
422 }
423  
424 sub error
425 {
426 0 ▶ my $self = shift( @_ );
Subroutine error: not called CC=7 SCAR=40.3
Pod undocumented
427 0 my $level = 0;
428 0 my $caller = caller;
429 0 my $err = join( '', @_ );
430 0 ▶ my $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
431 0 ▶ if( $err && length( $err ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($err and length $err) 0 0 0
Condition0%0/3
$err and length $err
!ll&&!rl&&r
000
MC/DC0%0/2
$err and length $err
$err length $err
Truth table0%0/3
A and B
A= $errB= length $err
ABresult
0X0
100
111
432 {
433 0 my( $frame, $caller ) = ( $level, '' );
434 0 ▶ while( $caller = ( caller( $frame ) )[ 0 ] )
Branch: 1 branch
BranchTrueFalseTotal
if ($caller = (caller $frame)[0]) 0 0 0
435 {
436 0 ▶ last if( $caller ne 'URI::tel' );
Branch: 1 branch
BranchTrueFalseTotal
if $caller ne "URI::tel" 0 0 0
437 0 $frame++;
438 }
439 0 my( $pack, $file, $line ) = caller( $frame );
440 0 $err =~ s/\n$//gs;
441 0 $self->{ 'error' } = ${ $class . '::ERROR' } = $err;
442 0 return( undef() );
443 }
444 0 ▶ return( $self->{ 'error' } || $ERROR );
Condition0%0/3
$self->{'error'} || $ERROR
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'error'} || $ERROR
$self->{'error'} $ERROR
Truth table0%0/3
A || B
A= $self->{'error'}B= $ERROR
ABresult
1X1
011
000
445 }
446  
447 3 *extension = \&ext;
448  
449 sub ext
450 {
451 33 ▶ my $self = shift( @_ );
Subroutine ext: called CC=4 SCAR=15.0
Pod undocumented
452 33 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 11 22 33
453 {
454 11 my $val = shift( @_ );
455 11 ▶ if( length( $val ) && $val !~ /^[$PHONEDIGIT]+$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (length $val and not $val =~ /^[$PHONEDIGIT]+$/) 0 11 11
Condition33%1/3
length $val and not $val =~ /^[$PHONEDIGIT]+$/
!ll&&!rl&&r
0110
MC/DC0%0/2
length $val and not $val =~ /^[$PHONEDIGIT]+$/
length $val not $val =~ /^[$PHONEDIGIT]+$/
Truth table33%1/3
A and not(B)
A= length $valB= not $val =~ /^[$PHONEDIGIT]+$/
ABresult
0X0
100
111
456 {
457 0 warn( "'$val' is not a valid extension ([$PHONEDIGIT]+)\n" );
458 0 return( undef() );
459 }
460 11 delete( $self->{ 'cache' } );
461 11 $self->{ 'ext' } = $val;
462 }
463 33 return( $self->{ 'ext' } );
464 }
465  
466 sub international_code
467 {
468 276 ▶ my $self = shift( @_ );
Subroutine international_code: called CC=4 SCAR=14.7
Pod documented
469 276 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 10 266 276
470 {
471 10 my $val = shift( @_ );
472 10 ▶ if( length( $val ) && $val !~ /^[$PHONEDIGIT]+$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (length $val and not $val =~ /^[$PHONEDIGIT]+$/) 0 10 10
Condition33%1/3
length $val and not $val =~ /^[$PHONEDIGIT]+$/
!ll&&!rl&&r
0100
MC/DC0%0/2
length $val and not $val =~ /^[$PHONEDIGIT]+$/
length $val not $val =~ /^[$PHONEDIGIT]+$/
Truth table33%1/3
A and not(B)
A= length $valB= not $val =~ /^[$PHONEDIGIT]+$/
ABresult
0X0
100
111
473 {
474 0 warn( "'$val' is not a valid international code.\n" );
475 0 return( undef() );
476 }
477 10 delete( $self->{ 'cache' } );
478 ## The international code was provided by the user as opposed to using the context() method,
479 ## so we flag it properly so it can be used in stringification of the phone number
480 10 $self->{ '_intl_code_from_context' } = 0;
481 10 $self->{ 'is_global' } = 1;
482 10 $self->{ 'intl_code' } = $val;
483 }
484 276 return( $self->{ 'intl_code' } );
485 }
486  
487 sub is_global
488 {
489 21 ▶ return( shift->{ 'is_global' } );
Subroutine is_global: called CC=1 SCAR=0.0
Pod documented
490 }
491  
492 sub is_local
493 {
494 0 ▶ return( shift->{ 'is_local' } );
Subroutine is_local: not called CC=1 SCAR=6.9
Pod documented
495 }
496  
497 sub is_other
498 {
499 0 ▶ return( shift->{ 'is_other' } );
Subroutine is_other: not called CC=1 SCAR=6.9
Pod documented
500 }
501  
502 sub is_vanity
503 {
504 2 ▶ return( shift->{ 'is_vanity' } );
Subroutine is_vanity: called CC=1 SCAR=0.0
Pod documented
505 }
506  
507 3 *isdn_subaddress = \&isub;
508 sub isub
509 {
510 21 ▶ my $self = shift( @_ );
Subroutine isub: called CC=4 SCAR=23.7
Pod documented
511 21 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 21 21
512 {
513 0 my $val = shift( @_ );
514 0 ▶ if( length( $val ) && $val !~ /^$URIC$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (length $val and not $val =~ /^$URIC$/) 0 0 0
Condition0%0/3
length $val and not $val =~ /^$URIC$/
!ll&&!rl&&r
000
MC/DC0%0/2
length $val and not $val =~ /^$URIC$/
length $val not $val =~ /^$URIC$/
Truth table0%0/3
A and not(B)
A= length $valB= not $val =~ /^$URIC$/
ABresult
0X0
100
111
515 {
516 0 warn( "'$val' is not a isdn subaddress\n" );
517 0 return( undef() );
518 }
519 0 delete( $self->{ 'cache' } );
520 0 $self->{ 'isub' } = $val;
521 }
522 21 return( $self->{ 'isub' } );
523 }
524  
525 sub original
526 {
527 0 ▶ return( shift->{ 'original' } );
Subroutine original: not called CC=1 SCAR=6.9
Pod documented
528 }
529  
530 sub prepend_context
531 {
532 1 ▶ my $self = shift( @_ );
Subroutine prepend_context: called CC=2 SCAR=7.0
Pod undocumented
533 1 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
534 {
535 1 $self->{ '_prepend_context' } = shift( @_ );
536 1 delete( $self->{ 'cache' } );
537 }
538 1 return( $self->{ '_prepend_context' } );
539 }
540  
541 sub private
542 {
543 3 ▶ my $self = shift( @_ );
Subroutine private: called CC=8 SCAR=37.1
Pod documented
544 3 my( $name, $val ) = @_;
545 3 ▶ if( length( $name ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $name) 0 3 3
546 {
547 ## The value could be blank and if so, we would remove the parameter
548 0 ▶ if( defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
549 {
550 0 ▶ if( $name !~ /^$PNAME$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($name =~ /^$PNAME$/) 0 0 0
551 {
552 0 warn( "'$name' is not a valid parameter name.\n" );
553 0 return( undef() );
554 }
555 0 ▶ if( length( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $val) { } 0 0 0
556 {
557 0 ▶ if( $val !~ /^$PVALUE$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($val =~ /^$PVALUE$/) 0 0 0
558 {
559 0 warn( "'$val' is not a valid parameter value.\n" );
560 0 return( undef() );
561 }
562 0 delete( $self->{ 'cache' } );
563 0 $self->{ 'private' }->{ $name } = $val;
564 0 return( $self->{ 'private' }->{ $name } );
565 }
566 else
567 {
568 0 return( delete( $self->{ 'private' }->{ $name } ) );
569 }
570 }
571 else
572 {
573 0 ▶ return( wantarray() ? %${$self->{ 'private' }->{ $name }} : \%${$self->{ 'private' }->{ $name }} );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
574 }
575 }
576 3 ▶ return( wantarray() ? %{$self->{ 'private' }} : \%{$self->{ 'private' }} );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
577 }
578  
579 sub subscriber
580 {
581 21 ▶ my $self = shift( @_ );
Subroutine subscriber: called CC=4 SCAR=23.7
Pod documented
582 21 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 21 21
583 {
584 0 my $val = shift( @_ );
585 0 ▶ if( length( $val ) && $val !~ /^$TEL_SUBSCRIBER$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (length $val and not $val =~ /^$TEL_SUBSCRIBER$/) 0 0 0
Condition0%0/3
length $val and not $val =~ /^$TEL_SUBSCRIBER$/
!ll&&!rl&&r
000
MC/DC0%0/2
length $val and not $val =~ /^$TEL_SUBSCRIBER$/
length $val not $val =~ /^$TEL_SUBSCRIBER$/
Truth table0%0/3
A and not(B)
A= length $valB= not $val =~ /^$TEL_SUBSCRIBER$/
ABresult
0X0
100
111
586 {
587 0 warn( "'$val' is not a valid subscriber value.\n" );
588 0 return( undef() );
589 }
590 0 delete( $self->{ 'cache' } );
591 0 $self->{ 'subscriber' } = $val;
592 }
593 21 return( $self->{ 'subscriber' } );
594 }
595  
596 sub type
597 {
598 0 ▶ return( shift->{ 'type' } );
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
599 }
600  
601 sub _extract_intl_code
602 {
603 271 ▶ my $self = shift( @_ );
Subroutine _extract_intl_code: called CC=6 SCAR=17.9
604 271 ▶ my $str = shift( @_ ) || return( '' );
Condition50%1/2
shift @_ || (return '')
l!l
2710
MC/DC0%0/1
shift @_ || (return '')
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
605 #print( STDERR "Trying to find international code from '$str'\n" );
606 271 my $code;
607 ## Extract the global idd
608 271 $self->_load_countries;
609 271 ( my $str2 = $str ) =~ s/[\Q$VISUAL_SEPARATOR\E]+//g;
610 271 $str2 =~ s/^tel\://;
611 271 ▶ if( $str2 =~ /^\+($IDD_RE)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($str2 =~ /^\+($IDD_RE)/) 268 3 271
612 {
613 268 my $idd = $1;
614 #print( STDERR "\tIDD is '$idd'\n" );
615 268 ▶ if( CORE::exists( $COUNTRIES->{ $idd } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $COUNTRIES->{$idd}) 268 0 268
616 {
617 268 my $idds = $COUNTRIES->{ $idd }->[0]->{ 'idd' };
618 #print( STDERR "\tFound entry.\n" );
619 268 foreach my $thisIdd ( @$idds )
620 {
621 277 my $check = $thisIdd;
622 277 $check =~ s/\D//g;
623 277 ▶ if( $check eq $idd )
Branch: 1 branch
BranchTrueFalseTotal
if ($check eq $idd) 268 9 277
624 {
625 #$temp->{ 'context' } = '+' . $thisIdd;
626 268 $code = $thisIdd;
627 268 last;
628 }
629 }
630 }
631 }
632 #print( STDERR "\tReturning '$code'\n" );
633 271 return( $code );
634 }
635  
636 sub _extract_local_number
637 {
638 262 ▶ my $self = shift( @_ );
Subroutine _extract_local_number: called CC=6 SCAR=18.0
639 262 my( $intl_code, $subscriber ) = @_;
640 262 my $j = 0;
641 262 ▶ for( my $i = 0; $i < length( $intl_code ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $intl_code) 800 262 1062
642 {
643 # Skip until we are on a number
644 800 ▶ next if( substr( $intl_code, $i, 1 ) !~ /^\d$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless substr($intl_code, $i, 1) =~ /^\d$/ 42 758 800
645 # and here too so we can compare number to number
646 758 ▶ while( substr( $subscriber, $j, 1 ) !~ /^\d$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless (substr($subscriber, $j, 1) =~ /^\d$/) 262 758 1020
647 {
648 262 $j++;
649 }
650 # Our international code does not seem to match the prefix of our subscriber! This should not happen.
651 758 ▶ if( substr( $subscriber, $j, 1 ) ne substr( $intl_code, $i, 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (substr($subscriber, $j, 1) ne substr($intl_code, $i, 1)) 0 758 758
652 {
653 # printf( STDERR "Mismatch... %s at position %d vs %s at position %d\n", substr( $intl_code, $i, 1 ), $i, substr( $subscriber, $j, 1 ), $j );
654 #last;
655 0 return( '' );
656 }
657 758 $j++;
658 }
659 262 ▶ $j++ while( substr( $subscriber, $j, 1 ) !~ /^\d$/ );
Branch: 1 branch
BranchTrueFalseTotal
substr($subscriber, $j, 1) =~ /^\d$/ or do { ++$j } 252 262 514
660 262 return( substr( $subscriber, $j ) );
661 }
662  
663 # Check if two objects are the same object
664 # https://tools.ietf.org/search/rfc3966#section-4
665 sub _obj_eq
666 {
667 ##return overload::StrVal( $_[0] ) eq overload::StrVal( $_[1] );
668 3 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
669 0 ▶ my $self = shift( @_ );
Subroutine _obj_eq: not called CC=12 SCAR=48.6
670 0 my $other = shift( @_ );
671 0 ▶ return( 0 ) if( !ref( $other ) || !$other->isa( 'URI::tel' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $other and $other->isa("URI::tel") 0 0 0
Condition0%0/3
ref $other and $other->isa("URI::tel")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $other and $other->isa("URI::tel")
ref $other $other->isa("URI::tel")
Truth table0%0/3
A and B
A= ref $otherB= $other->isa("URI::tel")
ABresult
0X0
100
111
672 0 my $sub = $self->canonical->subscriber;
673 0 my $sub2 = $other->canonical->subscriber;
674 0 $sub =~ s/^\+//;
675 0 $sub2 =~ s/^\+//;
676 0 ▶ return( 0 ) if( $sub ne $sub2 );
Branch: 1 branch
BranchTrueFalseTotal
if $sub ne $sub2 0 0 0
677 0 my $context = $self->context;
678 0 my $context2 = $other->context;
679 0 ▶ return( 0 ) if( $context ne $context2 );
Branch: 1 branch
BranchTrueFalseTotal
if $context ne $context2 0 0 0
680 0 my $ext = $self->ext;
681 0 my $ext2 = $other->ext;
682 0 ▶ return( 0 ) if( $ext ne $ext2 );
Branch: 1 branch
BranchTrueFalseTotal
if $ext ne $ext2 0 0 0
683 0 my $priv = $self->private;
684 0 my $priv2 = $other->private;
685 0 foreach my $k ( keys( %$priv ) )
686 {
687 0 ▶ return( 0 ) if( !exists( $priv2->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $priv2->{$k} 0 0 0
688 0 ▶ return( 0 ) if( $priv->{ $k } ne $priv2->{ $k } );
Branch: 1 branch
BranchTrueFalseTotal
if $priv->{$k} ne $priv2->{$k} 0 0 0
689 }
690 0 foreach my $k ( keys( %$priv2 ) )
691 {
692 0 ▶ return( 0 ) if( !exists( $priv->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $priv->{$k} 0 0 0
693 0 ▶ return( 0 ) if( $priv2->{ $k } ne $priv->{ $k } );
Branch: 1 branch
BranchTrueFalseTotal
if $priv2->{$k} ne $priv->{$k} 0 0 0
694 }
695 3 ▶ use overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
696 0 return( 1 );
697 }
698  
699 ## Taken from http://www.perlmonks.org/bare/?node_id=319761
700 ## This will do a split on a semi-colon, but being mindful if before it there is an escaped backslash
701 ## For example, this would not be skipped: something\;here
702 ## But this would be split: something\\;here resulting in something\ and here after unescaping
703 sub split_str
704 {
705 10 ▶ my $self = shift( @_ );
Subroutine split_str: called CC=4 SCAR=13.9
Pod undocumented
706 10 my $s = shift( @_ );
707 10 ▶ my $sep = @_ ? shift( @_ ) : ';';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 10 10
708 10 my @parts = ();
709 10 my $i = 0;
710 10 foreach( split( /(\\.)|$sep/, $s ) )
711 {
712 22 ▶ defined( $_ ) ? do{ $parts[$i] .= $_ } : do{ $i++ };
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 16 6 22
713 }
714 10 return( @parts );
715 }
716  
717 sub _load_countries
718 {
719 539 ▶ my $self = shift( @_ );
Subroutine _load_countries: called CC=10 SCAR=23.0
720 539 ▶ if( !%$COUNTRIES )
Branch: 1 branch
BranchTrueFalseTotal
if (not %$COUNTRIES) 2 537 539
721 {
722 2 my $in = 0;
723 2 my $hash = {};
724 2 my @data = <DATA>;
725 2 foreach ( @data )
726 {
727 960 chomp;
728 960 ▶ next unless( $in || /^\#{2} BEGIN DATA/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $in or /^\#{2} BEGIN DATA/ 456 504 960
Condition100%3/3
$in or /^\#{2} BEGIN DATA/
l!l&&r!l&&!r
5022456
MC/DC100%2/2
$in or /^\#{2} BEGIN DATA/
$in /^\#{2} BEGIN DATA/
Truth table100%3/3
A or B
A= $inB= /^\#{2} BEGIN DATA/
ABresult
1X1
011
000
729 504 ▶ last if( /^\#{2} END DATA/ );
Branch: 1 branch
BranchTrueFalseTotal
if /^\#{2} END DATA/ 2 502 504
730 502 $in++;
731 502 ▶ next if( /^\#{2} BEGIN DATA/ );
Branch: 1 branch
BranchTrueFalseTotal
if /^\#{2} BEGIN DATA/ 2 500 502
732 500 my( $cc, $cc3, $name, $idd ) = split( /[[:blank:]]*\;[[:blank:]]*/, $_ );
733 500 ▶ my $keys = index( $idd, ',' ) != -1 ? [ split( /[[:blank:]]*\,[[:blank:]]*/, $idd ) ] : [ $idd ];
Branch: 1 branch
BranchTrueFalseTotal
index($idd, ',') != -1 ? : 10 490 500
734 500 my $info =
735 {
736 'cc' => $cc,
737 'cc3' => $cc3,
738 'name' => $name,
739 'idd' => $idd,
740 };
741 500 $info->{ 'idd' } = $keys;
742 500 foreach my $k ( @$keys )
743 {
744 514 my $k2 = $k;
745 514 $k2 =~ s/-//gs;
746 514 ▶ $hash->{ $k2 } = [] if( !exists( $hash->{ $k2 } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{$k2} 490 24 514
747 514 push( @{$hash->{ $k2 }}, $info );
748 }
749 }
750 2 $COUNTRIES = $hash;
751 2 my @list = sort{ $b <=> $a } keys( %$hash );
752 2 my $re_list = join( '|', @list );
753 2 $IDD_RE = qr{(?:$re_list)};
754 }
755 }
756  
757 3 1;
758  
759 __DATA__
↑ Summary