| 1 | package Net::Easypost::Address; | ||||||||||
| 2 | 6 | $Net::Easypost::Address::VERSION = '0.23'; | |||||||||
| 3 | 6 | ▶ | use Carp qw/croak/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 6 | ▶ | use JSON::MaybeXS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 6 | ▶ | use Scalar::Util; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | use overload | ||||||||||
| 7 | 5 | ▶ | '""' => sub { $_[0]->as_string }, | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 4 | ▶ | '0+' => sub { Scalar::Util::refaddr($_[0]) }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 6 | fallback => 1; | |||||||||
| 10 | 6 | ▶ | use Types::Standard qw(Bool Enum HashRef InstanceOf Str Undef); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | 6 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 6 | with qw/Net::Easypost::PostOnBuild/; | |||||||||
| 15 | 6 | with qw/Net::Easypost::Resource/; | |||||||||
| 16 | 6 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 6 | has [qw/street1 | |||||||||
| 19 | street2 | ||||||||||
| 20 | city | ||||||||||
| 21 | state | ||||||||||
| 22 | zip | ||||||||||
| 23 | country | ||||||||||
| 24 | carrier_facility | ||||||||||
| 25 | name | ||||||||||
| 26 | company | ||||||||||
| 27 | phone | ||||||||||
| 28 | |||||||||||
| 29 | federal_tax_id | ||||||||||
| 30 | state_tax_id/ | ||||||||||
| 31 | ] => ( | ||||||||||
| 32 | is => 'rw', | ||||||||||
| 33 | isa => Str|Undef | ||||||||||
| 34 | ); | ||||||||||
| 35 | |||||||||||
| 36 | has 'residential' => ( | ||||||||||
| 37 | is => 'rw', | ||||||||||
| 38 | isa => Bool|InstanceOf['JSON::PP::Boolean'], | ||||||||||
| 39 | 10 | ▶ | coerce => sub { $_[0] ? JSON->true : JSON->false } | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 40 | 6 | ); | |||||||||
| 41 | |||||||||||
| 42 | 6 | has 'verifications' => ( | |||||||||
| 43 | is => 'rw', | ||||||||||
| 44 | isa => HashRef | ||||||||||
| 45 | ); | ||||||||||
| 46 | |||||||||||
| 47 | 6 | has 'verify_adress' => ( | |||||||||
| 48 | is => 'rw', | ||||||||||
| 49 | isa => Enum[qw/zip4 delivery/] | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | 31 | ▶ | sub _build_fieldnames { | ||||||||
|
Subroutine
_build_fieldnames: called CC=1 SCAR=0.0
| |||||||||||
| 53 | return [ | ||||||||||
| 54 | 31 | qw/ | |||||||||
| 55 | street1 | ||||||||||
| 56 | street2 | ||||||||||
| 57 | city | ||||||||||
| 58 | state | ||||||||||
| 59 | zip | ||||||||||
| 60 | country | ||||||||||
| 61 | residential | ||||||||||
| 62 | carrier_facility | ||||||||||
| 63 | name | ||||||||||
| 64 | company | ||||||||||
| 65 | phone | ||||||||||
| 66 | |||||||||||
| 67 | federal_tax_id | ||||||||||
| 68 | state_tax_id | ||||||||||
| 69 | / | ||||||||||
| 70 | ]; | ||||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 31 | ▶ | sub _build_role { 'address' } | ||||||||
|
Subroutine
_build_role: called CC=1 SCAR=0.0
| |||||||||||
| 74 | 31 | ▶ | sub _build_operation { '/addresses' } | ||||||||
|
Subroutine
_build_operation: called CC=1 SCAR=0.0
| |||||||||||
| 75 | |||||||||||
| 76 | 3 | ▶ | sub clone { | ||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 77 | 3 | my ($self) = @_; | |||||||||
| 78 | |||||||||||
| 79 | return Net::Easypost::Address->new( | ||||||||||
| 80 | 20 | map { $_ => $self->$_ } | |||||||||
| 81 | 3 | grep { defined $self->$_ } @{ $self->fieldnames } | |||||||||
| 82 | ); | ||||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 31 | ▶ | sub serialize { | ||||||||
|
Subroutine
serialize: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 86 | 31 | my ($self) = @_; | |||||||||
| 87 | |||||||||||
| 88 | # want a hashref of e.g., address[name] => foo from all defined attributes | ||||||||||
| 89 | # verify[]=zip4|delivery - verify an address | ||||||||||
| 90 | return { | ||||||||||
| 91 | # (defined $self->verify_address ? "verify[]" => $self->verify : ()), | ||||||||||
| 92 | 178 | (map { $self->role . "[$_]" => $self->$_ } | |||||||||
| 93 | 31 | grep { defined $self->$_ } @{ $self->fieldnames }) | |||||||||
| 94 | }; | ||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 5 | ▶ | sub as_string { | ||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 98 | 5 | my ($self) = @_; | |||||||||
| 99 | |||||||||||
| 100 | return join "\n", | ||||||||||
| 101 | 13 | (map { $self->$_ } | |||||||||
| 102 | 20 | grep { defined $self->$_ } qw(name phone street1 street2)), | |||||||||
| 103 | join " ", | ||||||||||
| 104 | 13 | (map { $self->$_ } | |||||||||
| 105 | 5 | grep { defined $self->$_ } qw(city state zip)); | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 9 | ▶ | sub merge { | ||||||||
|
Subroutine
merge: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 109 | 9 | my ($self, $old, $fields) = @_; | |||||||||
| 110 | |||||||||||
| 111 | 11 | map { $self->$_($old->$_) } | |||||||||
| 112 | 9 | grep { defined $old->$_ } | |||||||||
| 113 | @$fields; | ||||||||||
| 114 | |||||||||||
| 115 | 9 | return $self; | |||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | 9 | ▶ | sub verify { | ||||||||
|
Subroutine
verify: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 119 | 9 | my ($self) = @_; | |||||||||
| 120 | |||||||||||
| 121 | 9 | my $verify_response = | |||||||||
| 122 | $self->requester->get( | ||||||||||
| 123 | join '/', $self->operation, $self->id, 'verify' | ||||||||||
| 124 | ); | ||||||||||
| 125 | |||||||||||
| 126 | croak 'Unable to verify address, failed with message: ' | ||||||||||
| 127 | . $verify_response->{error} | ||||||||||
| 128 | 9 | ▶ | if $verify_response->{error}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | |||||||||||
| 130 | my $new_address = Net::Easypost::Address->new( | ||||||||||
| 131 | $verify_response->{address} | ||||||||||
| 132 | 8 | ); | |||||||||
| 133 | |||||||||||
| 134 | 8 | return $new_address->merge($self, [qw(phone name)]); | |||||||||
| 135 | } | ||||||||||
| 136 | |||||||||||
| 137 | 6 | 1; | |||||||||
| 138 | |||||||||||
| 139 | __END__ | ||||||||||