line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Easypost::Address; |
2
|
|
|
|
|
|
|
$Net::Easypost::Address::VERSION = '0.21'; |
3
|
6
|
|
|
6
|
|
35
|
use Carp qw/croak/; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
269
|
|
4
|
6
|
|
|
6
|
|
1582
|
use JSON::MaybeXS; |
|
6
|
|
|
|
|
36464
|
|
|
6
|
|
|
|
|
332
|
|
5
|
6
|
|
|
6
|
|
44
|
use Scalar::Util; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
499
|
|
6
|
|
|
|
|
|
|
use overload |
7
|
5
|
|
|
5
|
|
2581
|
'""' => sub { $_[0]->as_string }, |
8
|
4
|
|
|
4
|
|
3121
|
'0+' => sub { Scalar::Util::refaddr($_[0]) }, |
9
|
6
|
|
|
6
|
|
32
|
fallback => 1; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
44
|
|
10
|
6
|
|
|
6
|
|
2565
|
use Types::Standard qw(Bool Enum HashRef InstanceOf Str Undef); |
|
6
|
|
|
|
|
359170
|
|
|
6
|
|
|
|
|
68
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
|
9914
|
use Moo; |
|
6
|
|
|
|
|
49151
|
|
|
6
|
|
|
|
|
32
|
|
14
|
|
|
|
|
|
|
with qw/Net::Easypost::PostOnBuild/; |
15
|
|
|
|
|
|
|
with qw/Net::Easypost::Resource/; |
16
|
6
|
|
|
6
|
|
8137
|
use namespace::autoclean; |
|
6
|
|
|
|
|
58153
|
|
|
6
|
|
|
|
|
27
|
|
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
|
|
95677
|
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
|
|
5924
|
sub _build_role { 'address' } |
74
|
31
|
|
|
31
|
|
2763
|
sub _build_operation { '/addresses' } |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub clone { |
77
|
3
|
|
|
3
|
1
|
3616
|
my ($self) = @_; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return Net::Easypost::Address->new( |
80
|
20
|
|
|
|
|
489
|
map { $_ => $self->$_ } |
81
|
3
|
|
|
|
|
9
|
grep { defined $self->$_ } @{ $self->fieldnames } |
|
42
|
|
|
|
|
1247
|
|
|
3
|
|
|
|
|
18
|
|
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub serialize { |
86
|
31
|
|
|
31
|
0
|
109
|
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
|
|
|
|
|
4595
|
(map { $self->role . "[$_]" => $self->$_ } |
93
|
31
|
|
|
|
|
83
|
grep { defined $self->$_ } @{ $self->fieldnames }) |
|
434
|
|
|
|
|
11673
|
|
|
31
|
|
|
|
|
143
|
|
94
|
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub as_string { |
98
|
5
|
|
|
5
|
1
|
15
|
my ($self) = @_; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return join "\n", |
101
|
13
|
|
|
|
|
303
|
(map { $self->$_ } |
102
|
20
|
|
|
|
|
712
|
grep { defined $self->$_ } qw(name phone street1 street2)), |
103
|
|
|
|
|
|
|
join " ", |
104
|
13
|
|
|
|
|
329
|
(map { $self->$_ } |
105
|
5
|
|
|
|
|
18
|
grep { defined $self->$_ } qw(city state zip)); |
|
15
|
|
|
|
|
429
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub merge { |
109
|
9
|
|
|
9
|
1
|
62
|
my ($self, $old, $fields) = @_; |
110
|
|
|
|
|
|
|
|
111
|
11
|
|
|
|
|
353
|
map { $self->$_($old->$_) } |
112
|
9
|
|
|
|
|
34
|
grep { defined $old->$_ } |
|
19
|
|
|
|
|
823
|
|
113
|
|
|
|
|
|
|
@$fields; |
114
|
|
|
|
|
|
|
|
115
|
9
|
|
|
|
|
742
|
return $self; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub verify { |
119
|
9
|
|
|
9
|
1
|
435
|
my ($self) = @_; |
120
|
|
|
|
|
|
|
|
121
|
9
|
|
|
|
|
142
|
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
|
|
|
|
124
|
if $verify_response->{error}; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $new_address = Net::Easypost::Address->new( |
131
|
|
|
|
|
|
|
$verify_response->{address} |
132
|
8
|
|
|
|
|
562
|
); |
133
|
|
|
|
|
|
|
|
134
|
8
|
|
|
|
|
258
|
return $new_address->merge($self, [qw(phone name)]); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
__END__ |