line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Easypost::Address; |
2
|
|
|
|
|
|
|
$Net::Easypost::Address::VERSION = '0.23'; |
3
|
6
|
|
|
6
|
|
34
|
use Carp qw/croak/; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
237
|
|
4
|
6
|
|
|
6
|
|
2110
|
use JSON::MaybeXS; |
|
6
|
|
|
|
|
37799
|
|
|
6
|
|
|
|
|
302
|
|
5
|
6
|
|
|
6
|
|
35
|
use Scalar::Util; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
460
|
|
6
|
|
|
|
|
|
|
use overload |
7
|
5
|
|
|
5
|
|
2190
|
'""' => sub { $_[0]->as_string }, |
8
|
4
|
|
|
4
|
|
2976
|
'0+' => sub { Scalar::Util::refaddr($_[0]) }, |
9
|
6
|
|
|
6
|
|
32
|
fallback => 1; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
39
|
|
10
|
6
|
|
|
6
|
|
3245
|
use Types::Standard qw(Bool Enum HashRef InstanceOf Str Undef); |
|
6
|
|
|
|
|
358469
|
|
|
6
|
|
|
|
|
48
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
|
9084
|
use Moo; |
|
6
|
|
|
|
|
54048
|
|
|
6
|
|
|
|
|
24
|
|
14
|
|
|
|
|
|
|
with qw/Net::Easypost::PostOnBuild/; |
15
|
|
|
|
|
|
|
with qw/Net::Easypost::Resource/; |
16
|
6
|
|
|
6
|
|
9302
|
use namespace::autoclean; |
|
6
|
|
|
|
|
63699
|
|
|
6
|
|
|
|
|
18
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has [qw/street1 |
19
|
|
|
|
|
|
|
street2 |
20
|
|
|
|
|
|
|
city |
21
|
|
|
|
|
|
|
state |
22
|
|
|
|
|
|
|
zip |
23
|
|
|
|
|
|
|
country |
24
|
|
|
|
|
|
|
carrier_facility |
25
|
|
|
|
|
|
|
name |
26
|
|
|
|
|
|
|
company |
27
|
|
|
|
|
|
|
phone |
28
|
|
|
|
|
|
|
email |
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
|
|
|
|
|
|
|
coerce => sub { $_[0] ? JSON->true : JSON->false } |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has 'verifications' => ( |
43
|
|
|
|
|
|
|
is => 'rw', |
44
|
|
|
|
|
|
|
isa => HashRef |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has 'verify_adress' => ( |
48
|
|
|
|
|
|
|
is => 'rw', |
49
|
|
|
|
|
|
|
isa => Enum[qw/zip4 delivery/] |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _build_fieldnames { |
53
|
|
|
|
|
|
|
return [ |
54
|
31
|
|
|
31
|
|
93351
|
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
|
|
|
|
|
|
|
email |
67
|
|
|
|
|
|
|
federal_tax_id |
68
|
|
|
|
|
|
|
state_tax_id |
69
|
|
|
|
|
|
|
/ |
70
|
|
|
|
|
|
|
]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
31
|
|
|
31
|
|
4036
|
sub _build_role { 'address' } |
74
|
31
|
|
|
31
|
|
1280
|
sub _build_operation { '/addresses' } |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub clone { |
77
|
3
|
|
|
3
|
1
|
3853
|
my ($self) = @_; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return Net::Easypost::Address->new( |
80
|
20
|
|
|
|
|
366
|
map { $_ => $self->$_ } |
81
|
3
|
|
|
|
|
9
|
grep { defined $self->$_ } @{ $self->fieldnames } |
|
42
|
|
|
|
|
982
|
|
|
3
|
|
|
|
|
20
|
|
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub serialize { |
86
|
31
|
|
|
31
|
0
|
110
|
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
|
|
|
|
|
3314
|
(map { $self->role . "[$_]" => $self->$_ } |
93
|
31
|
|
|
|
|
75
|
grep { defined $self->$_ } @{ $self->fieldnames }) |
|
434
|
|
|
|
|
8440
|
|
|
31
|
|
|
|
|
135
|
|
94
|
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub as_string { |
98
|
5
|
|
|
5
|
1
|
13
|
my ($self) = @_; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return join "\n", |
101
|
13
|
|
|
|
|
217
|
(map { $self->$_ } |
102
|
20
|
|
|
|
|
516
|
grep { defined $self->$_ } qw(name phone street1 street2)), |
103
|
|
|
|
|
|
|
join " ", |
104
|
13
|
|
|
|
|
223
|
(map { $self->$_ } |
105
|
5
|
|
|
|
|
13
|
grep { defined $self->$_ } qw(city state zip)); |
|
15
|
|
|
|
|
279
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub merge { |
109
|
9
|
|
|
9
|
1
|
51
|
my ($self, $old, $fields) = @_; |
110
|
|
|
|
|
|
|
|
111
|
11
|
|
|
|
|
284
|
map { $self->$_($old->$_) } |
112
|
9
|
|
|
|
|
27
|
grep { defined $old->$_ } |
|
19
|
|
|
|
|
443
|
|
113
|
|
|
|
|
|
|
@$fields; |
114
|
|
|
|
|
|
|
|
115
|
9
|
|
|
|
|
620
|
return $self; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub verify { |
119
|
9
|
|
|
9
|
1
|
261
|
my ($self) = @_; |
120
|
|
|
|
|
|
|
|
121
|
9
|
|
|
|
|
129
|
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
|
100
|
|
|
|
89
|
if $verify_response->{error}; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $new_address = Net::Easypost::Address->new( |
131
|
|
|
|
|
|
|
$verify_response->{address} |
132
|
8
|
|
|
|
|
381
|
); |
133
|
|
|
|
|
|
|
|
134
|
8
|
|
|
|
|
212
|
return $new_address->merge($self, [qw(phone name)]); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
__END__ |