MWS/XML/Address.pm

filter: Statementstmt 73.6% 42 / 57 Branchbran 66.6% 12 / 18 Conditioncond 66.6% 10 / 15 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 64.2% 9 / 14 Podpod 100% 10 / 10 totaltotal 72.5% 87 / 120 CC 16 SCAR 19.1
CC
16
Cov
71%
phone
20.0
address_line
12.0
_unroll_ref
7.0
CRAP 6.7
« MWS/XML/GenericFeed.pm ↑ Summary MWS/XML/Order.pm »
1 package Amazon::MWS::XML::Address;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Amazon::MWS::XML::Address
11  
12 =head1 DESCRIPTION
13  
14 Class to handle the addresses in the Amazon MWS's XML responses. It
15 provides some aliases to get a consistent interface.
16  
17 =head1 ACCESSORS
18  
19 =over 4
20  
21 =item Name
22  
23 Name of customer for this address.
24  
25 =item AddressLine1
26  
27 =item AddressFieldOne
28  
29 =item address1
30  
31 This is a field where Amazon stores the company name, or the c/o, or
32 postal boxes, etc. It appears as the first line of the address, but
33 you can't be sure what exactly it is (save you don't want to lose it).
34  
35 Sometimes the street address is here, sometimes is empty.
36  
37 =item AddressLine2
38  
39 =item AddressFieldTwo
40  
41 =item address2
42  
43 This appears to be the regular street/number address line, sometimes.
44 Sometimes is in the address1. You just can't know, so you have to use
45 some euristics, like checking if they are both set, otherwise choosing
46 the first available to use as street address.
47  
48 =item PostalCode
49  
50 Postal code for this address.
51  
52 =item City
53  
54 City for this address.
55  
56 =item Phone
57  
58 =item PhoneNumber
59  
60 Phone number for this address.
61  
62 =item CountryCode
63  
64 =item StateOrRegion
65  
66 =back
67  
68 =cut
69  
70  
71 7 has Phone => (is => 'ro');
72 7 has PhoneNumber => (is => 'ro');
73 7 has PostalCode => (is => 'ro');
74 7 has AddressLine1 => (is => 'ro');
75 7 has AddressFieldOne => (is => 'ro');
76 7 has AddressLine2 => (is => 'ro');
77 7 has AddressFieldTwo => (is => 'ro');
78 7 has StateOrRegion => (is => 'ro');
79 7 has City => (is => 'ro');
80 7 has Name => (is => 'ro');
81 7 has CountryCode => (is => 'ro');
82  
83 8 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
84 8 return shift->Name;
85 }
86  
87 10 ▶sub address1 {
Subroutine address1: called CC=3 SCAR=11.0
Pod documented
88 10 my $self = shift;
89 10 ▶ return $self->_unroll_ref($self->AddressLine1) || $self->_unroll_ref($self->AddressFieldOne) || '';
Condition100%5/5
$self->_unroll_ref($self->AddressLine1) || $self->_unroll_ref($self->AddressFieldOne) || ''
l!l
28
$self->_unroll_ref($self->AddressLine1) or $self->_unroll_ref($self->AddressFieldOne)
l!l&&r!l&&!r
118
MC/DC100%2/2
$self->_unroll_ref($self->AddressLine1) || $self->_unroll_ref($self->AddressFieldOne) || ''
$self->_unroll_ref($self->AddressLine1) $self->_unroll_ref($self->AddressFieldOne)
Truth table100%3/3
A or B
A= $self->_unroll_ref($self->AddressLine1)B= $self->_unroll_ref($self->AddressFieldOne)
ABresult
1X1
011
000
90 }
91  
92 10 ▶sub address2 {
Subroutine address2: called CC=3 SCAR=11.0
Pod documented
93 10 my $self = shift;
94 10 ▶ return $self->_unroll_ref($self->AddressLine2) || $self->_unroll_ref($self->AddressFieldTwo) || '';
Condition100%5/5
$self->_unroll_ref($self->AddressLine2) || $self->_unroll_ref($self->AddressFieldTwo) || ''
l!l
37
$self->_unroll_ref($self->AddressLine2) or $self->_unroll_ref($self->AddressFieldTwo)
l!l&&r!l&&!r
217
MC/DC100%2/2
$self->_unroll_ref($self->AddressLine2) || $self->_unroll_ref($self->AddressFieldTwo) || ''
$self->_unroll_ref($self->AddressLine2) $self->_unroll_ref($self->AddressFieldTwo)
Truth table100%3/3
A or B
A= $self->_unroll_ref($self->AddressLine2)B= $self->_unroll_ref($self->AddressFieldTwo)
ABresult
1X1
011
000
95 }
96  
97 37 ▶sub _unroll_ref {
Subroutine _unroll_ref: called CC=7 SCAR=19.5
98 37 my ($self, $value) = @_;
99 37 ▶ return '' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 26 11 37
100 11 ▶ if (my $reftype = ref($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $reftype = ref $value) { } 10 1 11
101 10 ▶ if ($reftype eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if ($reftype eq 'HASH') { } 5 5 10
elsif ($reftype eq 'ARRAY') { } 4 1 5
102 # this is probably incorrect, but given that we don't
103 # expect this, it's better than nothing.
104 5 ▶ if (%$value) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$value) { } 2 3 5
105 # here we don't know exactly what to do.
106 2 my @list = %$value;
107 2 return join(' ', @list);
108 }
109 else {
110 3 return '';
111 }
112 }
113 elsif ($reftype eq 'ARRAY') {
114 4 ▶ if (@$value) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$value) { } 2 2 4
115 2 return join(' ', @$value);
116 }
117 else {
118 2 return '';
119 }
120 }
121 else {
122 1 warn "Unknown ref passed $reftype";
123 1 return '';
124 }
125 }
126 else {
127 1 return $value;
128 }
129 }
130  
131 =head2 ALIASES
132  
133 =over 4
134  
135 =item name (Name)
136  
137 =item address_line
138  
139 Concatenation of address1 and address2.
140  
141 =item city (City)
142  
143 =item zip (PostalCode)
144  
145 =item country (CountryCode)
146  
147 =item phone (Phone or PhoneNumber)
148  
149 =item region (StateOrRegion)
150  
151 =item state (StateOrRegion)
152  
153 =back
154  
155 =cut
156  
157 0 ▶sub address_line {
Subroutine address_line: not called CC=3 SCAR=24.8
Pod documented
158 0 my $self = shift;
159 0 my $line = $self->address1;
160 0 ▶ if (my $second = $self->address2) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $second = $self->address2) 0 0 0
161 0 ▶ if ($second ne $line) {
Branch: 1 branch
BranchTrueFalseTotal
if ($second ne $line) 0 0 0
162 0 $line .= "\n" . $second;
163 }
164 }
165 0 return $line;
166 }
167  
168 0 ▶sub city {
Subroutine city: not called CC=1 SCAR=6.9
Pod documented
169 0 return shift->City;
170 }
171  
172 0 ▶sub zip {
Subroutine zip: not called CC=1 SCAR=6.9
Pod documented
173 0 return shift->PostalCode;
174 }
175  
176 0 ▶sub country {
Subroutine country: not called CC=1 SCAR=6.9
Pod documented
177 0 return shift->CountryCode;
178 }
179  
180 0 ▶sub phone {
Subroutine phone: not called CC=4 SCAR=30.0
Pod documented
181 0 my $self = shift;
182 0 ▶ my $phone = $self->Phone || $self->PhoneNumber || '';
Condition0%0/5
$self->Phone || $self->PhoneNumber || ''
l!l
00
$self->Phone or $self->PhoneNumber
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->Phone || $self->PhoneNumber || ''
$self->Phone $self->PhoneNumber
Truth table0%0/3
A or B
A= $self->PhoneB= $self->PhoneNumber
ABresult
1X1
011
000
183 0 ▶ if (ref($phone) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $phone eq 'ARRAY') { } 0 0 0
184 0 return join(' ', map { $_->{_} } @$phone);
185 }
186 else {
187 0 return $phone;
188 }
189 }
190  
191 1 ▶sub region {
Subroutine region: called CC=1 SCAR=0.0
Pod documented
192 1 return shift->StateOrRegion;
193 }
194  
195 1 ▶sub state {
Subroutine state: called CC=1 SCAR=0.0
Pod documented
196 1 return shift->StateOrRegion;
197 }
198  
199 7 1;
« MWS/XML/GenericFeed.pm ↑ Summary MWS/XML/Order.pm »