blib/lib/WWW/eNom/PhoneNumber.pm

filter: Statementstmt 97.9% 48 / 49 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 97.0% 65 / 67 CC 4 SCAR 5.9
CC
4
Cov
96%
__ANON__
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.8
« blib/lib/WWW/eNom.pm ↑ Summary blib/lib/WWW/eNom/Types.pm »
1 package WWW::eNom::PhoneNumber;
2  
3 57 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 57 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 57 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 57 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 57 ▶use overload '""' => \&_to_string, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 57 ▶use WWW::eNom::Types qw( Str NumberPhone );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 57 ▶use Number::Phone;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 57 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 57 our $VERSION = 'v2.6.0'; # VERSION
17 # ABSTRACT: Extendes Number::Phone to add 'number' functionatly (without country code)
18  
19 57 has '_number_phone_obj' => (
20 is => 'ro',
21 isa => NumberPhone,
22 required => 1,
23 );
24  
25 57 has 'country_code' => (
26 is => 'ro',
27 isa => Str,
28 builder => '_build_country_code',
29 lazy => 1,
30 );
31  
32 57 has 'number' => (
33 is => 'ro',
34 isa => Str,
35 builder => '_build_number',
36 lazy => 1,
37 );
38  
39 around BUILDARGS => sub {
40 53 ▶ my $orig = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
41 53 my $class = shift;
42  
43 53 my $args;
44 53 ▶ if( scalar @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) { } 1 52 53
45 1 return $class->$orig( @_ );
46 }
47 else {
48 52 $args = shift;
49 }
50  
51 52 ▶ if( ref $args eq '' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $args eq '') { } 51 1 52
elsif (ref($args) =~ /Number::Phone/) { } 1 0 1
52 51 return $class->$orig( _number_phone_obj => Number::Phone->new( $args ) );
53 }
54 elsif( ( ref $args ) =~ m/Number::Phone/ ) {
55 1 return $class->$orig( _number_phone_obj => $args );
56 }
57 else {
58 0 croak "Invalid params passed to $class";
59 }
60 57 };
61  
62 sub _build_country_code {
63 3 ▶ my $self = shift;
Subroutine _build_country_code: called CC=1 SCAR=0.0
64  
65 3 return $self->_number_phone_obj->country_code;
66 }
67  
68 sub _build_number {
69 3 ▶ my $self = shift;
Subroutine _build_number: called CC=1 SCAR=0.0
70  
71 3 my $full_number = $self->_number_phone_obj->format;
72 3 $full_number =~ s/[^\d]*//g;
73  
74 3 return substr( $full_number, length( $self->country_code ) );
75 }
76  
77 sub _to_string {
78 3 ▶ my $self = shift;
Subroutine _to_string: called CC=1 SCAR=0.0
79  
80 3 return $self->country_code . $self->number;
81 }
82  
83 57 __PACKAGE__->meta->make_immutable;
84  
85 57 1;
86  
87 __END__
88 =pod
89  
90 =head1 NAME
91  
92 WWW::eNom::PhoneNumber - PhoneNumber object with eNom Compatable Formatting
93  
94 =head1 SYNOPSIS
95  
96 use WWW::eNom::PhoneNumber;
97  
98 my $phone_number = WWW::eNom::PhoneNumber->new( '+18005551212' );
99  
100  
101 use Number::Phone;
102 use WWW::eNom::PhoneNumber;
103  
104 my $number_phone = Number::Phone->new( '+18005551212' );
105 my $phone_number = WWW::eNom::PhoneNumber->new( $number_phone );
106  
107 print "My Phone Number is $phone_number \n";
108  
109 =head1 DESCRIPTION
110  
111 While L<Number::Phone> is an excellent library, there is a bit of inconsistency when it comes to international phone numbers and how to get the full number back out from the L<Number::Phone> object. The purpose of this object is to abstract away those difficulties and provide a uniform way to work with phone numbers.
112  
113 L<eNom|http://www.enom.com/APICommandCatalog/> is rather picky when it comes to phone numbers and this library exists to address that. While you certainly can use this object as a consumer it should be noted that coercions and overloads exist so that it's not needed. Anywhere that excepts a PhoneNumber will take a string or Number::Phone object and automagically convert it into a WWW::eNom::PhoneNumber. When used as a string the full phone number is returned.
114  
115 =head1 ATTRIBUTES
116  
117 =head2 B<_number_phone_obj>
118  
119 This private attribute contains an instance of L<Number::Phone>. While you certainly can set it in the call to new, it's not necessary as an around BUILDARGS will take the values passed to new and ensure this attribute is set.
120  
121 There really is no reason to do anything with this attribute.
122  
123 =head2 country_code
124  
125 Lazy built country code assoicated with the phone number.
126  
127 =head2 number
128  
129 Lazy built party number (the phone number without the country code) assoicated with the phone number.
130  
131 =cut
« blib/lib/WWW/eNom.pm ↑ Summary blib/lib/WWW/eNom/Types.pm »