UPS.pm

filter: Statementstmt 70.6% 231 / 327 Branchbran 51.1% 91 / 178 Conditioncond 34.2% 49 / 143 MC/DCmcdc 4.0% 3 / 75 Subroutinesub 79.5% 35 / 44 Podpod 58.6% 17 / 29 totaltotal 53.5% 426 / 796 CC 148 SCAR 46.7
CC
148
Cov
57%
request_rate
361.1
generate_cache_key
156.0
new
41.2
CRAP 106.6
↑ Summary UPS/Address.pm »
1 package Net::UPS;
2 5 $Net::UPS::VERSION = '0.16';
3 {
4 5 $Net::UPS::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 ('croak');
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Net::UPS::ErrorHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Net::UPS::Rate;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Net::UPS::Service;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Net::UPS::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Net::UPS::Package;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use IO::Socket::SSL;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 5 @Net::UPS::ISA = ( "Net::UPS::ErrorHandler" );
21 5 $Net::UPS::LIVE = 0;
22  
23 sub RATE_TEST_PROXY () { 'https://wwwcie.ups.com/ups.app/xml/Rate' }
24 sub RATE_LIVE_PROXY () { 'https://onlinetools.ups.com/ups.app/xml/Rate' }
25 sub AV_TEST_PROXY () { 'https://wwwcie.ups.com/ups.app/xml/AV' }
26 sub AV_LIVE_PROXY () { 'https://onlinetools.ups.com/ups.app/xml/AV' }
27 sub XAV_TEST_PROXY () { 'https://wwwcie.ups.com/ups.app/xml/XAV' }
28 sub XAV_LIVE_PROXY () { 'https://onlinetools.ups.com/ups.app/xml/XAV' }
29  
30 5 ▶sub PICKUP_TYPES () {
Subroutine PICKUP_TYPES: called CC=1 SCAR=0.0
Pod undocumented
31 return {
32 5 DAILY_PICKUP => '01',
33 DAILY => '01',
34 CUSTOMER_COUNTER => '03',
35 ONE_TIME_PICKUP => '06',
36 ONE_TIME => '06',
37 ON_CALL_AIR => '07',
38 SUGGESTED_RETAIL => '11',
39 SUGGESTED_RETAIL_RATES => '11',
40 LETTER_CENTER => '19',
41 AIR_SERVICE_CENTER => '20'
42 };
43 }
44  
45 0 ▶sub CUSTOMER_CLASSIFICATION () {
Subroutine CUSTOMER_CLASSIFICATION: not called CC=1 SCAR=6.9
Pod undocumented
46 return {
47 0 WHOLESALE => '01',
48 OCCASIONAL => '03',
49 RETAIL => '04'
50 };
51 }
52  
53  
54 13 ▶sub import {
Subroutine import: called CC=4 SCAR=23.7
55 13 my $class = shift;
56 13 ▶ @_ or return;
Branch: 1 branch
BranchTrueFalseTotal
@_ or return 0 13 13
57 0 ▶ if ( @_ % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2) 0 0 0
58 0 croak "import(): argument list has tobe in key=>value format";
59 }
60 0 my $args = { @_ };
61 0 ▶ $Net::UPS::LIVE = $args->{live} || 0;
Condition0%0/2
$args->{'live'} || 0
l!l
00
MC/DC0%0/1
$args->{'live'} || 0
$args->{'live'}
Truth table0%0/2
A
A= $args->{'live'}
Aresult
11
00
62 }
63  
64  
65 2 ▶sub live {
Subroutine live: called CC=2 SCAR=7.6
Pod documented
66 2 my $class = shift;
67 2 ▶ unless ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 2 2
68 0 croak "$class->live(): usage error";
69 }
70 2 $Net::UPS::LIVE = shift;
71 }
72  
73  
74  
75 5 my $ups = undef;
76 8 ▶sub new {
Subroutine new: called CC=16 SCAR=37.2
Pod documented
77 8 my $class = shift;
78 8 ▶ croak "new(): usage error" if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 8 8
79  
80 8 ▶ unless ( (@_ >= 1) || (@_ <= 4) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_ >= 1 or @_ <= 4) 0 8 8
Condition33%1/3
@_ >= 1 or @_ <= 4
l!l&&r!l&&!r
800
MC/DC0%0/2
@_ >= 1 or @_ <= 4
@_ >= 1 @_ <= 4
Truth table33%1/3
A or B
A= @_ >= 1B= @_ <= 4
ABresult
1X1
011
000
81 0 croak "new(): invalid number of arguments";
82 }
83 8 ▶ $ups = bless({
Condition87%7/8
$_[0] || undef
l!l
80
$_[1] || undef
l!l
53
$_[2] || undef
l!l
53
$_[3] || {}
l!l
35
MC/DC0%0/1
$_[0] || undef
$_[0]
MC/DC100%1/1
$_[1] || undef
$_[1]
MC/DC100%1/1
$_[2] || undef
$_[2]
MC/DC100%1/1
$_[3] || {}
$_[3]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
Truth table100%2/2
A
A= $_[2]
Aresult
11
00
Truth table100%2/2
A
A= $_[3]
Aresult
11
00
84 __userid => $_[0] || undef,
85 __password => $_[1] || undef,
86 __access_key => $_[2] || undef,
87 __args => $_[3] || {},
88 __last_service=> undef
89 }, $class);
90  
91 8 ▶ if ( @_ < 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ < 3) 3 5 8
92 3 ▶ $ups->_read_args_from_file(@_) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$ups->_read_args_from_file(@_) or return undef 1 2 3
93 }
94  
95 6 ▶ unless ( $ups->userid && $ups->password && $ups->access_key ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ups->userid and $ups->password and $ups->access_key) 0 6 6
Condition33%2/6
$ups->userid and $ups->password and $ups->access_key
!ll&&!rl&&r
006
$ups->userid and $ups->password
!ll&&!rl&&r
006
MC/DC0%0/3
$ups->userid and $ups->password and $ups->access_key
$ups->userid $ups->password $ups->access_key
Truth table25%1/4
A and B and C
A= $ups->useridB= $ups->passwordC= $ups->access_key
ABCresult
0XX0
10X0
1100
1111
96 0 croak "new(): usage error. Required arguments missing";
97 }
98 6 ▶ if ( my $cache_life = $ups->{__args}->{cache_life} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cache_life = $ups->{"__args"}{"cache_life"}) 0 6 6
99 0 eval "require Cache::File";
100 0 ▶ if (my $errstr = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $errstr = $@) 0 0 0
101 0 croak "'cache_life' requires Cache::File module";
102 }
103 0 ▶ unless ( $ups->{__args}->{cache_root} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ups->{"__args"}{"cache_root"}) 0 0 0
104 0 require File::Spec;
105 0 $ups->{__args}->{cache_root} = File::Spec->catdir(File::Spec->tmpdir, 'net_ups');
106 }
107 $ups->{__cache} = Cache::File->new( cache_root => $ups->{__args}->{cache_root},
108 0 default_expires => "$cache_life m",
109 cache_depth => 5,
110 lock_level => Cache::File::LOCK_LOCAL()
111 );
112 }
113 6 $ups->init();
114 6 return $ups;
115 }
116  
117  
118  
119  
120  
121 0 ▶sub instance {
Subroutine instance: not called CC=2 SCAR=17.9
Pod documented
122 0 ▶ return $ups if defined($ups);
Branch: 1 branch
BranchTrueFalseTotal
if defined $ups 0 0 0
123 0 croak "instance(): no object instance found";
124 }
125  
126  
127  
128  
129 3 ▶sub _read_args_from_file {
Subroutine _read_args_from_file: called CC=17 SCAR=34.1
130 3 my $self = shift;
131 3 my ($path, $args) = @_;
132 3 ▶ $args ||= {};
Condition50%1/2
$args ||= {}
l!l
03
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
133  
134 3 ▶ unless ( defined $path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path) 0 3 3
135 0 croak "_read_args_from_file(): required arguments are missing";
136 }
137  
138 3 require IO::File;
139 3 ▶ my $fh = IO::File->new($path, '<') or return $self->set_error("couldn't open $path: $!");
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($path, "<") or return $self->set_error("couldn't open ${path}: $!") 1 2 3
140 1 my %config = ();
141 1 ▶ while (local $_ = $fh->getline) {
Branch: 1 branch
BranchTrueFalseTotal
if (local $_ = $fh->getline) 5 1 6
142 5 ▶ next if /^\s*\#/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*\#/ 0 5 5
143 5 ▶ next if /^\n/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\n/ 0 5 5
144 5 ▶ next unless /^UPS/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^UPS/ 0 5 5
145 5 chomp();
146 5 my ($key, $value) = m/^\s*UPS(\w+)\s+(\S+)$/;
147 5 $config{ $key } = $value;
148 }
149 1 ▶ unless ( $config{UserID} && $config{Password} && $config{AccessKey} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config{"UserID"} and $config{"Password"} and $config{"AccessKey"}) 0 1 1
Condition33%2/6
$config{"UserID"} and $config{"Password"} and $config{"AccessKey"}
!ll&&!rl&&r
001
$config{"UserID"} and $config{"Password"}
!ll&&!rl&&r
001
MC/DC0%0/3
$config{"UserID"} and $config{"Password"} and $config{"AccessKey"}
$config{"UserID"} $config{"Password"} $config{"AccessKey"}
Truth table25%1/4
A and B and C
A= $config{"UserID"}B= $config{"Password"}C= $config{"AccessKey"}
ABCresult
0XX0
10X0
1100
1111
150 0 return $self->set_error( "_read_args_from_file(): required arguments are missing" );
151 }
152 1 $self->{__userid} = $config{UserID};
153 1 $self->{__password} = $config{Password};
154 1 $self->{__access_key} = $config{AccessKey};
155  
156  
157 1 ▶ $self->{__args}->{customer_classification} = $args->{customer_classification} || $config{CustomerClassification};
Condition33%1/3
$args->{'customer_classification'} || $config{'CustomerClassification'}
l!l&&r!l&&!r
001
MC/DC0%0/2
$args->{'customer_classification'} || $config{'CustomerClassification'}
$args->{'customer_classification'} $config{'CustomerClassification'}
Truth table33%1/3
A || B
A= $args->{'customer_classification'}B= $config{'CustomerClassification'}
ABresult
1X1
011
000
158 1 ▶ $self->{__args}->{ups_account_number} = $args->{ups_account_number} || $config{AccountNumber};
Condition33%1/3
$args->{'ups_account_number'} || $config{'AccountNumber'}
l!l&&r!l&&!r
001
MC/DC0%0/2
$args->{'ups_account_number'} || $config{'AccountNumber'}
$args->{'ups_account_number'} $config{'AccountNumber'}
Truth table33%1/3
A || B
A= $args->{'ups_account_number'}B= $config{'AccountNumber'}
ABresult
1X1
011
000
159 1 ▶ $self->{__args}->{rate_proxy} = $args->{rate_proxy} || $config{RateProxy};
Condition33%1/3
$args->{'rate_proxy'} || $config{'RateProxy'}
l!l&&r!l&&!r
010
MC/DC0%0/2
$args->{'rate_proxy'} || $config{'RateProxy'}
$args->{'rate_proxy'} $config{'RateProxy'}
Truth table33%1/3
A || B
A= $args->{'rate_proxy'}B= $config{'RateProxy'}
ABresult
1X1
011
000
160 1 ▶ $self->{__args}->{av_proxy} = $args->{av_proxy} || $config{AVProxy};
Condition33%1/3
$args->{'av_proxy'} || $config{'AVProxy'}
l!l&&r!l&&!r
010
MC/DC0%0/2
$args->{'av_proxy'} || $config{'AVProxy'}
$args->{'av_proxy'} $config{'AVProxy'}
Truth table33%1/3
A || B
A= $args->{'av_proxy'}B= $config{'AVProxy'}
ABresult
1X1
011
000
161 1 ▶ $self->cache_life( $args->{cache_life} || $config{CacheLife} );
Condition33%1/3
$args->{'cache_life'} || $config{'CacheLife'}
l!l&&r!l&&!r
001
MC/DC0%0/2
$args->{'cache_life'} || $config{'CacheLife'}
$args->{'cache_life'} $config{'CacheLife'}
Truth table33%1/3
A || B
A= $args->{'cache_life'}B= $config{'CacheLife'}
ABresult
1X1
011
000
162 1 ▶ $self->cache_root( $args->{cache_root} || $config{CacheRoot} );
Condition33%1/3
$args->{'cache_root'} || $config{'CacheRoot'}
l!l&&r!l&&!r
001
MC/DC0%0/2
$args->{'cache_root'} || $config{'CacheRoot'}
$args->{'cache_root'} $config{'CacheRoot'}
Truth table33%1/3
A || B
A= $args->{'cache_root'}B= $config{'CacheRoot'}
ABresult
1X1
011
000
163  
164 1 return $self;
165 }
166  
167 6 ▶sub init { }
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
168 10 ▶sub rate_proxy { return $_[0]->{__args}->{rate_proxy} || ($Net::UPS::LIVE ? RATE_LIVE_PROXY : RATE_TEST_PROXY) }
Subroutine rate_proxy: called CC=3 SCAR=11.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$Net::UPS::LIVE ? : 1 7 8
Condition66%2/3
$_[0]{'__args'}{'rate_proxy'} || ($Net::UPS::LIVE ? 'https://onlinetools.ups.com/ups.app/xml/Rate' : 'https://wwwcie.ups.com/ups.app/xml/Rate')
l!l&&r!l&&!r
280
MC/DC0%0/2
$_[0]{'__args'}{'rate_proxy'} || ($Net::UPS::LIVE ? 'https://onlinetools.ups.com/ups.app/xml/Rate' : 'https://wwwcie.ups.com/ups.app/xml/Rate')
$_[0]{'__args'}{'rate_proxy'} ($Net::UPS::LIVE ? 'https://onlinetools.ups.com/ups.app/xml/Rate' : 'https://wwwcie.ups.com/ups.app/xml/Rate')
Truth table66%2/3
A || B
A= $_[0]{'__args'}{'rate_proxy'}B= ($Net::UPS::LIVE ? 'https://onlinetools.ups.com/ups.app/xml/Rate' : 'https://wwwcie.ups.com/ups.app/xml/Rate')
ABresult
1X1
011
000
169 7 ▶sub av_proxy { return $_[0]->{__args}->{av_proxy} || ($Net::UPS::LIVE ? AV_LIVE_PROXY : AV_TEST_PROXY) }
Subroutine av_proxy: called CC=3 SCAR=11.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$Net::UPS::LIVE ? : 1 4 5
Condition66%2/3
$_[0]{'__args'}{'av_proxy'} || ($Net::UPS::LIVE ? 'https://onlinetools.ups.com/ups.app/xml/AV' : 'https://wwwcie.ups.com/ups.app/xml/AV')
l!l&&r!l&&!r
250
MC/DC0%0/2
$_[0]{'__args'}{'av_proxy'} || ($Net::UPS::LIVE ? 'https://onlinetools.ups.com/ups.app/xml/AV' : 'https://wwwcie.ups.com/ups.app/xml/AV')
$_[0]{'__args'}{'av_proxy'} ($Net::UPS::LIVE ? 'https://onlinetools.ups.com/ups.app/xml/AV' : 'https://wwwcie.ups.com/ups.app/xml/AV')
Truth table66%2/3
A || B
A= $_[0]{'__args'}{'av_proxy'}B= ($Net::UPS::LIVE ? 'https://onlinetools.ups.com/ups.app/xml/AV' : 'https://wwwcie.ups.com/ups.app/xml/AV')
ABresult
1X1
011
000
170 3 ▶sub xav_proxy { return $_[0]->{__args}->{xav_proxy} || ($Net::UPS::LIVE ? XAV_LIVE_PROXY : XAV_TEST_PROXY) }
Subroutine xav_proxy: called CC=3 SCAR=14.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$Net::UPS::LIVE ? : 0 3 3
Condition33%1/3
$_[0]{'__args'}{'xav_proxy'} || ($Net::UPS::LIVE ? 'https://onlinetools.ups.com/ups.app/xml/XAV' : 'https://wwwcie.ups.com/ups.app/xml/XAV')
l!l&&r!l&&!r
030
MC/DC0%0/2
$_[0]{'__args'}{'xav_proxy'} || ($Net::UPS::LIVE ? 'https://onlinetools.ups.com/ups.app/xml/XAV' : 'https://wwwcie.ups.com/ups.app/xml/XAV')
$_[0]{'__args'}{'xav_proxy'} ($Net::UPS::LIVE ? 'https://onlinetools.ups.com/ups.app/xml/XAV' : 'https://wwwcie.ups.com/ups.app/xml/XAV')
Truth table33%1/3
A || B
A= $_[0]{'__args'}{'xav_proxy'}B= ($Net::UPS::LIVE ? 'https://onlinetools.ups.com/ups.app/xml/XAV' : 'https://wwwcie.ups.com/ups.app/xml/XAV')
ABresult
1X1
011
000
171  
172 1 ▶sub cache_life { return $_[0]->{__args}->{cache_life} = $_[1] }
Subroutine cache_life: called CC=1 SCAR=0.0
Pod documented
173 1 ▶sub cache_root { return $_[0]->{__args}->{cache_root} = $_[1] }
Subroutine cache_root: called CC=1 SCAR=0.0
Pod documented
174 8 ▶sub userid { return $_[0]->{__userid} }
Subroutine userid: called CC=1 SCAR=0.0
Pod documented
175 8 ▶sub password { return $_[0]->{__password} }
Subroutine password: called CC=1 SCAR=0.0
Pod documented
176 6 ▶sub access_key { return $_[0]->{__access_key} }
Subroutine access_key: called CC=1 SCAR=0.0
Pod documented
177 0 ▶sub account_number{return $_[0]->{__args}->{ups_account_number} }
Subroutine account_number: not called CC=1 SCAR=6.9
Pod undocumented
178 0 ▶sub customer_classification { return $_[0]->{__args}->{customer_classification} }
Subroutine customer_classification: not called CC=1 SCAR=6.9
Pod documented
179 0 ▶sub dump { return Dumper($_[0]) }
Subroutine dump: not called CC=1 SCAR=6.9
Pod undocumented
180  
181 5 ▶sub ssl_options {
Subroutine ssl_options: called CC=2 SCAR=6.9
Pod documented
182 5 my ($self) = @_;
183  
184 5 ▶ unless ($self->{__args}{ssl_options}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"__args"}{"ssl_options"}) 1 4 5
185 1 require IO::Socket::SSL::Utils;
186 1 my $cert = IO::Socket::SSL::Utils::PEM_string2cert(<<'PEM');
187 -----BEGIN CERTIFICATE-----
188 MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMx
189 FzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmltYXJ5
190 IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVow
191 XzELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAz
192 IFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUA
193 A4GNADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhEBarsAx94
194 f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/isI19wKTakyYbnsZogy1Ol
195 hec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0GCSqGSIb3DQEBAgUAA4GBALtMEivPLCYA
196 TxQT3ab7/AoRhIzzKBxnki98tsX63/Dolbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59Ah
197 WM1pF+NEHJwZRDmJXNycAA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2Omuf
198 Tqj/ZA1k
199 -----END CERTIFICATE-----
200 PEM
201 1 require Mozilla::CA;
202 $self->{__args}{ssl_options} = {
203 1 SSL_verify_mode => 1,
204 SSL_verifycn_scheme => 'www',
205 SSL_ca => [ $cert ],
206 SSL_ca_file => Mozilla::CA::SSL_ca_file(),
207 };
208 }
209 5 return $self->{__args}{ssl_options};
210 }
211  
212  
213 3 ▶sub user_agent {
Subroutine user_agent: called CC=2 SCAR=6.9
Pod documented
214 3 my ($self) = @_;
215  
216 3 ▶ unless ($self->{__args}{user_agent}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"__args"}{"user_agent"}) 2 1 3
217 2 my $user_agent = LWP::UserAgent->new(
218 ssl_opts => $self->ssl_options,
219 );
220 2 $user_agent->env_proxy;
221 2 $self->{__args}{user_agent} = $user_agent;
222 }
223 return $self->{__args}{user_agent}
224 3 }
225  
226 0 ▶sub access_as_xml {
Subroutine access_as_xml: not called CC=1 SCAR=6.9
Pod undocumented
227 0 my $self = shift;
228 0 return XMLout({
229 AccessRequest => {
230 AccessLicenseNumber => $self->access_key,
231 Password => $self->password,
232 UserId => $self->userid
233 }
234 }, NoAttr=>1, KeepRoot=>1, XMLDecl=>1);
235 }
236  
237 10 ▶sub transaction_reference {
Subroutine transaction_reference: called CC=1 SCAR=0.0
Pod undocumented
238 return {
239 10 CustomerContext => "Net::UPS",
240 XpciVersion => '1.0001'
241 };
242 }
243  
244 3 ▶sub rate {
Subroutine rate: called CC=12 SCAR=25.5
Pod documented
245 3 my $self = shift;
246 3 my ($from, $to, $packages, $args) = @_;
247 3 ▶ croak "rate(): usage error" unless ($from && $to && $packages);
Branch: 1 branch
BranchTrueFalseTotal
unless $from and $to and $packages 0 3 3
Condition33%2/6
$from and $to and $packages
!ll&&!rl&&r
003
$from and $to
!ll&&!rl&&r
003
MC/DC0%0/3
$from and $to and $packages
$from $to $packages
Truth table25%1/4
A and B and C
A= $fromB= $toC= $packages
ABCresult
0XX0
10X0
1100
1111
248  
249 3 ▶ unless ( ref $from ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $from) 2 1 3
250 2 $from = Net::UPS::Address->new(postal_code=>$from);
251 }
252 3 ▶ unless ( ref $to ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $to) 2 1 3
253 2 $to = Net::UPS::Address->new(postal_code=>$to);
254 }
255 3 ▶ unless ( ref $packages eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $packages eq "ARRAY") 2 1 3
256 2 $packages = [$packages];
257 }
258 3 ▶ $args ||= {};
Condition50%1/2
$args ||= {}
l!l
03
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
259 3 $args->{mode} = "rate";
260 3 ▶ $args->{service} ||= "GROUND";
Condition50%1/2
$args->{"service"} ||= "GROUND"
l!l
03
MC/DC0%0/1
$args->{"service"} ||= "GROUND"
$args->{"service"}
Truth table50%1/2
A
A= $args->{"service"}
Aresult
11
00
261  
262 3 my $services = $self->request_rate($from, $to, $packages, $args);
263 3 ▶ return if !defined $services;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $services 0 3 3
264  
265 # we need to replace the rate->service ref with a non-weak one,
266 # but we also need to avoid the circular reference problem. Hence
267 # all this mess
268  
269 3 my $service = $services->[0];
270 3 my @rates = @{$service->rates()};
271 3 $service->rates([]); # now the service no longer references the rates
272 3 $_->service($service) for @rates; # and each rate has a non-weak service ref
273  
274 3 ▶ if ( @$packages == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$packages == 1) 2 1 3
275 2 return $rates[0];
276 }
277  
278 1 return \@rates;
279 }
280  
281  
282 2 ▶sub shop_for_rates {
Subroutine shop_for_rates: called CC=10 SCAR=27.1
Pod documented
283 2 my $self = shift;
284 2 my ($from, $to, $packages, $args) = @_;
285  
286 2 ▶ unless ( $from && $to && $packages ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from and $to and $packages) 0 2 2
Condition33%2/6
$from and $to and $packages
!ll&&!rl&&r
002
$from and $to
!ll&&!rl&&r
002
MC/DC0%0/3
$from and $to and $packages
$from $to $packages
Truth table25%1/4
A and B and C
A= $fromB= $toC= $packages
ABCresult
0XX0
10X0
1100
1111
287 0 croak "shop_for_rates(): usage error";
288 }
289 2 ▶ unless ( ref $from ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $from) 0 2 2
290 0 $from = Net::UPS::Address->new(postal_code=>$from);
291 }
292 2 ▶ unless ( ref $to ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $to) 0 2 2
293 0 $to = Net::UPS::Address->new(postal_code=>$to);
294 }
295 2 ▶ unless ( ref $packages eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $packages eq "ARRAY") 1 1 2
296 1 $packages = [$packages];
297 }
298 2 ▶ $args ||= {};
Condition50%1/2
$args ||= {}
l!l
02
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
299 2 $args->{mode} = "shop";
300 2 ▶ $args->{service}||= "GROUND";
Condition50%1/2
$args->{"service"} ||= "GROUND"
l!l
02
MC/DC0%0/1
$args->{"service"} ||= "GROUND"
$args->{"service"}
Truth table50%1/2
A
A= $args->{"service"}
Aresult
11
00
301  
302 # Scoob correction Aug 19th 2006 / cpan@pickledbrain.com
303 # There was a Perl run time error when no rates were found
304 # (empty package list, bad zip code etc...)
305 # request_rate() can now return undef in case of errors.
306 ####
307 2 my $services_aref = $self->request_rate($from, $to, $packages, $args);
308 2 ▶ if (defined $services_aref) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $services_aref) { } 2 0 2
309 2 return [sort {$a->total_charges <=>$b->total_charges} @$services_aref];
310 } else {
311 0 return undef; # No services were
312 }
313 }
314  
315 5 ▶sub request_rate {
Subroutine request_rate: called CC=45 SCAR=58.9
Pod undocumented
316 5 my $self = shift;
317 5 my ($from, $to, $packages, $args) = @_;
318  
319 5 ▶ croak "request_rate(): usage error" unless ($from && $to && $packages && $args);
Branch: 1 branch
BranchTrueFalseTotal
unless $from and $to and $packages and $args 0 5 5
Condition33%3/9
$from and $to and $packages and $args
!ll&&!rl&&r
005
$from and $to and $packages
!ll&&!rl&&r
005
$from and $to
!ll&&!rl&&r
005
MC/DC0%0/4
$from and $to and $packages and $args
$from $to $packages $args
Truth table20%1/5
A and B and C and D
A= $fromB= $toC= $packagesD= $args
ABCDresult
0XXX0
10XX0
110X0
11100
11111
320 5 ▶ unless (ref($from) && $from->isa("Net::UPS::Address")&&
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $from and $from->isa("Net::UPS::Address") and ref $to and $to->isa("Net::UPS::Address") and ref $packages and ref $packages eq "ARRAY" and ref $args and ref $args eq "HASH") 0 5 5
Condition33%7/21
ref $from and $from->isa("Net::UPS::Address") and ref $to and $to->isa("Net::UPS::Address") and ref $packages and ref $packages eq "ARRAY" and ref $args and ref $args eq "HASH"
!ll&&!rl&&r
005
ref $from and $from->isa("Net::UPS::Address") and ref $to and $to->isa("Net::UPS::Address") and ref $packages and ref $packages eq "ARRAY" and ref $args
!ll&&!rl&&r
005
ref $from and $from->isa("Net::UPS::Address") and ref $to and $to->isa("Net::UPS::Address") and ref $packages and ref $packages eq "ARRAY"
!ll&&!rl&&r
005
ref $from and $from->isa("Net::UPS::Address") and ref $to and $to->isa("Net::UPS::Address") and ref $packages
!ll&&!rl&&r
005
ref $from and $from->isa("Net::UPS::Address") and ref $to and $to->isa("Net::UPS::Address")
!ll&&!rl&&r
005
ref $from and $from->isa("Net::UPS::Address") and ref $to
!ll&&!rl&&r
005
ref $from and $from->isa("Net::UPS::Address")
!ll&&!rl&&r
005
MC/DC0%0/8
ref $from and $from->isa("Net::UPS::Address") and ref $to and $to->isa("Net::UPS::Address") and ref $packages and ref $packages eq "ARRAY" and ref $args and ref $args eq "HASH"
ref $from $from->isa("Net::UPS::Address") ref $to $to->isa("Net::UPS::Address") ref $packages ref $packages eq "ARRAY" ref $args ref $args eq "HASH"
Truth table11%1/9
A and B and C and D and E and F and G and H
A= ref $fromB= $from->isa("Net::UPS::Address")C= ref $toD= $to->isa("Net::UPS::Address")E= ref $packagesF= ref $packages eq "ARRAY"G= ref $argsH= ref $args eq "HASH"
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
321 ref($to) && $to->isa("Net::UPS::Address") &&
322 ref($packages) && (ref $packages eq 'ARRAY') &&
323 ref($args) && (ref $args eq 'HASH')) {
324 0 croak "request_rate(): usage error";
325 }
326 5 ▶ if ( defined($args->{limit_to}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"limit_to"}) 0 5 5
327 0 ▶ unless ( ref($args->{limit_to}) && ref($args->{limit_to}) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args->{"limit_to"} and ref $args->{"limit_to"} eq "ARRAY") 0 0 0
Condition0%0/3
ref $args->{"limit_to"} and ref $args->{"limit_to"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $args->{"limit_to"} and ref $args->{"limit_to"} eq "ARRAY"
ref $args->{"limit_to"} ref $args->{"limit_to"} eq "ARRAY"
Truth table0%0/3
A and B
A= ref $args->{"limit_to"}B= ref $args->{"limit_to"} eq "ARRAY"
ABresult
0X0
100
111
328 0 croak "request_rate(): usage error. 'limit_to' should be of type ARRAY";
329 }
330 }
331 5 ▶ if ( defined $args->{exclude} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"exclude"}) 0 5 5
332 0 ▶ unless ( ref($args->{exclude}) && ref($args->{exclude}) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args->{"exclude"} and ref $args->{"exclude"} eq "ARRAY") 0 0 0
Condition0%0/3
ref $args->{"exclude"} and ref $args->{"exclude"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $args->{"exclude"} and ref $args->{"exclude"} eq "ARRAY"
ref $args->{"exclude"} ref $args->{"exclude"} eq "ARRAY"
Truth table0%0/3
A and B
A= ref $args->{"exclude"}B= ref $args->{"exclude"} eq "ARRAY"
ABresult
0X0
100
111
333 0 croak "request_rate(): usage error. 'exclude' has to be of type 'ARRAY'";
334 }
335 }
336 5 ▶ if ( $args->{exclude} && $args->{limit_to} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"exclude"} and $args->{"limit_to"}) 0 5 5
Condition33%1/3
$args->{"exclude"} and $args->{"limit_to"}
!ll&&!rl&&r
500
MC/DC0%0/2
$args->{"exclude"} and $args->{"limit_to"}
$args->{"exclude"} $args->{"limit_to"}
Truth table33%1/3
A and B
A= $args->{"exclude"}B= $args->{"limit_to"}
ABresult
0X0
100
111
337 0 croak "request_rate(): usage error. You cannot use both 'limit_to' and 'exclude' at the same time";
338 }
339 5 ▶ unless (scalar(@$packages)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$packages) 0 5 5
340 0 return $self->set_error( "request_rate() was given an empty list of packages!" );
341 }
342  
343 5 ▶ for (my $i=0; $i < @$packages; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$packages) 7 5 12
344 7 $packages->[$i]->id( $i + 1 );
345 }
346 5 my $cache_key = undef;
347 5 my $cache = undef;
348 5 ▶ if ( defined($cache = $self->{__cache}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($cache = $self->{"__cache"})) 0 5 5
349 0 $cache_key = $self->generate_cache_key($from, $to, $packages, $args);
350 0 ▶ if ( my $services = $cache->thaw($cache_key) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $services = $cache->thaw($cache_key)) 0 0 0
351 0 return $services;
352 }
353 }
354 my %data = (
355 RatingServiceSelectionRequest => {
356 Request => {
357 RequestAction => 'Rate',
358 RequestOption => $args->{mode},
359 TransactionReference => $self->transaction_reference,
360 },
361 PickupType => {
362 Code => PICKUP_TYPES->{$self->{__args}->{pickup_type}||"ONE_TIME"}
363 },
364 Shipment => {
365 Service => { Code => Net::UPS::Service->new_from_label( $args->{service} )->code },
366 5 ▶ Package => [map { $_->as_hash()->{Package} } @$packages],
Condition50%1/2
$self->{'__args'}{'pickup_type'} || 'ONE_TIME'
l!l
05
MC/DC0%0/1
$self->{'__args'}{'pickup_type'} || 'ONE_TIME'
$self->{'__args'}{'pickup_type'}
Truth table50%1/2
A
A= $self->{'__args'}{'pickup_type'}
Aresult
11
00
367 Shipper => $from->as_hash('AV'),
368 ShipTo => $to->as_hash('AV')
369 }
370 });
371 5 ▶ if ( my $shipper_number = $self->{__args}->{ups_account_number} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $shipper_number = $self->{"__args"}{"ups_account_number"}) 0 5 5
372 0 $data{RatingServiceSelectionRequest}->{Shipment}->{Shipper}->{ShipperNumber} = $shipper_number;
373 }
374 5 ▶ if (my $classification_code = $self->{__args}->{customer_classification} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $classification_code = $self->{"__args"}{"customer_classification"}) 0 5 5
375 0 $data{RatingServiceSelectionRequest}->{CustomerClassification}->{Code} = CUSTOMER_CLASSIFICATION->{$classification_code};
376 }
377 5 my $xml = $self->access_as_xml . XMLout(\%data, KeepRoot=>1, NoAttr=>1, KeyAttr=>[], XMLDecl=>1);
378 5 my $response = XMLin( $self->post( $self->rate_proxy, $xml ),
379 KeepRoot => 0,
380 NoAttr => 1,
381 KeyAttr => [],
382 ForceArray => ['RatedPackage', 'RatedShipment']);
383  
384 ##############################################################################
385 # Scoob correction Jan 2nd 2007 / cpan AT pickledbrain.com
386 #
387 # Changes to handle latest UPS xml service. See this document for details:
388 #
389 # This new release of the document:
390 # "UPS online tools
391 # Rates and Service Selection - XML Programming Invormation
392 # version 1.0, Volume 7, number 1 rev date Dec 17th 2006"
393 #
394 # Get it at: http://www.ups.com/onlinetools (registration required)
395 #
396 # UPS just introduced two new errors codes (warning level):
397 # ErrorCode: 110971
398 # ErrorSeverity: Warning
399 # ErrorDescription: 'Your invoice may vary from the displayed reference rates'
400 # AND
401 # ErrorCode: 110920
402 # ErrorSeverity: Warning
403 # ErrorDescription: 'Ship To address has been changed from (residential/commercial)
404 # to (commercial/residential)'
405 #
406 # The original code here did not handle any "warning" level
407 # (there were no other cases of warning level errors prior to this)
408 # and simply returned an error w/o the shipping rates.
409 #
410 # The code change below simply ignore those two warnings as they are
411 # essentially legal cover-your-ass and not all that useful here.
412 #
413 #####
414 # Ignore "Warning" level error
415 5 ▶ if ( my $error = $response->{Response}->{Error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $response->{"Response"}{"Error"}) 0 5 5
416 0 ▶ unless ($error->{'ErrorSeverity'} eq 'Warning') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($error->{"ErrorSeverity"} eq "Warning") 0 0 0
417 0 return $self->set_error( $error->{ErrorDescription} );
418 }
419 }
420  
421 5 my @services;
422 5 ▶ for (my $i=0; $i < @{$response->{RatedShipment}}; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$response->{"RatedShipment"};}) 17 5 22
423 17 ▶ my $ref = $response->{RatedShipment}->[$i] or die;
Branch: 1 branch
BranchTrueFalseTotal
my $ref = $response->{"RatedShipment"}[$i] or die 17 0 17
424 17 my $service = Net::UPS::Service->new_from_code($ref->{Service}->{Code});
425 17 $service->total_charges( $ref->{TotalCharges}->{MonetaryValue} );
426 $service->guaranteed_days(ref($ref->{GuaranteedDaysToDelivery}) ?
427 17 ▶ undef : $ref->{GuaranteedDaysToDelivery});
Branch: 1 branch
BranchTrueFalseTotal
ref $ref->{'GuaranteedDaysToDelivery'} ? : 5 12 17
428 17 $service->rated_packages( $packages );
429 17 my @rates = ();
430 17 ▶ for (my $j=0; $j < @{$ref->{RatedPackage}}; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @{$ref->{"RatedPackage"};}) 25 17 42
431 push @rates, Net::UPS::Rate->new(
432 billing_weight => $ref->{RatedPackage}->[$j]->{BillingWeight}->{Weight},
433 total_charges => $ref->{RatedPackage}->[$j]->{TotalCharges}->{MonetaryValue},
434 25 rated_package => $packages->[$j],
435 service => $service,
436 from => $from,
437 to => $to
438 );
439 # bad hack! we have to do it this way because:
440 #
441 # 1) Class::Struct has no support for weak references
442 #
443 # 2) weakening the result of the accessor would not change
444 # the actual value inside the object
445 #
446 # 3) the objects created by Class::Struct by default are
447 # array-based
448 #
449 # we are clearly breaking encapsulation, and this may stop
450 # working if the internals of Class::Struct change. I
451 # can't see any better way, though.
452 25 weaken($rates[-1]->[3]);
453 }
454 17 $service->rates(\@rates);
455 17 ▶ if ( (lc($args->{mode}) eq 'shop') && defined($cache) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $args->{"mode"} eq "shop" and defined $cache) 0 17 17
Condition66%2/3
lc $args->{"mode"} eq "shop" and defined $cache
!ll&&!rl&&r
3140
MC/DC0%0/2
lc $args->{"mode"} eq "shop" and defined $cache
lc $args->{"mode"} eq "shop" defined $cache
Truth table66%2/3
A and B
A= lc $args->{"mode"} eq "shop"B= defined $cache
ABresult
0X0
100
111
456 0 local ($args->{mode}, $args->{service});
457 0 $args->{mode} = 'rate';
458 0 $args->{service} = $service->label;
459 0 my $cache_key = $self->generate_cache_key($from, $to, $packages, $args);
460 0 $cache->freeze($cache_key, [$service]);
461 }
462 17 ▶ if ( $args->{limit_to} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"limit_to"}) 0 17 17
463 0 my $limit_ok = 0;
464 0 for ( @{$args->{limit_to}} ) {
465 0 ▶ ($_ eq $service->label) && $limit_ok++;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq $service->label and ++$limit_ok 0 0 0
466 }
467 0 ▶ $limit_ok or next;
Branch: 1 branch
BranchTrueFalseTotal
$limit_ok or next 0 0 0
468 }
469 17 ▶ if ( $args->{exclude} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"exclude"}) 0 17 17
470 0 my $exclude_ok = 0;
471 0 for ( @{$args->{exclude}} ) {
472 0 ▶ ($_ eq $service->label) && $exclude_ok++;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq $service->label and ++$exclude_ok 0 0 0
473 }
474 0 ▶ $exclude_ok and next;
Branch: 1 branch
BranchTrueFalseTotal
$exclude_ok and next 0 0 0
475 }
476 17 push @services, $service;
477 17 $self->{__last_service} = $service;
478  
479 }
480 5 ▶ if ( defined $cache ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cache) 0 5 5
481 0 $cache->freeze($cache_key, \@services);
482 }
483 5 return \@services;
484 }
485  
486  
487  
488  
489 0 ▶sub service {
Subroutine service: not called CC=1 SCAR=6.9
Pod documented
490 0 return $_[0]->{__last_service};
491 }
492  
493  
494 0 ▶sub post {
Subroutine post: not called CC=4 SCAR=30.0
Pod undocumented
495 0 my $self = shift;
496 0 my ($url, $content) = @_;
497  
498 0 ▶ unless ( $url && $content ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($url and $content) 0 0 0
Condition0%0/3
$url and $content
!ll&&!rl&&r
000
MC/DC0%0/2
$url and $content
$url $content
Truth table0%0/3
A and B
A= $urlB= $content
ABresult
0X0
100
111
499 0 croak "post(): usage error";
500 }
501  
502 0 my $request = HTTP::Request->new('POST', $url);
503 0 $request->content( encode('utf-8',$content) );
504 0 my $response = $self->user_agent->request( $request );
505 0 ▶ if ( $response->is_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_error) 0 0 0
506 0 die $response->status_line();
507 }
508 0 return $response->decoded_content;
509 }
510  
511  
512  
513  
514 2 ▶sub validate_address {
Subroutine validate_address: called CC=13 SCAR=29.1
Pod documented
515 2 my $self = shift;
516 2 my ($address, $args) = @_;
517  
518 2 ▶ croak "verify_address(): usage error" unless defined($address);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $address 0 2 2
519  
520 2 ▶ unless ( ref $address ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $address) 0 2 2
521 0 $address = {postal_code => $address};
522 }
523 2 ▶ if ( ref $address eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $address eq "HASH") 0 2 2
524 0 $address = Net::UPS::Address->new(%$address);
525 }
526 2 ▶ $args ||= {};
Condition50%1/2
$args ||= {}
l!l
20
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
527 2 ▶ unless ( defined $args->{tolerance} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args->{"tolerance"}) 0 2 2
528 0 $args->{tolerance} = 0.05;
529 }
530 2 ▶ unless ( ($args->{tolerance} >= 0) && ($args->{tolerance} <= 1) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"tolerance"} >= 0 and $args->{"tolerance"} <= 1) 0 2 2
Condition33%1/3
$args->{"tolerance"} >= 0 and $args->{"tolerance"} <= 1
!ll&&!rl&&r
002
MC/DC0%0/2
$args->{"tolerance"} >= 0 and $args->{"tolerance"} <= 1
$args->{"tolerance"} >= 0 $args->{"tolerance"} <= 1
Truth table33%1/3
A and B
A= $args->{"tolerance"} >= 0B= $args->{"tolerance"} <= 1
ABresult
0X0
100
111
531 0 croak "validate_address(): invalid tolerance threshold";
532 }
533 my %data = (
534 AddressValidationRequest => {
535 Request => {
536 RequestAction => "AV",
537 TransactionReference => $self->transaction_reference(),
538 },
539 2 %{$address->as_hash('AV')},
540 }
541 );
542  
543 2 my $xml = $self->access_as_xml . XMLout(\%data, KeepRoot=>1, NoAttr=>1, KeyAttr=>[], XMLDecl=>1);
544 2 my $response = XMLin($self->post($self->av_proxy, $xml),
545 KeepRoot=>0, NoAttr=>1,
546 KeyAttr=>[], ForceArray=>["AddressValidationResult"]);
547  
548 2 ▶ if ( my $error = $response->{Response}->{Error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $response->{"Response"}{"Error"}) 0 2 2
549 0 ▶ unless ($error->{'ErrorSeverity'} eq 'Warning') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($error->{"ErrorSeverity"} eq "Warning") 0 0 0
550 0 return $self->set_error( $error->{ErrorDescription} );
551 }
552 }
553 2 my @addresses = ();
554 2 ▶ for (my $i=0; $i < @{$response->{AddressValidationResult}}; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$response->{"AddressValidationResult"};}) 11 2 13
555 11 my $ref = $response->{AddressValidationResult}->[$i];
556 11 ▶ next if $ref->{Quality} < (1 - $args->{tolerance});
Branch: 1 branch
BranchTrueFalseTotal
if $ref->{"Quality"} < 1 - $args->{"tolerance"} 10 1 11
557 1 ▶ while ( $ref->{PostalCodeLowEnd} <= $ref->{PostalCodeHighEnd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->{"PostalCodeLowEnd"} <= $ref->{"PostalCodeHighEnd"}) 4 1 5
558 my $address = Net::UPS::Address->new(
559 quality => $ref->{Quality},
560 postal_code => $ref->{PostalCodeLowEnd},
561 city => $ref->{Address}->{City},
562 state => $ref->{Address}->{StateProvinceCode},
563 4 country_code => "US"
564 );
565 4 push @addresses, $address;
566 4 $ref->{PostalCodeLowEnd}++;
567 }
568 }
569 2 return \@addresses;
570 }
571  
572 3 ▶sub validate_street_address {
Subroutine validate_street_address: called CC=14 SCAR=31.2
Pod undocumented
573 3 my $self = shift;
574 3 my ($address, $args) = @_;
575  
576 3 ▶ croak "validate_street_address(): usage error" unless defined($address);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $address 0 3 3
577  
578 3 ▶ unless ( ref $address ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $address) 0 3 3
579 0 $address = {postal_code => $address};
580 }
581 3 ▶ if ( ref $address eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $address eq "HASH") 0 3 3
582 0 $address = Net::UPS::StreetAddress->new(%$address);
583 }
584 3 ▶ $args ||= {};
Condition50%1/2
$args ||= {}
l!l
03
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
585  
586 my %data = (
587 AddressValidationRequest => {
588 Request => {
589 RequestAction => "XAV",
590 RequestOption => "3",
591 TransactionReference => $self->transaction_reference(),
592 },
593 3 %{$address->as_hash('XAV')},
594 },
595 );
596  
597 3 my $xml = $self->access_as_xml . XMLout(\%data, KeepRoot=>1, NoAttr=>1, KeyAttr=>[], XMLDecl=>1);
598 3 my $response = XMLin($self->post($self->xav_proxy, $xml),
599 KeepRoot=>0, NoAttr=>1,
600 KeyAttr=>[], ForceArray=>["AddressValidationResponse", "AddressLine"]);
601  
602 3 ▶ if ( my $error = $response->{Response}->{Error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $response->{"Response"}{"Error"}) 0 3 3
603 0 ▶ unless ($error->{'ErrorSeverity'} eq 'Warning') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($error->{"ErrorSeverity"} eq "Warning") 0 0 0
604 0 return $self->set_error( $error->{ErrorDescription} );
605 }
606 }
607 3 ▶ if ( $response->{NoCandidatesIndicator} )
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"NoCandidatesIndicator"}) 1 2 3
608 {
609 1 return $self->set_error("The Address Matching System is not able to match an address from any other one in the database.");
610 }
611 2 my $quality = 0;
612 2 ▶ if ( $response->{AmbiguousAddressIndicator} )
Branch: 2 branches
BranchTrueFalseTotal
if ($response->{'AmbiguousAddressIndicator'}) { } 0 2 2
elsif ($response->{'ValidAddressIndicator'}) { } 2 0 2
613 {
614 0 $self->set_error("The Address Matching System is not able to explicitly differentiate an address from any other one in the database.");
615 }
616 elsif ( $response->{ValidAddressIndicator} )
617 {
618 2 $quality = 1;
619 }
620  
621 2 my $response_address;
622 2 ▶ if ($response->{AddressKeyFormat}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"AddressKeyFormat"}) 2 0 2
623 2 my $akf = $response->{AddressKeyFormat};
624 2 ▶ if (ref($akf) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $akf eq "ARRAY") 0 2 2
625 0 $akf = $akf->[0];
626 }
627 $response_address = Net::UPS::Address->new(
628 quality => $quality,
629 building_name => $akf->{BuildingName},
630 address => $akf->{AddressLine}->[0],
631 address2 => $akf->{AddressLine}->[1],
632 address3 => $akf->{AddressLine}->[2],
633 postal_code => $akf->{PostcodePrimaryLow},
634 postal_code_extended => $akf->{PostcodeExtendedLow},
635 city => $akf->{PoliticalDivision2},
636 state => $akf->{PoliticalDivision1},
637 country_code => $akf->{CountryCode},
638 is_commercial => ( $response->{AddressClassification}->{Code} eq "1" ) ? 1 : 0,
639 2 ▶ is_residential => ( $response->{AddressClassification}->{Code} eq "2" ) ? 1 : 0,
Branch: 2 branches
BranchTrueFalseTotal
$response->{'AddressClassification'}{'Code'} eq '1' ? : 2 0 2
$response->{'AddressClassification'}{'Code'} eq '2' ? : 0 2 2
640 );
641 }
642  
643 2 return $response_address;
644 }
645  
646 0 ▶sub generate_cache_key {
Subroutine generate_cache_key: not called CC=12 SCAR=50.5
Pod undocumented
647 0 my $self = shift;
648 0 my ($from, $to, $packages, $args) = @_;
649 0 ▶ unless ( $from && $to && $packages && ref($from) && ref($to) && ref($packages) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from and $to and $packages and ref $from and ref $to and ref $packages) 0 0 0
Condition0%0/15
$from and $to and $packages and ref $from and ref $to and ref $packages
!ll&&!rl&&r
000
$from and $to and $packages and ref $from and ref $to
!ll&&!rl&&r
000
$from and $to and $packages and ref $from
!ll&&!rl&&r
000
$from and $to and $packages
!ll&&!rl&&r
000
$from and $to
!ll&&!rl&&r
000
MC/DC0%0/6
$from and $to and $packages and ref $from and ref $to and ref $packages
$from $to $packages ref $from ref $to ref $packages
Truth table0%0/7
A and B and C and D and E and F
A= $fromB= $toC= $packagesD= ref $fromE= ref $toF= ref $packages
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
650 0 croak "generate_cache_key(): usage error";
651 }
652 0 my @keys = ($from->cache_id, $to->cache_id);
653 0 for my $package ( @$packages ) {
654 0 push @keys, $package->cache_id;
655 }
656 0 for my $key ( sort keys %{$self->{__args}} ) {
657 0 push @keys, sprintf("%s:%s", lc $key, lc $self->{__args}->{$key} );
658 }
659 0 for my $key (sort keys %$args ) {
660 0 ▶ next if $key eq 'limit_to';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "limit_to" 0 0 0
661 0 ▶ next if $key eq 'exclude';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "exclude" 0 0 0
662 0 push @keys, sprintf("%s:%s", lc $key, lc $args->{$key});
663 }
664 0 return join(":", @keys);
665 }
666  
667  
668  
669  
670 5 1;
671 __END__
↑ Summary UPS/Address.pm »