blib/lib/Number/Phone/NANP.pm

filter: Statementstmt 68.7% 757 / 1101 Branchbran 94.4% 51 / 54 Conditioncond 95.2% 20 / 21 MC/DCmcdc 90.9% 10 / 11 Subroutinesub 100% 367 / 367 Podpod 100% 15 / 15 totaltotal 77.7% 1220 / 1569 CC 35 SCAR 3.7
CC
35
Cov
70%
is_valid
10.0
_datafh
5.1
_get_data_starting_from_pointer_at_offset
4.0
CRAP 1.5
« blib/lib/Number/Phone/StubCountry/IE.pm ↑ Summary blib/lib/Number/Phone/StubCountry/TT.pm »
1 package Number::Phone::NANP;
2  
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 15 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 15 ▶use base 'Number::Phone';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use Number::Phone::NANP::Data;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 14 ▶use Number::Phone::Country;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 11 our $VERSION = '1.7001';
13  
14 11 my $cache = {};
15  
16 =head1 NAME
17  
18 Number::Phone::NANP - NANP-specific methods for Number::Phone
19  
20 =head1 DESCRIPTION
21  
22 This is a base class which encapsulates that information about phone
23 numbers in the North American Numbering Plan (NANP) which are
24 common to all NANP countries - that is, those whose international
25 dialling code is +1.
26  
27 Country-specific modules should inherit from this module and provide
28 their own versions of methods as necessary. However, they should not
29 provide an C<is_valid> method or a constructor.
30  
31 =head1 SYNOPSIS
32  
33 This module should not be used directly. It will be loaded as necessary
34 by Number::Phone:
35  
36 use Number::Phone;
37  
38 my $phone_number = Number::Phone->new('+1 202 418 1440');
39 # $phone_number is now a Number::Phone::NANP::US
40  
41 my $other_phone_number = Number::Phone->new('+1 866 623 2282');
42 # $phone_number is non-geographic so is a Number::Phone::NANP
43  
44 =cut
45  
46 975 ▶sub new {
Subroutine new: called CC=3 SCAR=12.3
Pod documented
47 975 my $class = shift;
48 973 my $number = shift;
49  
50 973 ▶ return undef if(!is_valid($number));
Branch: 1 branch
BranchTrueFalseTotal
unless is_valid($number) 465 505 970
51
52 # cunningly, N::P::C::p2c supports local NANPish number formats
53 # as well as +1XXXXXXXXXX format. Yay!
54 510 my $country = Number::Phone::Country::phone2country($number);
55
56 # try to load country class
57 0 ▶ eval "use Number::Phone::NANP::$country;";
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
58 # if we fail, return a generic NANP object, which just happens to
59 # also be the right thing to do for pan-NANP numbers like 800
60 508 ▶ return bless(\$number, $class) if($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 238 267 505
61 272 return bless(\$number, $class."::$country");
62 }
63  
64 =head1 METHODS
65  
66 The following methods from Number::Phone are overridden:
67  
68 =over 4
69  
70 =item new
71  
72 The constructor, you should never have to call this yourself. To create an
73 object the canonical incantation is C<Number::Phone->new('+1 ...')>.
74  
75 =item operator
76  
77 For some countries operator data is available.
78  
79 =item data_source
80  
81 Returns a string telling where and when the data for operators was last updated, looking something like:
82  
83 "localcallingguide.com at Wed Sep 30 10:37:39 2020 UTC"
84  
85 The current value of this is also documented in L<Number::Phone::Data>.
86  
87 =cut
88  
89 # some faffing about to re-open the database if we fork
90 11 my $WORDLENGTH;
91 my $datafh;
92 11 my $pid = -1;
93 366 ▶sub _datafh {
Subroutine _datafh: called CC=5 SCAR=16.3
94 364 ▶ if(!$datafh || $pid != $$) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $datafh or $pid != $$) 1 360 361
Condition66%2/3
not $datafh or $pid != $$
l!l&&r!l&&!r
10360
MC/DC50%1/2
not $datafh or $pid != $$
not $datafh $pid != $$
Truth table66%2/3
not(A) or B
A= not $datafhB= $pid != $$
ABresult
1X1
011
000
95 4 my $file = Number::Phone::_find_data_file('Number-Phone-NANP-Data.db');
96 6 ▶ open($datafh, '<:bytes', $file) || die("Can't read $file: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $datafh, "<:bytes", $file or die "Can't read ${file}: $!" 1 0 1
97 4 read($datafh, my $header, 8);
98 4 ▶ die("$file isn't the right format\n") unless($header eq 'NANPOP'.chr(0).chr(0));
Branch: 1 branch
BranchTrueFalseTotal
unless $header eq "NANPOP\0\0" 0 1 1
99 6 read($datafh, $WORDLENGTH, 1);
100 4 $WORDLENGTH = ord($WORDLENGTH);
101 4 $pid = $$;
102 }
103 366 return $datafh;
104 }
105  
106 46 ▶sub operator {
Subroutine operator: called CC=1 SCAR=0.0
Pod documented
107 44 my $self = shift;
108  
109 # file needs to be open so we have a $WORDLENGTH
110 44 $self->_datafh();
111  
112 43 (my $number = ${$self}) =~ s/\D//g;
113 42 my $ten_thousands = substr($number, 1, 6);
114  
115 43 $ten_thousands -= 200000; # area codes below 200 are invalid
116 42 return $self->_get_data_starting_from_pointer_at_offset($WORDLENGTH * $ten_thousands);
117 }
118  
119 58 ▶sub _get_data_starting_from_pointer_at_offset {
Subroutine _get_data_starting_from_pointer_at_offset: called CC=4 SCAR=13.9
120 54 my($self, $offset) = @_;
121  
122 55 my $pointer = $self->_get_pointer_at_offset($offset);
123 54 ▶ return undef unless($pointer);
Branch: 1 branch
BranchTrueFalseTotal
unless $pointer 3 50 53
124  
125 51 my $block_type = $self->_get_block_type_at_offset($pointer);
126 52 $pointer += 1;
127  
128 52 ▶ if($block_type == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($block_type == 0) { } 38 12 50
elsif ($block_type == 1) { } 12 0 12
129 # $pointer points at a string
130 40 return $self->_get_string_at_offset($pointer);
131 } elsif($block_type == 1) {
132 # $pointer points at a block of pointers
133 14 (my $number = ${$self}) =~ s/\D//g;
134 14 my $thousands = substr($number, 7, 1); # the seventh digit
135 14 return $self->_get_data_starting_from_pointer_at_offset($pointer + $WORDLENGTH * $thousands);
136 } else {
137 2 die("Don't know how to handle a block of type $block_type at ".($pointer - 1)."\n");
138 }
139 }
140  
141 55 ▶sub _get_block_type_at_offset {
Subroutine _get_block_type_at_offset: called CC=1 SCAR=0.0
142 52 my($self, $offset) = @_;
143  
144 52 seek($self->_datafh(), $offset, 0);
145 52 read($self->_datafh(), my $block_type, 1);
146 52 return ord($block_type);
147 }
148  
149 43 ▶sub _get_string_at_offset {
Subroutine _get_string_at_offset: called CC=1 SCAR=0.0
150 40 my($self, $offset) = @_;
151  
152 40 seek($self->_datafh(), $offset, 0);
153 40 read($self->_datafh(), my $chars, 1);
154 40 $chars = unpack('C', $chars);
155 40 read($self->_datafh(), my $string, $chars);
156 40 return $string;
157 }
158  
159 55 ▶sub _get_pointer_at_offset {
Subroutine _get_pointer_at_offset: called CC=1 SCAR=0.0
160 55 my($self, $offset) = @_;
161  
162 54 seek($self->_datafh(), $offset, 0);
163 54 read($self->_datafh(), my $pointer, $WORDLENGTH);
164 55 return unpack('N', $pointer);
165 }
166  
167 =item is_valid
168  
169 The number is valid within the numbering scheme. It may or may
170 not yet be allocated, or it may be reserved.
171  
172 =item is_geographic
173  
174 NANP-globals like 1-800 aren't geographic, the rest are.
175  
176 As a special case, 1-600 is non-geographic. So too will be
177 1-622/633/644/655/677/688 when they come in to service.
178  
179 =item is_mobile
180  
181 NANP-globals like 1-800 aren't mobile. For most others we just don't know because
182 the data isn't published. libphonenumber has data for *some* countries, so we use
183 that if we can.
184  
185 =item is_fixed_line
186  
187 NANP-globals are fixed lines, for the rest we generally don't know with some
188 exceptions as per is_mobile above.
189  
190 =cut
191  
192 # NB the EF digits being 11 *is* legal in at least some area codes.
193 # Obviously you can't dial, eg, 911-1234
194 976 ▶sub is_valid {
Subroutine is_valid: called CC=10 SCAR=23.0
Pod documented
195 975 my $number = shift;
196  
197 # If called as an object method, it *must* be valid otherwise the
198 # object would never have been instantiated.
199 # If called as a sub, then it's the constructor that's calling.
200 975 ▶ return 1 if(blessed($number));
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($number) 4 970 974
201  
202 # otherwise we have to validate
203  
204 # if we've seen this number before, use cached result
205 972 ▶ return 1 if($cache->{$number}->{is_valid});
Branch: 1 branch
BranchTrueFalseTotal
if $cache->{$number}{"is_valid"} 348 622 970
206  
207 623 my $parsed_number = $number;
208 623 my %digits;
209 624 $parsed_number =~ s/[^\d+]//g; # strip non-digits/plusses
210 623 $parsed_number =~ s/^\+1//; # remove leading +1
211  
212 623 @digits{qw(A B C D)} = split(//, $parsed_number, 5);
213  
214 # this is checked in N::P::C::phone2country_and_idd waaaay before we
215 # ever get here. NB leave this here in case a refactor makes that go
216 # away. There are tests for this!
217 #
218 # # and quickly check length
219 # if(length($parsed_number) != 10) {
220 # $cache->{$number}->{is_valid} = 0;
221 # return 0;
222 # }
223
224 $cache->{$number}->{is_valid} = (
225 $digits{A} ne '1' &&
226 $digits{B}.$digits{C} ne '11' &&
227  
228 # checked on 2025-03-23
229 # next check due 2027-01-01 (annually)
230 # https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#Summary_table
231 $digits{B} ne '9' &&
232 $digits{A}.$digits{B} ne '37' &&
233 624 ▶ $digits{A}.$digits{B} ne '96'
Branch: 1 branch
BranchTrueFalseTotal
$digits{'A'} ne '1' && $digits{'B'} . $digits{'C'} ne '11' && $digits{'B'} ne '9' && $digits{'A'} . $digits{'B'} ne '37' && $digits{'A'} . $digits{'B'} ne '96' ? : 617 5 622
Condition100%12/12
$digits{"A"} ne 1 and $digits{"B"} . $digits{"C"} ne 11 and $digits{"B"} ne 9 and $digits{"A"} . $digits{"B"} ne 37 and $digits{"A"} . $digits{"B"} ne 96
!ll&&!rl&&r
41617
$digits{"A"} ne 1 and $digits{"B"} . $digits{"C"} ne 11 and $digits{"B"} ne 9 and $digits{"A"} . $digits{"B"} ne 37
!ll&&!rl&&r
31618
$digits{"A"} ne 1 and $digits{"B"} . $digits{"C"} ne 11 and $digits{"B"} ne 9
!ll&&!rl&&r
21619
$digits{"A"} ne 1 and $digits{"B"} . $digits{"C"} ne 11
!ll&&!rl&&r
11620
MC/DC100%5/5
$digits{"A"} ne 1 and $digits{"B"} . $digits{"C"} ne 11 and $digits{"B"} ne 9 and $digits{"A"} . $digits{"B"} ne 37 and $digits{"A"} . $digits{"B"} ne 96
$digits{"A"} ne 1 $digits{"B"} . $digits{"C"} ne 11 $digits{"B"} ne 9 $digits{"A"} . $digits{"B"} ne 37 $digits{"A"} . $digits{"B"} ne 96
Truth table100%6/6
A and B and C and D and E
A= $digits{"A"} ne 1B= $digits{"B"} . $digits{"C"} ne 11C= $digits{"B"} ne 9D= $digits{"A"} . $digits{"B"} ne 37E= $digits{"A"} . $digits{"B"} ne 96
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
234 ) ? 1 : 0;
235  
236 # Dominican Republic has local-only toll-free numbers with D = 0 or 1
237 623 ▶ if($digits{D} eq 1 && join('', @digits{'A', 'B', 'C'}) !~ /^8[024]9/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($digits{"D"} eq 1 and not join("", @digits{"A", "B", "C"}) =~ /^8[024]9/) 460 162 622
Condition100%3/3
$digits{"D"} eq 1 and not join("", @digits{"A", "B", "C"}) =~ /^8[024]9/
!ll&&!rl&&r
1593460
MC/DC100%2/2
$digits{"D"} eq 1 and not join("", @digits{"A", "B", "C"}) =~ /^8[024]9/
$digits{"D"} eq 1 not join("", @digits{"A", "B", "C"}) =~ /^8[024]9/
Truth table100%3/3
A and not(B)
A= $digits{"D"} eq 1B= not join("", @digits{"A", "B", "C"}) =~ /^8[024]9/
ABresult
0X0
100
111
238 461 $cache->{$number}->{is_valid} = 0;
239 }
240  
241 624 $cache->{$number}->{areacode} = substr($parsed_number, 0, 3);
242 623 $cache->{$number}->{subscriber} = substr($parsed_number, 3);
243 623 return $cache->{$number}->{is_valid};
244 }
245  
246 # define the other methods
247  
248 11 foreach my $method (qw(areacode subscriber)) {
249 14 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
250 20 ▶ *{__PACKAGE__."::$method"} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
251 170 my $self = shift;
252 169 return $cache->{${$self}}->{$method};
253 }
254 20 }
255  
256 159 ▶sub _is_canadian_600 {
Subroutine _is_canadian_600: called CC=1 SCAR=0.0
257 159 my $self = shift;
258 158 ${$self} =~ /^(\+1)?6([0234578])\2/;
259 }
260  
261 159 ▶sub is_geographic {
Subroutine is_geographic: called CC=3 SCAR=11.0
Pod documented
262 159 my $self = shift;
263 # 600 is non-geographic. 6(22|33|44|55|77|88) are reserved
264 # for non-geographic use but not yet in use
265 158 ▶ return 0 if($self->_is_canadian_600());
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_canadian_600 1 156 157
266 # NANP-globals like 1-800 aren't geographic, the rest are
267 157 ▶ return ref($self) eq __PACKAGE__ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
ref $self eq __PACKAGE__ ? : 1 155 156
268 }
269  
270 83 ▶sub is_mobile {
Subroutine is_mobile: called CC=4 SCAR=13.9
Pod documented
271 83 my $self = shift;
272 # NANP-globals like 1-800 aren't mobile
273 83 ▶ if(ref($self) eq __PACKAGE__) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self eq __PACKAGE__) 1 80 81
274 82 (my $ISO_country_code = ref($self)) =~ s/.*(..)$/$1/;
275 82 ▶ return undef if(!exists($Number::Phone::NANP::Data::mobile_regexes{$ISO_country_code}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Number::Phone::NANP::Data::mobile_regexes{$ISO_country_code} 30 50 80
276 52 ▶ return ${$self} =~ /^\+1($Number::Phone::NANP::Data::mobile_regexes{$ISO_country_code})$/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
${$self;} =~ /^\+1($Number::Phone::NANP::Data::mobile_regexes{$ISO_country_code})$/ ? : 49 1 50
277 }
278  
279 83 ▶sub is_fixed_line {
Subroutine is_fixed_line: called CC=4 SCAR=13.9
Pod documented
280 83 my $self = shift;
281 # NANP-globals like 1-800 are fixed
282 83 ▶ if(ref($self) eq __PACKAGE__) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self eq __PACKAGE__) 1 80 81
283 82 (my $ISO_country_code = ref($self)) =~ s/.*(..)$/$1/;
284 82 ▶ return undef if(!exists($Number::Phone::NANP::Data::fixed_line_regexes{$ISO_country_code}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Number::Phone::NANP::Data::fixed_line_regexes{$ISO_country_code} 30 50 80
285 52 ▶ return ${$self} =~ /^\+1($Number::Phone::NANP::Data::fixed_line_regexes{$ISO_country_code})$/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
${$self;} =~ /^\+1($Number::Phone::NANP::Data::fixed_line_regexes{$ISO_country_code})$/ ? : 49 1 50
286 }
287  
288 =item is_drama
289  
290 The number is a '555' number. Numbers with the D, E, and F digits set to 555
291 are not allocated to real customers, and are intended for use in fiction. eg
292 212 555 2368 for Ghostbusters.
293  
294 NB, despite Ghostbusters above, only 555-0100 to 555-0199 are actually reserved.
295  
296 =cut
297  
298 8 ▶sub is_drama {
Subroutine is_drama: called CC=4 SCAR=13.9
Pod documented
299 8 my $self = shift;
300 8 ▶ if(${$self} =~ /555(\d{4})$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (${$self;} =~ /555(\d{4})$/) 5 1 6
301 7 ▶ return ($1 gt '0099' && $1 lt '0200') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$1 gt '0099' && $1 lt '0200' ? : 1 4 5
Condition100%3/3
$1 gt "0099" and $1 lt "0200"
!ll&&!rl&&r
131
MC/DC100%2/2
$1 gt "0099" and $1 lt "0200"
$1 gt "0099" $1 lt "0200"
Truth table100%3/3
A and B
A= $1 gt "0099"B= $1 lt "0200"
ABresult
0X0
100
111
302 }
303 3 return 0;
304 }
305  
306 =item is_government
307  
308 Area code 710 is reserved for the US Feds, but apparently only one number
309 in the whole area code works.
310  
311 =cut
312  
313 6 ▶sub is_government {
Subroutine is_government: called CC=2 SCAR=6.9
Pod documented
314 5 my $self = shift;
315 5 ▶ if(${$self} =~ /^(\+1)?710/) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (${$self;} =~ /^(\+1)?710/) { } 1 3 4
316 4 else { return 0; }
317 }
318  
319 =item is_tollfree
320  
321 The number is free to the caller. 800, 833, 844, 855, 866, 877 and 888 "area codes"
322  
323 =cut
324  
325 92 ▶sub is_tollfree {
Subroutine is_tollfree: called CC=2 SCAR=6.9
Pod documented
326 92 my $self = shift;
327  
328 # FIXME this really should be data-driven, based on US data in libphonenumber
329 # https://en.wikipedia.org/wiki/Toll-free_telephone_numbers_in_the_North_American_Numbering_Plan
330 # see also tests in t/nanp.t if anything changes
331 # checked on 2025-12-10
332 # next check due 2026-12-01 (annually)
333 91 ▶ if(${$self} =~ /^(\+1)?8(00|33|44|55|66|77|88)/) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (${$self;} =~ /^(\+1)?8(00|33|44|55|66|77|88)/) { } 83 7 90
334 8 else { return 0; }
335 }
336  
337 =item is_specialrate
338  
339 The number is charged at a higher rate than normal. The 900 "area code"
340 and some parts of 242 and 246 (Bahamas and Barbados).
341  
342 =cut
343  
344 88 ▶sub is_specialrate {
Subroutine is_specialrate: called CC=2 SCAR=6.9
Pod documented
345 87 my $self = shift;
346 # FIXME this realy should be data-driven, based on data in libphonenumber
347 # check BS and BB against libphonenumber data
348 # checked on 2025-12-10
349 # next check due 2026-12-01 (annually)
350 88 ▶ if(${$self} =~ /
Branch: 1 branch
BranchTrueFalseTotal
if (${$self;} =~ / ^(\+1)? ( # NANP-global for local premium rate numbers in any NPA ...976 | # BB UAN 246(?: 292| 367| 4(?: 1[7-9]| 3[01]| 4[47-9]| 67 )| 7(?: 1[2-9]| 2\d| 3[016]| 53 ) ) | # BS UAN 242225 | # NANP-global 900 ) /x) { } 83 3 86
351 ^(\+1)?
352 (
353 # NANP-global for local premium rate numbers in any NPA
354 ...976 |
355 # BB UAN
356 246(?:
357 292|
358 367|
359 4(?:
360 1[7-9]|
361 3[01]|
362 4[47-9]|
363 67
364 )|
365 7(?:
366 1[2-9]|
367 2\d|
368 3[016]|
369 53
370 )
371 ) |
372 # BS UAN
373 242225 |
374 # NANP-global
375 900
376 )
377 84 /x) { return 1; }
378 5 else { return 0; }
379 }
380  
381 =item is_personal
382  
383 The number is a "personal" number. The 500, 533, 544, 566 and 577 "area codes".
384  
385 =cut
386  
387 81 ▶sub is_personal {
Subroutine is_personal: called CC=2 SCAR=6.9
Pod documented
388 80 my $self = shift;
389 # FIXME this really should be data-driven, based on data in libphonenumber
390 # https://en.wikipedia.org/wiki/Personal_communications_service_(NANP)
391 # checked on 2025-12-10
392 # next check due 2026-12-01 (annually)
393 80 ▶ if(${$self} =~ /
Branch: 1 branch
BranchTrueFalseTotal
if (${$self;} =~ / ^(\+1)? ( 500 | 52[1-9] | 53[238] | 544 | 566 | 577 | 588 ) /x) { } 76 3 79
394 ^(\+1)?
395 (
396 500 | 52[1-9] | 53[238] | 544 | 566 | 577 | 588
397 )
398 77 /x) { return 1; }
399 4 else { return 0; }
400 }
401  
402 8 ▶sub areaname {
Subroutine areaname: called CC=1 SCAR=0.0
Pod documented
403 8 my $self = shift;
404 7 return Number::Phone::NANP::Data::_areaname('1'.$self->areacode().$self->subscriber());
405 }
406  
407 =item country_code
408  
409 Returns 1.
410  
411 =cut
412  
413 99 ▶sub country_code { 1; }
Subroutine country_code: called CC=1 SCAR=0.0
Pod documented
414  
415 =item regulator
416  
417 Returns informational text relevant to the whole NANP. Note that when
418 this method is inherited by a subclass it returns undef meaning "not
419 known", but returns information about the NANPA when called on an object
420 of class Number::Phone::NANP.
421  
422 =cut
423  
424 10 ▶sub regulator {
Subroutine regulator: called CC=2 SCAR=6.9
Pod documented
425 10 my $class = shift;
426 9 ▶ if(blessed($class) eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($class) eq __PACKAGE__) { } 1 7 8
427 2 return 'NANPA, http://www.nanpa.com/';
428 } else {
429 9 return undef;
430 }
431 }
432  
433 =item areacode
434  
435 Return the area code for the number.
436  
437 =item areaname
438  
439 Return the name for the area code, if applicable, otherwise returns undef.
440 For instance, for a number beginning with +1 201 200 it would return "Jersey City, NJ".
441  
442 =item subscriber
443  
444 Return the subscriber part of the number.
445  
446 =item format
447  
448 Return a sanely formatted version of the number, complete with IDD code.
449  
450 =cut
451  
452 48 ▶sub format {
Subroutine format: called CC=1 SCAR=0.0
Pod documented
453 48 my $self = shift;
454 48 return '+'.country_code().' '.
455 $self->areacode().' '.
456 substr($self->subscriber(), 0, 3).' '.
457 substr($self->subscriber(), 3);
458 }
459  
460 =back
461  
462 =head1 BUGS/FEEDBACK
463  
464 Please report bugs at L<https://github.com/DrHyde/perl-modules-Number-Phone/issues>, including, if possible, a test case.
465  
466 I welcome feedback from users.
467  
468 =head1 LICENCE
469  
470 You may use, modify and distribute this software under the same terms as
471 perl itself.
472  
473 =head1 AUTHOR
474  
475 David Cantrell E<lt>david@cantrell.org.ukE<gt>
476  
477 Copyright 2026
478  
479 =cut
480  
481 11 1;
« blib/lib/Number/Phone/StubCountry/IE.pm ↑ Summary blib/lib/Number/Phone/StubCountry/TT.pm »