| 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.7.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 | 53 | ▶ | around BUILDARGS => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||
| 40 | 53 | my $orig = shift; | |||||||||||||
| 41 | 53 | my $class = shift; | |||||||||||||
| 42 | |||||||||||||||
| 43 | 53 | my $args; | |||||||||||||
| 44 | 53 | ▶ | if( scalar @_ > 1 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | 1 | return $class->$orig( @_ ); | |||||||||||||
| 46 | } | ||||||||||||||
| 47 | else { | ||||||||||||||
| 48 | 52 | $args = shift; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 52 | ▶ | if( ref $args eq '' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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 | 3 | ▶ | sub _build_country_code { | ||||||||||||
|
Subroutine
_build_country_code: called CC=1 SCAR=0.0
| |||||||||||||||
| 63 | 3 | my $self = shift; | |||||||||||||
| 64 | |||||||||||||||
| 65 | 3 | return $self->_number_phone_obj->country_code; | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | |||||||||||||||
| 68 | 3 | ▶ | sub _build_number { | ||||||||||||
|
Subroutine
_build_number: called CC=1 SCAR=0.0
| |||||||||||||||
| 69 | 3 | my $self = shift; | |||||||||||||
| 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 | 3 | ▶ | sub _to_string { | ||||||||||||
|
Subroutine
_to_string: called CC=1 SCAR=0.0
| |||||||||||||||
| 78 | 3 | my $self = shift; | |||||||||||||
| 79 | |||||||||||||||
| 80 | 3 | return $self->country_code . $self->number; | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | 57 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 84 | |||||||||||||||
| 85 | 57 | 1; | |||||||||||||
| 86 | |||||||||||||||
| 87 | __END__ | ||||||||||||||