UPS/Address.pm

filter: Statementstmt 69.8% 51 / 73 Branchbran 52.2% 23 / 44 Conditioncond 33.3% 14 / 42 MC/DCmcdc 14.2% 3 / 21 Subroutinesub 57.1% 8 / 14 Podpod 87.5% 7 / 8 totaltotal 52.4% 106 / 202 CC 41 SCAR 33.8
CC
41
Cov
55%
cache_id
90.0
BUILDARGS
30.3
as_hash
15.9
CRAP 29.3
« UPS/Payment.pm ↑ Summary UPS/Package.pm »
1 package Net::Async::Webservice::UPS::Address;
2 5 $Net::Async::Webservice::UPS::Address::VERSION = '1.1.4';
3 {
4 5 $Net::Async::Webservice::UPS::Address::DIST = 'Net-Async-Webservice-UPS';
5 }
6 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Types::Standard qw(Str Int Bool StrictNum);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Net::Async::Webservice::UPS::Types ':types';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Net::Async::Webservice::UPS::Response::Utils ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # ABSTRACT: an address for UPS
14  
15  
16 5 has city => (
17 is => 'ro',
18 isa => Str,
19 required => 0,
20 );
21  
22  
23 5 has postal_code => (
24 is => 'ro',
25 isa => Str,
26 required => 0,
27 );
28  
29  
30 5 has postal_code_extended => (
31 is => 'ro',
32 isa => Str,
33 required => 0,
34 );
35  
36  
37 5 has state => (
38 is => 'ro',
39 isa => Str,
40 required => 0,
41 );
42  
43  
44 5 has country_code => (
45 is => 'ro',
46 isa => Str,
47 required => 0,
48 default => 'US',
49 );
50  
51  
52 5 has name => (
53 is => 'ro',
54 isa => Str,
55 required => 0,
56 );
57  
58  
59 5 has building_name => (
60 is => 'ro',
61 isa => Str,
62 required => 0,
63 );
64  
65  
66 5 has address => (
67 is => 'ro',
68 isa => Str,
69 required => 0,
70 );
71  
72  
73 5 has address2 => (
74 is => 'ro',
75 isa => Str,
76 required => 0,
77 );
78  
79  
80 5 has address3 => (
81 is => 'ro',
82 isa => Str,
83 required => 0,
84 );
85  
86  
87 5 has is_residential => (
88 is => 'ro',
89 isa => Bool,
90 required => 0,
91 );
92  
93  
94 5 has quality => (
95 is => 'ro',
96 isa => StrictNum,
97 required => 0,
98 );
99  
100  
101 0 ▶sub is_exact_match {
Subroutine is_exact_match: not called CC=2 SCAR=17.9
Pod documented
102 0 my $self = shift;
103 0 ▶ return unless $self->quality();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quality 0 0 0
104 0 return ($self->quality == 1);
105 }
106  
107  
108 0 ▶sub is_very_close_match {
Subroutine is_very_close_match: not called CC=2 SCAR=17.9
Pod documented
109 0 my $self = shift;
110 0 ▶ return unless $self->quality();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quality 0 0 0
111 0 return ($self->quality >= 0.95);
112 }
113  
114  
115 0 ▶sub is_close_match {
Subroutine is_close_match: not called CC=2 SCAR=17.9
Pod documented
116 0 my $self = shift;
117 0 ▶ return unless $self->quality();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quality 0 0 0
118 0 return ($self->quality >= 0.90);
119 }
120  
121  
122 0 ▶sub is_possible_match {
Subroutine is_possible_match: not called CC=2 SCAR=17.9
Pod documented
123 0 my $self = shift;
124 0 ▶ return unless $self->quality();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quality 0 0 0
125 0 return ($self->quality >= 0.90);
126 }
127  
128  
129 0 ▶sub is_poor_match {
Subroutine is_poor_match: not called CC=2 SCAR=17.9
Pod documented
130 0 my $self = shift;
131 0 ▶ return unless $self->quality();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quality 0 0 0
132 0 return ($self->quality <= 0.69);
133 }
134  
135  
136 26 ▶sub as_hash {
Subroutine as_hash: called CC=12 SCAR=27.7
Pod documented
137 26 my ($self, $shape) = @_;
138 26 ▶ $shape //= 'AV';
Condition50%1/2
$shape //= "AV"
l!l
260
MC/DC0%0/1
$shape //= "AV"
$shape
Truth table50%1/2
A
A= $shape
Aresult
11
00
139  
140 26 set_implied_argument($self);
141  
142 26 ▶ if ($shape eq 'AV') {
Branch: 3 branches
BranchTrueFalseTotal
if ($shape eq 'AV') { } 14 12 26
elsif ($shape eq 'XAV') { } 3 9 12
elsif ($shape eq 'Ship') { } 9 0 9
143 return {
144 14 ▶ Address => {
Branch: 1 branch
BranchTrueFalseTotal
$self->is_residential ? : 2 12 14
Condition50%1/2
$self->country_code || 'US'
l!l
140
MC/DC0%0/1
$self->country_code || 'US'
$self->country_code
Truth table50%1/2
A
A= $self->country_code
Aresult
11
00
145 CountryCode => $self->country_code || "US",
146 PostalCode => $self->postal_code,
147 out_if(City=>'city'),
148 out_if(StateProvinceCode=>'state'),
149 ( $self->is_residential ? ( ResidentialAddressIndicator => undef ) : () ),
150 }
151 };
152 }
153 elsif ($shape eq 'XAV') {
154 return {
155 3 ▶ AddressKeyFormat => {
Branch: 3 branches
BranchTrueFalseTotal
$self->address ? : 3 0 3
$self->address2 ? : 0 3 3
$self->address3 ? : 0 3 3
Condition50%1/2
$self->country_code || 'US'
l!l
30
MC/DC0%0/1
$self->country_code || 'US'
$self->country_code
Truth table50%1/2
A
A= $self->country_code
Aresult
11
00
156 CountryCode => $self->country_code || "US",
157 PostcodePrimaryLow => $self->postal_code,
158 out_if(PostcodeExtendedLow=>'postal_code_extended'),
159 out_if(ConsigneeName=>'name'),
160 out_if(BuildingName=>'building_name'),
161 AddressLine => [
162 ( $self->address ? $self->address : () ),
163 ( $self->address2 ? $self->address2 : () ),
164 ( $self->address3 ? $self->address3 : () ),
165 ],
166 out_if(PoliticalDivision1=>'state'),
167 out_if(PoliticalDivision2=>'city'),
168 }
169 }
170 }
171 elsif ($shape eq 'Ship') {
172 return {
173 9 ▶ Address => {
Condition50%1/2
$self->country_code || 'US'
l!l
90
MC/DC0%0/1
$self->country_code || 'US'
$self->country_code
Truth table50%1/2
A
A= $self->country_code
Aresult
11
00
174 CountryCode => $self->country_code || "US",
175 PostalCode => $self->postal_code,
176 out_if(AddressLine1=>'address'),
177 out_if(AddressLine2=>'address2'),
178 out_if(AddressLine3=>'address3'),
179 out_if(City=>'city'),
180 out_if(StateProvinceCode=>'state'),
181 }
182 }
183 }
184 else {
185 0 die "bad address as_hash shape $shape";
186 }
187 }
188  
189 150 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=17 SCAR=34.1
Pod undocumented
190 150 my ($class,@etc) = @_;
191 150 my $hashref = $class->next::method(@etc);
192  
193 150 ▶ my $data = $hashref->{Address} || $hashref->{AddressKeyFormat} || $hashref->{AddressArtifactFormat};
Condition100%6/6
$hashref->{'Address'} || $hashref->{'AddressKeyFormat'} || $hashref->{'AddressArtifactFormat'}
l!l&&r!l&&!r
613014
$hashref->{"Address"} or $hashref->{"AddressKeyFormat"}
l!l&&r!l&&!r
42144
MC/DC100%3/3
$hashref->{'Address'} || $hashref->{'AddressKeyFormat'} || $hashref->{'AddressArtifactFormat'}
$hashref->{"Address"} $hashref->{"AddressKeyFormat"} $hashref->{'AddressArtifactFormat'}
Truth table100%4/4
A or B || C
A= $hashref->{"Address"}B= $hashref->{"AddressKeyFormat"}C= $hashref->{'AddressArtifactFormat'}
ABCresult
1XX1
01X1
0011
0000
194  
195 150 ▶ if (not $data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data) 14 136 150
196 14 ▶ if ($hashref->{postal_code}
Branch: 1 branch
BranchTrueFalseTotal
if ($hashref->{"postal_code"} and not defined $hashref->{"postal_code_extended"} and $hashref->{"postal_code"} =~ /\A(\d+)-(\d+)\z/) 0 14 14
Condition33%2/6
$hashref->{"postal_code"} and not defined $hashref->{"postal_code_extended"} and $hashref->{"postal_code"} =~ /\A(\d+)-(\d+)\z/
!ll&&!rl&&r
0140
$hashref->{"postal_code"} and not defined $hashref->{"postal_code_extended"}
!ll&&!rl&&r
0014
MC/DC0%0/3
$hashref->{"postal_code"} and not defined $hashref->{"postal_code_extended"} and $hashref->{"postal_code"} =~ /\A(\d+)-(\d+)\z/
$hashref->{"postal_code"} not defined $hashref->{"postal_code_extended"} $hashref->{"postal_code"} =~ /\A(\d+)-(\d+)\z/
Truth table25%1/4
A and not(B) and C
A= $hashref->{"postal_code"}B= not defined $hashref->{"postal_code_extended"}C= $hashref->{"postal_code"} =~ /\A(\d+)-(\d+)\z/
ABCresult
0XX0
10X0
1100
1111
197 and not defined $hashref->{postal_code_extended}
198 and $hashref->{postal_code} =~ m{\A(\d+)-(\d+)\z}) {
199 0 $hashref->{postal_code} = $1;
200 0 $hashref->{postal_code_extended} = $2;
201 }
202 14 my @undef_k = grep {not defined $hashref->{$_} } keys %$hashref;
203 14 delete @$hashref{@undef_k};
204 14 return $hashref;
205 }
206  
207 136 set_implied_argument($data);
208  
209 return {
210 country_code => 'US', # default,
211 pair_if(quality=>$hashref->{Quality}),
212 in_if(country_code=>'CountryCode'),
213 in_if(postal_code=>'PostalCode'),
214 in_if(postal_code=>'PostcodePrimaryLow'),
215 in_if(city=>'City'),
216 in_if(city=>'PoliticalDivision2'),
217 in_if(state=>'StateProvinceCode'),
218 in_if(state=>'PoliticalDivision1'),
219 in_if(postal_code_extended=>'PostcodeExtendedLow'),
220 in_if(name=>'ConsigneeName'),
221 in_if(building_name=>'BuildingName'),
222 in_if(address=>'AddressLine1'),
223 in_if(address2=>'AddressLine2'),
224 in_if(address3=>'AddressLine3'),
225  
226 ( exists $data->{ResidentialAddressIndicator} ? ( is_residential => 1 ) : () ),
227 ( exists $data->{AddressClassification} ? ( is_residential => $data->{AddressClassification}{Code} eq 2 ? 1 : 0 ) : () ),
228  
229 ( $data->{StreetName} || $data->{StreetNumberLow} || $data->{StreetType} ? (
230 address => join(
231 0 ' ',grep { defined }
232 0 ▶ @{$data}{qw(StreetNumberLow StreetName {StreetType)})
Branch: 4 branches
BranchTrueFalseTotal
ref $data->{'AddressLine'} eq 'ARRAY' ? : 2 134 136
$data->{'AddressLine'}[0] ? : 2 0 2
$data->{'AddressLine'}[1] ? : 0 2 2
$data->{'AddressLine'}[2] ? : 0 2 2
233 ) : () ),
234  
235 ( ref($data->{AddressLine}) eq 'ARRAY' ? (
236 ( $data->{AddressLine}[0] ? ( address => $data->{AddressLine}[0] ) : () ),
237 ( $data->{AddressLine}[1] ? ( address2 => $data->{AddressLine}[1] ) : () ),
238 136 ▶ ( $data->{AddressLine}[2] ? ( address3 => $data->{AddressLine}[2] ) : () ),
Branch: 4 branches
BranchTrueFalseTotal
exists $data->{'ResidentialAddressIndicator'} ? : 0 136 136
exists $data->{'AddressClassification'} ? : 2 134 136
$data->{'AddressClassification'}{'Code'} eq 2 ? : 0 2 2
$data->{'StreetName'} || $data->{'StreetNumberLow'} || $data->{'StreetType'} ? : 0 136 136
Condition33%2/6
$data->{"StreetName"} or $data->{"StreetNumberLow"} or $data->{"StreetType"}
l!l&&r!l&&!r
00136
$data->{"StreetName"} or $data->{"StreetNumberLow"}
l!l&&r!l&&!r
00136
MC/DC0%0/3
$data->{"StreetName"} or $data->{"StreetNumberLow"} or $data->{"StreetType"}
$data->{"StreetName"} $data->{"StreetNumberLow"} $data->{"StreetType"}
Truth table25%1/4
A or B or C
A= $data->{"StreetName"}B= $data->{"StreetNumberLow"}C= $data->{"StreetType"}
ABCresult
1XX1
01X1
0011
0000
239 ) : () ),
240 };
241 }
242  
243  
244 0 ▶sub cache_id {
Subroutine cache_id: not called CC=9 SCAR=45.0
Pod documented
245 0 my ($self) = @_;
246 0 ▶ return join ':',
Condition0%0/16
$self->name || ''
l!l
00
$self->building_name || ''
l!l
00
$self->address || ''
l!l
00
$self->address2 || ''
l!l
00
$self->address3 || ''
l!l
00
$self->state || ''
l!l
00
$self->city || ''
l!l
00
$self->postal_code_extended || ''
l!l
00
MC/DC0%0/1
$self->name || ''
$self->name
MC/DC0%0/1
$self->building_name || ''
$self->building_name
MC/DC0%0/1
$self->address || ''
$self->address
MC/DC0%0/1
$self->address2 || ''
$self->address2
MC/DC0%0/1
$self->address3 || ''
$self->address3
MC/DC0%0/1
$self->state || ''
$self->state
MC/DC0%0/1
$self->city || ''
$self->city
MC/DC0%0/1
$self->postal_code_extended || ''
$self->postal_code_extended
Truth table0%0/2
A
A= $self->name
Aresult
11
00
Truth table0%0/2
A
A= $self->building_name
Aresult
11
00
Truth table0%0/2
A
A= $self->address
Aresult
11
00
Truth table0%0/2
A
A= $self->address2
Aresult
11
00
Truth table0%0/2
A
A= $self->address3
Aresult
11
00
Truth table0%0/2
A
A= $self->state
Aresult
11
00
Truth table0%0/2
A
A= $self->city
Aresult
11
00
Truth table0%0/2
A
A= $self->postal_code_extended
Aresult
11
00
247 $self->name||'',
248 $self->building_name||'',
249 $self->address||'',
250 $self->address2||'',
251 $self->address3||'',
252 $self->country_code,
253 $self->state||'',
254 $self->city||'',
255 $self->postal_code,
256 $self->postal_code_extended||'',
257 }
258  
259 5 1;
260  
261 __END__
« UPS/Payment.pm ↑ Summary UPS/Package.pm »