UPS/Address.pm

filter: Statementstmt 57.4% 54 / 94 Branchbran 47.8% 22 / 46 Conditioncond 50.0% 8 / 16 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 40.0% 6 / 15 Podpod 60.0% 6 / 10 totaltotal 51.0% 97 / 190 CC 31 SCAR 32.3
CC
31
Cov
54%
as_hash
43.3
is_match
6.0
is_very_close_match
6.0
CRAP 25.2
« UPS.pm ↑ Summary UPS/Package.pm »
1 package Net::UPS::Address;
2 5 $Net::UPS::Address::VERSION = '0.16';
3 {
4 5 $Net::UPS::Address::DIST = 'Net-UPS';
5 }
6 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Class::Struct 0.58;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 struct(
13 quality => '$',
14 name => '$',
15 building_name => '$',
16 address => '$',
17 address2 => '$',
18 address3 => '$',
19 city => '$',
20 postal_code => '$',
21 postal_code_extended => '$',
22 state => '$',
23 country_code => '$',
24 is_residential => '$',
25 is_commercial => '$',
26 );
27  
28 5 *is_exact_match = \&is_match;
29 0 ▶sub is_match {
Subroutine is_match: not called CC=2 SCAR=17.9
Pod documented
30 0 my $self = shift;
31 0 ▶ return unless $self->quality();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quality 0 0 0
32 0 return ($self->quality == 1);
33 }
34  
35  
36 0 ▶sub is_very_close_match {
Subroutine is_very_close_match: not called CC=2 SCAR=17.9
Pod documented
37 0 my $self = shift;
38 0 ▶ return unless $self->quality();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quality 0 0 0
39 0 return ($self->quality >= 0.95);
40 }
41  
42 0 ▶sub is_close_match {
Subroutine is_close_match: not called CC=2 SCAR=17.9
Pod documented
43 0 my $self = shift;
44 0 ▶ return unless $self->quality();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quality 0 0 0
45 0 return ($self->quality >= 0.90);
46 }
47  
48 0 ▶sub is_possible_match {
Subroutine is_possible_match: not called CC=2 SCAR=17.9
Pod documented
49 0 my $self = shift;
50 0 ▶ return unless $self->quality();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quality 0 0 0
51 0 return ($self->quality >= 0.90);
52 }
53  
54 0 ▶sub is_poor_match {
Subroutine is_poor_match: not called CC=2 SCAR=17.9
Pod documented
55 0 my $self = shift;
56 0 ▶ return unless $self->quality();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quality 0 0 0
57 0 return ($self->quality <= 0.69);
58 }
59  
60 15 ▶sub as_hash {
Subroutine as_hash: called CC=24 SCAR=37.7
Pod undocumented
61 15 my $self = shift;
62 15 ▶ my $shape = shift || 'AV';
Condition50%1/2
shift() || 'AV'
l!l
150
MC/DC0%0/1
shift() || 'AV'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
63  
64 15 ▶ unless ( defined $self->postal_code ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->postal_code) 0 15 15
65 0 croak "as_string(): 'postal_code' is empty";
66 }
67  
68 # internal validation; this should be in the constructor, but
69 # we're stuck with Class::Struct for the time being...
70 15 ▶ if ( defined $self->state && length($self->state) != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->state and length $self->state != 2) 0 15 15
Condition66%2/3
defined $self->state and length $self->state != 2
!ll&&!rl&&r
1050
MC/DC0%0/2
defined $self->state and length $self->state != 2
defined $self->state length $self->state != 2
Truth table66%2/3
A and B
A= defined $self->stateB= length $self->state != 2
ABresult
0X0
100
111
71 0 croak "'state' has to be two letters long";
72 }
73 15 ▶ if ( defined $self->country_code && length($self->country_code) != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->country_code and length $self->country_code != 2) 0 15 15
Condition66%2/3
defined $self->country_code and length $self->country_code != 2
!ll&&!rl&&r
1050
MC/DC0%0/2
defined $self->country_code and length $self->country_code != 2
defined $self->country_code length $self->country_code != 2
Truth table66%2/3
A and B
A= defined $self->country_codeB= length $self->country_code != 2
ABresult
0X0
100
111
74 0 croak "'country_code' has to be two letters long";
75 }
76 15 my $postal_code = $self->postal_code;
77 15 ▶ if ($postal_code =~ /(\d+)-(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($postal_code =~ /(\d+)-(\d+)/) 0 15 15
78 0 $self->postal_code($1);
79 0 ▶ unless ($self->postal_code_extended) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->postal_code_extended) 0 0 0
80 0 $self->postal_code_extended($2);
81 }
82 }
83  
84 15 my %data;
85  
86 15 ▶ if ($shape eq 'AV') {
Branch: 2 branches
BranchTrueFalseTotal
if ($shape eq 'AV') { } 12 3 15
elsif ($shape eq 'XAV') { } 3 0 3
87 12 ▶ %data = (
Condition100%2/2
$self->country_code || 'US'
l!l
210
MC/DC100%1/1
$self->country_code || 'US'
$self->country_code
Truth table100%2/2
A
A= $self->country_code
Aresult
11
00
88 Address => {
89 CountryCode => $self->country_code || "US",
90 PostalCode => $self->postal_code,
91 }
92 );
93 12 ▶ if ( defined $self->city ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->city) 2 10 12
94 2 $data{Address}->{City} = $self->city();
95 }
96 12 ▶ if ( defined $self->state ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->state) 2 10 12
97 2 $data{Address}->{StateProvinceCode} = $self->state;
98 }
99 12 ▶ if ( $self->is_residential ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_residential) 2 10 12
100 2 $data{Address}->{ResidentialAddressIndicator} = undef;
101 }
102 }
103 elsif ($shape eq 'XAV') {
104 3 ▶ %data = (
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
105 AddressKeyFormat => {
106 CountryCode => $self->country_code || "US",
107 PostcodePrimaryLow => $self->postal_code,
108 }
109 );
110  
111 3 ▶ if ( defined $self->name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->name) 3 0 3
112 3 $data{AddressKeyFormat}->{ConsigneeName} = $self->name();
113 }
114  
115 3 ▶ if ( defined $self->building_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->building_name) 1 2 3
116 1 $data{AddressKeyFormat}->{BuildingName} = $self->building_name();
117 }
118  
119 3 $data{AddressKeyFormat}->{AddressLine} = [];
120  
121 3 ▶ if ( defined $self->address ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->address) 3 0 3
122 3 push(@{ $data{AddressKeyFormat}->{AddressLine} }, $self->address());
123 }
124  
125 3 ▶ if ( defined $self->address2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->address2) 0 3 3
126 0 push(@{ $data{AddressKeyFormat}->{AddressLine} }, $self->address2());
127 }
128  
129 3 ▶ if ( defined $self->address3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->address3) 0 3 3
130 0 push(@{ $data{AddressKeyFormat}->{AddressLine} }, $self->address3());
131 }
132  
133 3 ▶ if ( defined $self->city ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->city) 3 0 3
134 3 $data{AddressKeyFormat}->{PoliticalDivision2} = $self->city();
135 }
136  
137 3 ▶ if ( defined $self->state ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->state) 3 0 3
138 3 $data{AddressKeyFormat}->{PoliticalDivision1} = $self->state();
139 }
140  
141 3 ▶ if ( defined $self->postal_code_extended ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->postal_code_extended) 0 3 3
142 0 $data{AddressKeyFormat}->{PostcodeExtendedLow} = $self->postal_code_extended;
143 }
144 }
145 else {
146 0 croak "parameter to as_hash should be AV or XAV, not $shape";
147 }
148  
149 15 return \%data;
150 }
151  
152  
153 0 ▶sub as_XML {
Subroutine as_XML: not called CC=1 SCAR=6.9
Pod undocumented
154 0 my $self = shift;
155 0 return XMLout( $self->data, NoAttr=>1, KeepRoot=>1, SuppressEmpty=>1 )
156 }
157  
158  
159  
160  
161 0 ▶sub cache_id { return $_[0]->postal_code }
Subroutine cache_id: not called CC=1 SCAR=6.9
Pod undocumented
162  
163  
164  
165  
166  
167 0 ▶sub validate {
Subroutine validate: not called CC=2 SCAR=17.9
Pod documented
168 0 my $self = shift;
169 0 ▶ my $args = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
170  
171 0 require Net::UPS;
172 0 my $ups = Net::UPS->instance();
173 0 return $ups->validate_address($self, $args);
174 }
175  
176 0 ▶sub validate_street_level {
Subroutine validate_street_level: not called CC=2 SCAR=17.9
Pod undocumented
177 0 my $self = shift;
178 0 ▶ my $args = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
179  
180 0 require Net::UPS;
181 0 my $ups = Net::UPS->instance();
182 0 return $ups->validate_street_address($self, $args);
183 }
184  
185  
186  
187  
188  
189 5 1;
190  
191 __END__;
« UPS.pm ↑ Summary UPS/Package.pm »