blib/lib/WWW/LogicBoxes/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/LogicBoxes/Role/Command/Domain/Registration.pm ↑ Summary blib/lib/WWW/LogicBoxes/DomainAvailability.pm »
1 package WWW::LogicBoxes::PhoneNumber;
2  
3 47 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 47 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 47 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 47 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 47 ▶use overload '""' => \&_to_string, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 47 ▶use WWW::LogicBoxes::Types qw( Str NumberPhone );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 47 ▶use Number::Phone;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 47 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 47 our $VERSION = '1.1.0'; # VERSION
17 # ABSTRACT: Extendes Number::Phone to add 'number' functionatly (without country code)
18  
19 47 has '_number_phone_obj' => (
20 is => 'ro',
21 isa => NumberPhone,
22 required => 1,
23 );
24  
25 47 has 'country_code' => (
26 is => 'ro',
27 isa => Str,
28 builder => '_build_country_code',
29 lazy => 1,
30 );
31  
32 47 has 'number' => (
33 is => 'ro',
34 isa => Str,
35 builder => '_build_number',
36 lazy => 1,
37 );
38  
39 around BUILDARGS => sub {
40 3 ▶ my $orig = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
41 3 my $class = shift;
42  
43 3 my $args;
44 3 ▶ if( scalar @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) { } 1 2 3
45 1 return $class->$orig( @_ );
46 }
47 else {
48 2 $args = shift;
49 }
50  
51 2 ▶ if( ref $args eq '' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $args eq '') { } 1 1 2
elsif (ref($args) =~ /Number::Phone/) { } 1 0 1
52 1 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 47 };
61  
62 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
63 sub _build_country_code {
64 3 ▶ my $self = shift;
Subroutine _build_country_code: called CC=1 SCAR=0.0
65  
66 3 return $self->_number_phone_obj->country_code;
67 }
68 ## use critic
69  
70 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
71 sub _build_number {
72 3 ▶ my $self = shift;
Subroutine _build_number: called CC=1 SCAR=0.0
73  
74 3 my $full_number = $self->_number_phone_obj->format;
75 3 $full_number =~ s/[^\d]*//g;
76  
77 3 return substr( $full_number, length( $self->country_code ) );
78 }
79 ## use critic
80  
81 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
82 sub _to_string {
83 3 ▶ my $self = shift;
Subroutine _to_string: called CC=1 SCAR=0.0
84  
85 3 return $self->country_code . $self->number;
86 }
87 ## use critic
88  
89 47 __PACKAGE__->meta->make_immutable;
90  
91 47 1;
92  
93 __END__
94 =pod
95  
96 =head1 NAME
97  
98 WWW::LogicBoxes::PhoneNumber - PhoneNumber object with LogicBoxes Compatable Formatting
99  
100 =head1 SYNOPSIS
101  
102 use WWW::LogicBoxes::PhoneNumber;
103  
104 my $phone_number = WWW::LogicBoxes::PhoneNumber->new( '+18005551212' );
105  
106  
107 use Number::Phone;
108 use WWW::LogicBoxes::PhoneNumber;
109  
110 my $number_phone = Number::Phone->new( '+18005551212' );
111 my $phone_number = WWW::LogicBoxes::PhoneNumber->new( $number_phone );
112  
113 print "My Phone Number is $phone_number \n";
114  
115 =head1 DESCRIPTION
116  
117 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.
118  
119 L<LogicBoxes|http://www.logicboxes.com> 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::LogicBoxes::PhoneNumber. When used as a string the full phone number is returned.
120  
121 =head1 ATTRIBUTES
122  
123 =head2 B<_number_phone_obj>
124  
125 This private attribute contains an instance of L<Number::Phone>. While you certainly can set it in the call to new, it's not nessicary as an around BUILDARGS will take the values passed to new and ensure this attribute is set.
126  
127 There really is no reason to do anything with this attribute.
128  
129 =head2 country_code
130  
131 Lazy built country code assoicated with the phone number.
132  
133 =head2 number
134  
135 Lazy built party number (the phone number without the country code) assoicated with the phone number.
136  
137 =cut
« blib/lib/WWW/LogicBoxes/Role/Command/Domain/Registration.pm ↑ Summary blib/lib/WWW/LogicBoxes/DomainAvailability.pm »