blib/lib/URI/tel.pm

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