| 1 | package Net::Async::Webservice::UPS; | ||||||||||||||||||||||||||||
| 2 | 5 | $Net::Async::Webservice::UPS::VERSION = '1.1.4'; | |||||||||||||||||||||||||||
| 3 | { | ||||||||||||||||||||||||||||
| 4 | 5 | $Net::Async::Webservice::UPS::DIST = 'Net-Async-Webservice-UPS'; | |||||||||||||||||||||||||||
| 5 | } | ||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use XML::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Types::Standard 1.000003 qw(Str Int Bool Object Dict Optional ArrayRef HashRef Undef); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Types::URI qw(Uri); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Type::Params qw(compile); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Error::TypeTiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Net::Async::Webservice::UPS::Types qw(:types to_Service); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Net::Async::Webservice::UPS::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use List::AllUtils 'pairwise'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use Net::Async::Webservice::UPS::Rate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 5 | ▶ | use Net::Async::Webservice::UPS::Address; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use Net::Async::Webservice::UPS::Service; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 5 | ▶ | use Net::Async::Webservice::UPS::Response::Rate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 5 | ▶ | use Net::Async::Webservice::UPS::Response::Address; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 5 | ▶ | use Net::Async::Webservice::UPS::Response::ShipmentConfirm; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 5 | ▶ | use Net::Async::Webservice::UPS::Response::ShipmentAccept; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 5 | ▶ | use Net::Async::Webservice::UPS::Response::QV; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 5 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 5 | ▶ | use Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 5 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # ABSTRACT: UPS API client, non-blocking | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 5 | my %code_for_pickup_type = ( | |||||||||||||||||||||||||||
| 35 | DAILY_PICKUP => '01', | ||||||||||||||||||||||||||||
| 36 | DAILY => '01', | ||||||||||||||||||||||||||||
| 37 | CUSTOMER_COUNTER => '03', | ||||||||||||||||||||||||||||
| 38 | ONE_TIME_PICKUP => '06', | ||||||||||||||||||||||||||||
| 39 | ONE_TIME => '06', | ||||||||||||||||||||||||||||
| 40 | ON_CALL_AIR => '07', | ||||||||||||||||||||||||||||
| 41 | SUGGESTED_RETAIL => '11', | ||||||||||||||||||||||||||||
| 42 | SUGGESTED_RETAIL_RATES => '11', | ||||||||||||||||||||||||||||
| 43 | LETTER_CENTER => '19', | ||||||||||||||||||||||||||||
| 44 | AIR_SERVICE_CENTER => '20' | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 5 | my %code_for_customer_classification = ( | |||||||||||||||||||||||||||
| 48 | WHOLESALE => '01', | ||||||||||||||||||||||||||||
| 49 | OCCASIONAL => '03', | ||||||||||||||||||||||||||||
| 50 | RETAIL => '04' | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 5 | my %base_urls = ( | |||||||||||||||||||||||||||
| 54 | live => 'https://onlinetools.ups.com/ups.app/xml', | ||||||||||||||||||||||||||||
| 55 | test => 'https://wwwcie.ups.com/ups.app/xml', | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | has live_mode => ( | ||||||||||||||||||||||||||||
| 60 | is => 'rw', | ||||||||||||||||||||||||||||
| 61 | isa => Bool, | ||||||||||||||||||||||||||||
| 62 | trigger => 1, | ||||||||||||||||||||||||||||
| 63 | 1 | ▶ | default => sub { 0 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | 5 | ); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 5 | has base_url => ( | |||||||||||||||||||||||||||
| 68 | is => 'lazy', | ||||||||||||||||||||||||||||
| 69 | isa => Uri, | ||||||||||||||||||||||||||||
| 70 | clearer => '_clear_base_url', | ||||||||||||||||||||||||||||
| 71 | coerce => Uri->coercion, | ||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | ▶ | sub _trigger_live_mode { | ||||||||||||||||||||||||||
|
Subroutine
_trigger_live_mode: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 75 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 2 | $self->_clear_base_url; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 3 | ▶ | sub _build_base_url { | ||||||||||||||||||||||||||
|
Subroutine
_build_base_url: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 80 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 3 | ▶ | return $base_urls{$self->live_mode ? 'live' : 'test'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 5 | has user_id => ( | |||||||||||||||||||||||||||
| 87 | is => 'ro', | ||||||||||||||||||||||||||||
| 88 | isa => Str, | ||||||||||||||||||||||||||||
| 89 | required => 1, | ||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||
| 91 | 5 | has password => ( | |||||||||||||||||||||||||||
| 92 | is => 'ro', | ||||||||||||||||||||||||||||
| 93 | isa => Str, | ||||||||||||||||||||||||||||
| 94 | required => 1, | ||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||
| 96 | 5 | has access_key => ( | |||||||||||||||||||||||||||
| 97 | is => 'ro', | ||||||||||||||||||||||||||||
| 98 | isa => Str, | ||||||||||||||||||||||||||||
| 99 | required => 1, | ||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 5 | has account_number => ( | |||||||||||||||||||||||||||
| 104 | is => 'ro', | ||||||||||||||||||||||||||||
| 105 | isa => Str, | ||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 5 | has customer_classification => ( | |||||||||||||||||||||||||||
| 110 | is => 'rw', | ||||||||||||||||||||||||||||
| 111 | isa => CustomerClassification, | ||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | has pickup_type => ( | ||||||||||||||||||||||||||||
| 116 | is => 'rw', | ||||||||||||||||||||||||||||
| 117 | isa => PickupType, | ||||||||||||||||||||||||||||
| 118 | 1 | ▶ | default => sub { 'ONE_TIME' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 119 | 5 | ); | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 5 | has cache => ( | |||||||||||||||||||||||||||
| 123 | is => 'ro', | ||||||||||||||||||||||||||||
| 124 | isa => Cache|Undef, | ||||||||||||||||||||||||||||
| 125 | ); | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 21 | ▶ | sub does_caching { | ||||||||||||||||||||||||||
|
Subroutine
does_caching: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 129 | 21 | my ($self) = @_; | |||||||||||||||||||||||||||
| 130 | 21 | return defined $self->cache; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 1 | ▶ | sub _build_ssl_options { | ||||||||||||||||||||||||||
|
Subroutine
_build_ssl_options: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 135 | 1 | ▶ | eval "require IO::Socket::SSL; require IO::Socket::SSL::Utils; require Mozilla::CA;" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | or return {}; | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 1 | my $cert = IO::Socket::SSL::Utils::PEM_string2cert(<<'PEM'); | |||||||||||||||||||||||||||
| 139 | -----BEGIN CERTIFICATE----- | ||||||||||||||||||||||||||||
| 140 | MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMx | ||||||||||||||||||||||||||||
| 141 | FzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmltYXJ5 | ||||||||||||||||||||||||||||
| 142 | IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVow | ||||||||||||||||||||||||||||
| 143 | XzELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAz | ||||||||||||||||||||||||||||
| 144 | IFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUA | ||||||||||||||||||||||||||||
| 145 | A4GNADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhEBarsAx94 | ||||||||||||||||||||||||||||
| 146 | f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/isI19wKTakyYbnsZogy1Ol | ||||||||||||||||||||||||||||
| 147 | hec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0GCSqGSIb3DQEBAgUAA4GBALtMEivPLCYA | ||||||||||||||||||||||||||||
| 148 | TxQT3ab7/AoRhIzzKBxnki98tsX63/Dolbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59Ah | ||||||||||||||||||||||||||||
| 149 | WM1pF+NEHJwZRDmJXNycAA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2Omuf | ||||||||||||||||||||||||||||
| 150 | Tqj/ZA1k | ||||||||||||||||||||||||||||
| 151 | -----END CERTIFICATE----- | ||||||||||||||||||||||||||||
| 152 | PEM | ||||||||||||||||||||||||||||
| 153 | return { | ||||||||||||||||||||||||||||
| 154 | 1 | SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(), | |||||||||||||||||||||||||||
| 155 | SSL_ca => [ $cert ], | ||||||||||||||||||||||||||||
| 156 | SSL_ca_file => Mozilla::CA::SSL_ca_file(), | ||||||||||||||||||||||||||||
| 157 | }; | ||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 5 | with 'Net::Async::Webservice::Common::WithUserAgent'; | |||||||||||||||||||||||||||
| 162 | 5 | with 'Net::Async::Webservice::Common::WithConfigFile'; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 1 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=16.3
| |||||||||||||||||||||||||||||
| 165 | 1 | my ($orig,$class,@args) = @_; | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 1 | my $ret = $class->$orig(@args); | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 1 | ▶ | if ($ret->{cache_life}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 0 | require CHI; | |||||||||||||||||||||||||||
| 171 | 0 | ▶ | if (not $ret->{cache_root}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | require File::Spec; | |||||||||||||||||||||||||||
| 173 | $ret->{cache_root} = | ||||||||||||||||||||||||||||
| 174 | 0 | File::Spec->catdir(File::Spec->tmpdir,'naws_ups'), | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | $ret->{cache} = CHI->new( | ||||||||||||||||||||||||||||
| 177 | driver => 'File', | ||||||||||||||||||||||||||||
| 178 | root_dir => $ret->{cache_root}, | ||||||||||||||||||||||||||||
| 179 | depth => 5, | ||||||||||||||||||||||||||||
| 180 | 0 | expires_in => $ret->{cache_life} . ' min', | |||||||||||||||||||||||||||
| 181 | ); | ||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 1 | return $ret; | |||||||||||||||||||||||||||
| 185 | 5 | }; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 22 | ▶ | sub transaction_reference { | ||||||||||||||||||||||||||
|
Subroutine
transaction_reference: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 189 | 22 | my ($self,$args) = @_; | |||||||||||||||||||||||||||
| 190 | 5 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 191 | return { | ||||||||||||||||||||||||||||
| 192 | 22 | ▶ | CustomerContext => ($args->{customer_context} // "Net::Async::Webservice::UPS"), | ||||||||||||||||||||||||||
|
Condition75%3/4
$args->{"customer_context"} // "Net::Async::Webservice::UPS"
$Net::Async::Webservice::UPS::VERSION || 0
MC/DC100%1/1
$args->{"customer_context"} // "Net::Async::Webservice::UPS"
$args->{"customer_context"}
MC/DC0%0/1
$Net::Async::Webservice::UPS::VERSION || 0
$Net::Async::Webservice::UPS::VERSION
Truth table100%2/2
A
A= $args->{"customer_context"}
Truth table50%1/2
A
A= $Net::Async::Webservice::UPS::VERSION
| |||||||||||||||||||||||||||||
| 193 | XpciVersion => "".($Net::Async::Webservice::UPS::VERSION||0), | ||||||||||||||||||||||||||||
| 194 | }; | ||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 22 | ▶ | sub access_as_xml { | ||||||||||||||||||||||||||
|
Subroutine
access_as_xml: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 199 | 22 | my $self = shift; | |||||||||||||||||||||||||||
| 200 | 22 | return XMLout({ | |||||||||||||||||||||||||||
| 201 | AccessRequest => { | ||||||||||||||||||||||||||||
| 202 | AccessLicenseNumber => $self->access_key, | ||||||||||||||||||||||||||||
| 203 | Password => $self->password, | ||||||||||||||||||||||||||||
| 204 | UserId => $self->user_id, | ||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | }, NoAttr=>1, KeepRoot=>1, XMLDecl=>1); | ||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 5 | ▶ | sub request_rate { | ||||||||||||||||||||||||||
|
Subroutine
request_rate: called CC=15 SCAR=32.5
Pod
documented
| |||||||||||||||||||||||||||||
| 211 | 5 | state $argcheck = compile(Object, Dict[ | |||||||||||||||||||||||||||
| 212 | from => Address|Shipper, | ||||||||||||||||||||||||||||
| 213 | to => Address, | ||||||||||||||||||||||||||||
| 214 | packages => PackageList, | ||||||||||||||||||||||||||||
| 215 | limit_to => Optional[ArrayRef[Str]], | ||||||||||||||||||||||||||||
| 216 | exclude => Optional[ArrayRef[Str]], | ||||||||||||||||||||||||||||
| 217 | mode => Optional[RequestMode], | ||||||||||||||||||||||||||||
| 218 | service => Optional[Service], | ||||||||||||||||||||||||||||
| 219 | customer_context => Optional[Str], | ||||||||||||||||||||||||||||
| 220 | ]); | ||||||||||||||||||||||||||||
| 221 | 5 | my ($self,$args) = $argcheck->(@_); | |||||||||||||||||||||||||||
| 222 | 5 | ▶ | $args->{mode} ||= 'rate'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"mode"} ||= "rate"
MC/DC100%1/1
$args->{"mode"} ||= "rate"
$args->{"mode"}
Truth table100%2/2
A
A= $args->{"mode"}
| |||||||||||||||||||||||||||||
| 223 | 5 | ▶ | $args->{service} ||= to_Service('GROUND'); | ||||||||||||||||||||||||||
|
Condition33%1/3
$args->{"service"} ||= &to_Service("GROUND")
MC/DC0%0/2
$args->{"service"} ||= &to_Service("GROUND")
$args->{"service"}
&to_Service("GROUND")
Truth table33%1/3
A ||= B
A= $args->{"service"}B= &to_Service("GROUND")
| |||||||||||||||||||||||||||||
| 224 | 5 | ▶ | if ($args->{from}->isa('Net::Async::Webservice::UPS::Address')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 5 | ▶ | $args->{from} ||= $self->_shipper_from_address($args->{from}); | ||||||||||||||||||||||||||
|
Condition33%1/3
$args->{"from"} ||= $self->_shipper_from_address($args->{"from"})
MC/DC0%0/2
$args->{"from"} ||= $self->_shipper_from_address($args->{"from"})
$args->{"from"}
$self->_shipper_from_address($args->{"from"})
Truth table33%1/3
A ||= B
A= $args->{"from"}B= $self->_shipper_from_address($args->{"from"})
| |||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 5 | ▶ | if ( $args->{exclude} && $args->{limit_to} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args->{"exclude"} and $args->{"limit_to"}
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"}
| |||||||||||||||||||||||||||||
| 229 | 0 | Error::TypeTiny::croak("You cannot use both 'limit_to' and 'exclude' at the same time"); | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 5 | my $packages = $args->{packages}; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 5 | ▶ | unless (scalar(@$packages)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | 0 | Error::TypeTiny::croak("request_rate() was given an empty list of packages"); | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 5 | my $cache_key; | |||||||||||||||||||||||||||
| 239 | 5 | ▶ | if ($self->does_caching) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | $cache_key = $self->generate_cache_key( | ||||||||||||||||||||||||||||
| 241 | 'rate', | ||||||||||||||||||||||||||||
| 242 | [ $args->{from},$args->{to},@$packages, ], | ||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||
| 244 | mode => $args->{mode}, | ||||||||||||||||||||||||||||
| 245 | service => $args->{service}->code, | ||||||||||||||||||||||||||||
| 246 | 0 | pickup_type => $self->pickup_type, | |||||||||||||||||||||||||||
| 247 | customer_classification => $self->customer_classification, | ||||||||||||||||||||||||||||
| 248 | }, | ||||||||||||||||||||||||||||
| 249 | ); | ||||||||||||||||||||||||||||
| 250 | 0 | ▶ | if (my $cached_services = $self->cache->get($cache_key)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | 0 | return Future->wrap($cached_services); | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | my %request = ( | ||||||||||||||||||||||||||||
| 256 | RatingServiceSelectionRequest => { | ||||||||||||||||||||||||||||
| 257 | Request => { | ||||||||||||||||||||||||||||
| 258 | RequestAction => 'Rate', | ||||||||||||||||||||||||||||
| 259 | RequestOption => $args->{mode}, | ||||||||||||||||||||||||||||
| 260 | TransactionReference => $self->transaction_reference($args), | ||||||||||||||||||||||||||||
| 261 | }, | ||||||||||||||||||||||||||||
| 262 | PickupType => { | ||||||||||||||||||||||||||||
| 263 | Code => $code_for_pickup_type{$self->pickup_type}, | ||||||||||||||||||||||||||||
| 264 | }, | ||||||||||||||||||||||||||||
| 265 | Shipment => { | ||||||||||||||||||||||||||||
| 266 | Service => { Code => $args->{service}->code }, | ||||||||||||||||||||||||||||
| 267 | 7 | ▶ | Package => [map { $_->as_hash() } @$packages], | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | Shipper => $args->{from}->as_hash('AV'), | ||||||||||||||||||||||||||||
| 269 | ShipTo => $args->{to}->as_hash('AV'), | ||||||||||||||||||||||||||||
| 270 | }, | ||||||||||||||||||||||||||||
| 271 | ( $self->customer_classification ? ( | ||||||||||||||||||||||||||||
| 272 | 5 | CustomerClassification => { Code => $code_for_customer_classification{$self->customer_classification} } | |||||||||||||||||||||||||||
| 273 | ) : () ), | ||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | ); | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | # default to "all allowed" | ||||||||||||||||||||||||||||
| 278 | 5 | my %ok_labels = map { $_ => 1 } @{ServiceLabel->values}; | |||||||||||||||||||||||||||
| 279 | 5 | ▶ | if ($args->{limit_to}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 280 | # deny all, allow requested | ||||||||||||||||||||||||||||
| 281 | 0 | %ok_labels = map { $_ => 0 } @{ServiceLabel->values}; | |||||||||||||||||||||||||||
| 282 | 0 | $ok_labels{$_} = 1 for @{$args->{limit_to}}; | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | elsif ($args->{exclude}) { | ||||||||||||||||||||||||||||
| 285 | # deny requested | ||||||||||||||||||||||||||||
| 286 | 0 | $ok_labels{$_} = 0 for @{$args->{exclude}}; | |||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | $self->xml_request({ | ||||||||||||||||||||||||||||
| 290 | data => \%request, | ||||||||||||||||||||||||||||
| 291 | url_suffix => '/Rate', | ||||||||||||||||||||||||||||
| 292 | XMLin => { | ||||||||||||||||||||||||||||
| 293 | ForceArray => [ 'RatedPackage', 'RatedShipment' ], | ||||||||||||||||||||||||||||
| 294 | }, | ||||||||||||||||||||||||||||
| 295 | })->transform( | ||||||||||||||||||||||||||||
| 296 | 5 | ▶ | done => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 297 | 5 | my ($response) = @_; | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 5 | my @services; | |||||||||||||||||||||||||||
| 300 | 5 | for my $rated_shipment (@{$response->{RatedShipment}}) { | |||||||||||||||||||||||||||
| 301 | 17 | my $code = $rated_shipment->{Service}{Code}; | |||||||||||||||||||||||||||
| 302 | 17 | my $label = Net::Async::Webservice::UPS::Service::label_for_code($code); | |||||||||||||||||||||||||||
| 303 | 17 | ▶ | next if not $ok_labels{$label}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | push @services, my $service = Net::Async::Webservice::UPS::Service->new({ | ||||||||||||||||||||||||||||
| 306 | code => $code, | ||||||||||||||||||||||||||||
| 307 | label => $label, | ||||||||||||||||||||||||||||
| 308 | total_charges => $rated_shipment->{TotalCharges}{MonetaryValue}, | ||||||||||||||||||||||||||||
| 309 | # TODO check this logic | ||||||||||||||||||||||||||||
| 310 | ( ref($rated_shipment->{GuaranteedDaysToDelivery}) | ||||||||||||||||||||||||||||
| 311 | ? () | ||||||||||||||||||||||||||||
| 312 | : ( guaranteed_days => $rated_shipment->{GuaranteedDaysToDelivery} ) ), | ||||||||||||||||||||||||||||
| 313 | rated_packages => $packages, | ||||||||||||||||||||||||||||
| 314 | # TODO check this pairwise | ||||||||||||||||||||||||||||
| 315 | 25 | ▶ | rates => [ pairwise { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 316 | Net::Async::Webservice::UPS::Rate->new({ | ||||||||||||||||||||||||||||
| 317 | %$a, | ||||||||||||||||||||||||||||
| 318 | rated_package => $b, | ||||||||||||||||||||||||||||
| 319 | from => $args->{from}, | ||||||||||||||||||||||||||||
| 320 | to => $args->{to}, | ||||||||||||||||||||||||||||
| 321 | 25 | }); | |||||||||||||||||||||||||||
| 322 | 17 | ▶ | } @{$rated_shipment->{RatedPackage}},@$packages ], | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | }); | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | # fixup service-rate-service refs | ||||||||||||||||||||||||||||
| 326 | 17 | $_->_set_service($service) for @{$service->rates}; | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | 5 | @services = sort { $a->total_charges <=> $b->total_charges } @services; | |||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 5 | my $ret = Net::Async::Webservice::UPS::Response::Rate->new({ | |||||||||||||||||||||||||||
| 331 | %$response, | ||||||||||||||||||||||||||||
| 332 | services => \@services, | ||||||||||||||||||||||||||||
| 333 | }); | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 5 | ▶ | $self->cache->set($cache_key,$ret) if $self->does_caching; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 5 | return $ret; | |||||||||||||||||||||||||||
| 338 | }, | ||||||||||||||||||||||||||||
| 339 | 5 | ); | |||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 4 | ▶ | sub validate_address { | ||||||||||||||||||||||||||
|
Subroutine
validate_address: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||
| 344 | 4 | state $argcheck = compile( | |||||||||||||||||||||||||||
| 345 | Object, | ||||||||||||||||||||||||||||
| 346 | Address, Optional[Tolerance], | ||||||||||||||||||||||||||||
| 347 | ); | ||||||||||||||||||||||||||||
| 348 | 4 | my ($self,$address,$tolerance) = $argcheck->(@_); | |||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 4 | ▶ | $tolerance //= 0.05; | ||||||||||||||||||||||||||
|
Condition100%2/2
$tolerance //= "0.05"
MC/DC100%1/1
$tolerance //= "0.05"
$tolerance
Truth table100%2/2
A
A= $tolerance
| |||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | my %data = ( | ||||||||||||||||||||||||||||
| 353 | AddressValidationRequest => { | ||||||||||||||||||||||||||||
| 354 | Request => { | ||||||||||||||||||||||||||||
| 355 | RequestAction => "AV", | ||||||||||||||||||||||||||||
| 356 | TransactionReference => $self->transaction_reference(), | ||||||||||||||||||||||||||||
| 357 | }, | ||||||||||||||||||||||||||||
| 358 | 4 | %{$address->as_hash('AV')}, | |||||||||||||||||||||||||||
| 359 | }, | ||||||||||||||||||||||||||||
| 360 | ); | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 4 | my $cache_key; | |||||||||||||||||||||||||||
| 363 | 4 | ▶ | if ($self->does_caching) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | 0 | $cache_key = $self->generate_cache_key( | |||||||||||||||||||||||||||
| 365 | 'AV', | ||||||||||||||||||||||||||||
| 366 | [ $address ], | ||||||||||||||||||||||||||||
| 367 | { tolerance => $tolerance }, | ||||||||||||||||||||||||||||
| 368 | ); | ||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if (my $cached_services = $self->cache->get($cache_key)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | 0 | return Future->wrap($cached_services); | |||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | $self->xml_request({ | ||||||||||||||||||||||||||||
| 375 | data => \%data, | ||||||||||||||||||||||||||||
| 376 | url_suffix => '/AV', | ||||||||||||||||||||||||||||
| 377 | XMLin => { | ||||||||||||||||||||||||||||
| 378 | ForceArray => [ 'AddressValidationResult' ], | ||||||||||||||||||||||||||||
| 379 | }, | ||||||||||||||||||||||||||||
| 380 | })->transform( | ||||||||||||||||||||||||||||
| 381 | 2 | ▶ | done => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 382 | 2 | my ($response) = @_; | |||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | 2 | my @addresses; | |||||||||||||||||||||||||||
| 385 | 2 | for my $address (@{$response->{AddressValidationResult}}) { | |||||||||||||||||||||||||||
| 386 | 11 | ▶ | next if $address->{Quality} < (1 - $tolerance); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | 1 | for my $possible_postal_code ($address->{PostalCodeLowEnd} .. $address->{PostalCodeHighEnd}) { | |||||||||||||||||||||||||||
| 388 | 4 | $address->{Address}{PostalCode} = $possible_postal_code; | |||||||||||||||||||||||||||
| 389 | 4 | push @addresses, Net::Async::Webservice::UPS::Address->new($address); | |||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 2 | my $ret = Net::Async::Webservice::UPS::Response::Address->new({ | |||||||||||||||||||||||||||
| 395 | %$response, | ||||||||||||||||||||||||||||
| 396 | addresses => \@addresses, | ||||||||||||||||||||||||||||
| 397 | }); | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 2 | ▶ | $self->cache->set($cache_key,$ret) if $self->does_caching; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 400 | 2 | return $ret; | |||||||||||||||||||||||||||
| 401 | }, | ||||||||||||||||||||||||||||
| 402 | 4 | ); | |||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 3 | ▶ | sub validate_street_address { | ||||||||||||||||||||||||||
|
Subroutine
validate_street_address: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||
| 407 | 3 | state $argcheck = compile( | |||||||||||||||||||||||||||
| 408 | Object, | ||||||||||||||||||||||||||||
| 409 | Address, | ||||||||||||||||||||||||||||
| 410 | ); | ||||||||||||||||||||||||||||
| 411 | 3 | my ($self,$address) = $argcheck->(@_); | |||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | my %data = ( | ||||||||||||||||||||||||||||
| 414 | AddressValidationRequest => { | ||||||||||||||||||||||||||||
| 415 | Request => { | ||||||||||||||||||||||||||||
| 416 | RequestAction => 'XAV', | ||||||||||||||||||||||||||||
| 417 | RequestOption => '3', | ||||||||||||||||||||||||||||
| 418 | TransactionReference => $self->transaction_reference(), | ||||||||||||||||||||||||||||
| 419 | }, | ||||||||||||||||||||||||||||
| 420 | 3 | %{$address->as_hash('XAV')}, | |||||||||||||||||||||||||||
| 421 | }, | ||||||||||||||||||||||||||||
| 422 | ); | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | 3 | my $cache_key; | |||||||||||||||||||||||||||
| 425 | 3 | ▶ | if ($self->does_caching) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 426 | 0 | $cache_key = $self->generate_cache_key( | |||||||||||||||||||||||||||
| 427 | 'XAV', | ||||||||||||||||||||||||||||
| 428 | [ $address ], | ||||||||||||||||||||||||||||
| 429 | ); | ||||||||||||||||||||||||||||
| 430 | 0 | ▶ | if (my $cached_services = $self->cache->get($cache_key)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | 0 | return Future->wrap($cached_services); | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | $self->xml_request({ | ||||||||||||||||||||||||||||
| 436 | data => \%data, | ||||||||||||||||||||||||||||
| 437 | url_suffix => '/XAV', | ||||||||||||||||||||||||||||
| 438 | XMLin => { | ||||||||||||||||||||||||||||
| 439 | ForceArray => [ 'AddressValidationResponse','AddressLine', 'AddressKeyFormat' ], | ||||||||||||||||||||||||||||
| 440 | }, | ||||||||||||||||||||||||||||
| 441 | })->then( | ||||||||||||||||||||||||||||
| 442 | 3 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||
| 443 | 3 | my ($response) = @_; | |||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | 3 | ▶ | if ($response->{NoCandidatesIndicator}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 447 | 1 | return Future->new->fail(Net::Async::Webservice::UPS::Exception::UPSError->new({ | |||||||||||||||||||||||||||
| 448 | error => { | ||||||||||||||||||||||||||||
| 449 | ErrorDescription => 'The Address Matching System is not able to match an address from any other one in the database', | ||||||||||||||||||||||||||||
| 450 | ErrorCode => 'NoCandidates', | ||||||||||||||||||||||||||||
| 451 | }, | ||||||||||||||||||||||||||||
| 452 | }),'ups'); | ||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||
| 454 | 2 | ▶ | if ($response->{AmbiguousAddressIndicator}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 455 | 0 | return Future->new->fail(Net::Async::Webservice::UPS::Exception::UPSError->new({ | |||||||||||||||||||||||||||
| 456 | error => { | ||||||||||||||||||||||||||||
| 457 | ErrorDescription => 'The Address Matching System is not able to explicitly differentiate an address from any other one in the database', | ||||||||||||||||||||||||||||
| 458 | ErrorCode => 'AmbiguousAddress', | ||||||||||||||||||||||||||||
| 459 | }, | ||||||||||||||||||||||||||||
| 460 | }),'ups'); | ||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | 2 | my $quality = 0; | |||||||||||||||||||||||||||
| 464 | 2 | ▶ | if ($response->{ValidAddressIndicator}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 465 | 2 | $quality = 1; | |||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 2 | my @addresses; | |||||||||||||||||||||||||||
| 469 | 2 | for my $ak (@{$response->{AddressKeyFormat}}) { | |||||||||||||||||||||||||||
| 470 | 2 | push @addresses, Net::Async::Webservice::UPS::Address->new({ | |||||||||||||||||||||||||||
| 471 | AddressKeyFormat => $ak, | ||||||||||||||||||||||||||||
| 472 | Quality => $quality, | ||||||||||||||||||||||||||||
| 473 | }); | ||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | 2 | my $ret = Net::Async::Webservice::UPS::Response::Address->new({ | |||||||||||||||||||||||||||
| 477 | %$response, | ||||||||||||||||||||||||||||
| 478 | addresses => \@addresses, | ||||||||||||||||||||||||||||
| 479 | }); | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | 2 | ▶ | $self->cache->set($cache_key,$ret) if $self->does_caching; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 482 | 2 | return Future->wrap($ret); | |||||||||||||||||||||||||||
| 483 | }, | ||||||||||||||||||||||||||||
| 484 | 3 | ); | |||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | 3 | ▶ | sub ship_confirm { | ||||||||||||||||||||||||||
|
Subroutine
ship_confirm: called CC=9 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||
| 489 | 3 | state $argcheck = compile(Object, Dict[ | |||||||||||||||||||||||||||
| 490 | from => Contact, | ||||||||||||||||||||||||||||
| 491 | to => Contact, | ||||||||||||||||||||||||||||
| 492 | shipper => Optional[Shipper], | ||||||||||||||||||||||||||||
| 493 | service => Optional[Service], | ||||||||||||||||||||||||||||
| 494 | description => Str, | ||||||||||||||||||||||||||||
| 495 | payment => Payment, | ||||||||||||||||||||||||||||
| 496 | label => Optional[Label], | ||||||||||||||||||||||||||||
| 497 | packages => PackageList, | ||||||||||||||||||||||||||||
| 498 | return_service => Optional[ReturnService], | ||||||||||||||||||||||||||||
| 499 | customer_context => Optional[Str], | ||||||||||||||||||||||||||||
| 500 | delivery_confirmation => Optional[Int], | ||||||||||||||||||||||||||||
| 501 | ]); | ||||||||||||||||||||||||||||
| 502 | 3 | my ($self,$args) = $argcheck->(@_); | |||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | 3 | ▶ | $args->{service} //= to_Service('GROUND'); | ||||||||||||||||||||||||||
|
Condition33%1/3
$args->{"service"} //= &to_Service("GROUND")
MC/DC0%0/2
$args->{"service"} //= &to_Service("GROUND")
$args->{"service"}
&to_Service("GROUND")
Truth table33%1/3
A //= B
A= $args->{"service"}B= &to_Service("GROUND")
| |||||||||||||||||||||||||||||
| 505 | 3 | ▶ | $args->{shipper} //= $self->_shipper_from_contact($args->{from}); | ||||||||||||||||||||||||||
|
Condition33%1/3
$args->{"shipper"} //= $self->_shipper_from_contact($args->{"from"})
MC/DC0%0/2
$args->{"shipper"} //= $self->_shipper_from_contact($args->{"from"})
$args->{"shipper"}
$self->_shipper_from_contact($args->{"from"})
Truth table33%1/3
A //= B
A= $args->{"shipper"}B= $self->_shipper_from_contact($args->{"from"})
| |||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | 3 | my $packages = $args->{packages}; | |||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | 3 | ▶ | unless (scalar(@$packages)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 510 | 0 | Error::TypeTiny::croak("ship_confirm() was given an empty list of packages"); | |||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||
| 512 | 3 | my $package_data = [map { $_->as_hash() } @$packages]; | |||||||||||||||||||||||||||
| 513 | 3 | ▶ | if ($args->{delivery_confirmation}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 514 | 0 | for my $p (@$package_data) { | |||||||||||||||||||||||||||
| 515 | $p->{PackageServiceOptions}{DeliveryConfirmation}{DCISType} = | ||||||||||||||||||||||||||||
| 516 | 0 | $args->{delivery_confirmation}; | |||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | my %data = ( | ||||||||||||||||||||||||||||
| 521 | ShipmentConfirmRequest => { | ||||||||||||||||||||||||||||
| 522 | Request => { | ||||||||||||||||||||||||||||
| 523 | TransactionReference => $self->transaction_reference($args), | ||||||||||||||||||||||||||||
| 524 | RequestAction => 'ShipConfirm', | ||||||||||||||||||||||||||||
| 525 | RequestOption => 'validate', # this makes the request | ||||||||||||||||||||||||||||
| 526 | # fail if there are | ||||||||||||||||||||||||||||
| 527 | # address problems | ||||||||||||||||||||||||||||
| 528 | }, | ||||||||||||||||||||||||||||
| 529 | Shipment => { | ||||||||||||||||||||||||||||
| 530 | Service => { Code => $args->{service}->code }, | ||||||||||||||||||||||||||||
| 531 | Description => $args->{description}, | ||||||||||||||||||||||||||||
| 532 | ( $args->{return_service} ? ( | ||||||||||||||||||||||||||||
| 533 | ReturnService => { Code => $args->{return_service}->code } | ||||||||||||||||||||||||||||
| 534 | ) : () ), | ||||||||||||||||||||||||||||
| 535 | Shipper => $args->{shipper}->as_hash, | ||||||||||||||||||||||||||||
| 536 | ( $args->{from} ? ( ShipFrom => $args->{from}->as_hash ) : () ), | ||||||||||||||||||||||||||||
| 537 | ShipTo => $args->{to}->as_hash, | ||||||||||||||||||||||||||||
| 538 | PaymentInformation => $args->{payment}->as_hash, | ||||||||||||||||||||||||||||
| 539 | Package => $package_data, | ||||||||||||||||||||||||||||
| 540 | }, | ||||||||||||||||||||||||||||
| 541 | 3 | ▶ | ( $args->{label} ? ( LabelSpecification => $args->{label}->as_hash ) : () ), | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||
| 543 | ); | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | $self->xml_request({ | ||||||||||||||||||||||||||||
| 546 | data => \%data, | ||||||||||||||||||||||||||||
| 547 | url_suffix => '/ShipConfirm', | ||||||||||||||||||||||||||||
| 548 | })->transform( | ||||||||||||||||||||||||||||
| 549 | 3 | ▶ | done => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 550 | 3 | my ($response) = @_; | |||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | 3 | return Net::Async::Webservice::UPS::Response::ShipmentConfirm->new({ | |||||||||||||||||||||||||||
| 553 | %$response, | ||||||||||||||||||||||||||||
| 554 | packages => $packages, | ||||||||||||||||||||||||||||
| 555 | }); | ||||||||||||||||||||||||||||
| 556 | }, | ||||||||||||||||||||||||||||
| 557 | 3 | ); | |||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | 3 | ▶ | sub ship_accept { | ||||||||||||||||||||||||||
|
Subroutine
ship_accept: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 562 | 3 | state $argcheck = compile( Object, Dict[ | |||||||||||||||||||||||||||
| 563 | confirm => ShipmentConfirm, | ||||||||||||||||||||||||||||
| 564 | customer_context => Optional[Str], | ||||||||||||||||||||||||||||
| 565 | ]); | ||||||||||||||||||||||||||||
| 566 | 3 | my ($self,$args) = $argcheck->(@_); | |||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | my %data = ( | ||||||||||||||||||||||||||||
| 569 | ShipmentAcceptRequest => { | ||||||||||||||||||||||||||||
| 570 | Request => { | ||||||||||||||||||||||||||||
| 571 | TransactionReference => $self->transaction_reference($args), | ||||||||||||||||||||||||||||
| 572 | RequestAction => 'ShipAccept', | ||||||||||||||||||||||||||||
| 573 | }, | ||||||||||||||||||||||||||||
| 574 | ShipmentDigest => $args->{confirm}->shipment_digest, | ||||||||||||||||||||||||||||
| 575 | }, | ||||||||||||||||||||||||||||
| 576 | 3 | ); | |||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | 3 | my $packages = $args->{confirm}->packages; | |||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | $self->xml_request({ | ||||||||||||||||||||||||||||
| 581 | data => \%data, | ||||||||||||||||||||||||||||
| 582 | url_suffix => '/ShipAccept', | ||||||||||||||||||||||||||||
| 583 | XMLin => { | ||||||||||||||||||||||||||||
| 584 | ForceArray => [ 'PackageResults' ], | ||||||||||||||||||||||||||||
| 585 | }, | ||||||||||||||||||||||||||||
| 586 | })->transform( | ||||||||||||||||||||||||||||
| 587 | 3 | ▶ | done => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 588 | 3 | my ($response) = @_; | |||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||
| 590 | 3 | return Net::Async::Webservice::UPS::Response::ShipmentAccept->new({ | |||||||||||||||||||||||||||
| 591 | packages => $packages, | ||||||||||||||||||||||||||||
| 592 | %$response, | ||||||||||||||||||||||||||||
| 593 | }); | ||||||||||||||||||||||||||||
| 594 | }, | ||||||||||||||||||||||||||||
| 595 | 3 | ); | |||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | 4 | ▶ | sub qv_events { | ||||||||||||||||||||||||||
|
Subroutine
qv_events: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 600 | 4 | state $argcheck = compile( Object, Dict[ | |||||||||||||||||||||||||||
| 601 | subscriptions => Optional[ArrayRef[QVSubscription]], | ||||||||||||||||||||||||||||
| 602 | bookmark => Optional[Str], | ||||||||||||||||||||||||||||
| 603 | customer_context => Optional[Str], | ||||||||||||||||||||||||||||
| 604 | ]); | ||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | 4 | my ($self,$args) = $argcheck->(@_); | |||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | my %data = ( | ||||||||||||||||||||||||||||
| 609 | QuantumViewRequest => { | ||||||||||||||||||||||||||||
| 610 | Request => { | ||||||||||||||||||||||||||||
| 611 | TransactionReference => $self->transaction_reference($args), | ||||||||||||||||||||||||||||
| 612 | RequestAction => 'QVEvents', | ||||||||||||||||||||||||||||
| 613 | }, | ||||||||||||||||||||||||||||
| 614 | ( $args->{subscriptions} ? ( SubscriptionRequest => [ | ||||||||||||||||||||||||||||
| 615 | 2 | ▶ | map { $_->as_hash } @{$args->{subscriptions}} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 616 | ] ) : () ), | ||||||||||||||||||||||||||||
| 617 | 4 | ▶ | ($args->{bookmark} ? (Bookmark => $args->{bookmark}) : () ), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 618 | }, | ||||||||||||||||||||||||||||
| 619 | ); | ||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||
| 621 | $self->xml_request({ | ||||||||||||||||||||||||||||
| 622 | data => \%data, | ||||||||||||||||||||||||||||
| 623 | url_suffix => '/QVEvents', | ||||||||||||||||||||||||||||
| 624 | })->transform( | ||||||||||||||||||||||||||||
| 625 | 3 | ▶ | done => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 626 | 3 | my ($response) = @_; | |||||||||||||||||||||||||||
| 627 | 3 | return Net::Async::Webservice::UPS::Response::QV->new($response); | |||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||
| 629 | 4 | ); | |||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||
| 633 | 22 | ▶ | sub xml_request { | ||||||||||||||||||||||||||
|
Subroutine
xml_request: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 634 | 22 | state $argcheck = compile( | |||||||||||||||||||||||||||
| 635 | Object, | ||||||||||||||||||||||||||||
| 636 | Dict[ | ||||||||||||||||||||||||||||
| 637 | data => HashRef, | ||||||||||||||||||||||||||||
| 638 | url_suffix => Str, | ||||||||||||||||||||||||||||
| 639 | XMLout => Optional[HashRef], | ||||||||||||||||||||||||||||
| 640 | XMLin => Optional[HashRef], | ||||||||||||||||||||||||||||
| 641 | ], | ||||||||||||||||||||||||||||
| 642 | ); | ||||||||||||||||||||||||||||
| 643 | 22 | my ($self, $args) = $argcheck->(@_); | |||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||
| 645 | # default XML::Simple args | ||||||||||||||||||||||||||||
| 646 | 22 | my $xmlargs = { | |||||||||||||||||||||||||||
| 647 | NoAttr => 1, | ||||||||||||||||||||||||||||
| 648 | KeyAttr => [], | ||||||||||||||||||||||||||||
| 649 | }; | ||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||
| 651 | my $request = | ||||||||||||||||||||||||||||
| 652 | $self->access_as_xml . | ||||||||||||||||||||||||||||
| 653 | XMLout( | ||||||||||||||||||||||||||||
| 654 | $args->{data}, | ||||||||||||||||||||||||||||
| 655 | 22 | %{ $xmlargs }, | |||||||||||||||||||||||||||
| 656 | XMLDecl => 1, | ||||||||||||||||||||||||||||
| 657 | KeepRoot => 1, | ||||||||||||||||||||||||||||
| 658 | 22 | ▶ | %{ $args->{XMLout}||{} }, | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'XMLout'} || {}
MC/DC0%0/1
$args->{'XMLout'} || {}
$args->{'XMLout'}
Truth table50%1/2
A
A= $args->{'XMLout'}
| |||||||||||||||||||||||||||||
| 659 | ); | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | return $self->post( $self->base_url . $args->{url_suffix}, $request )->then( | ||||||||||||||||||||||||||||
| 662 | 21 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 663 | 21 | my ($response_string) = @_; | |||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | my $response = XMLin( | ||||||||||||||||||||||||||||
| 666 | $response_string, | ||||||||||||||||||||||||||||
| 667 | 21 | %{ $xmlargs }, | |||||||||||||||||||||||||||
| 668 | 21 | %{ $args->{XMLin} }, | |||||||||||||||||||||||||||
| 669 | ); | ||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||
| 671 | 21 | ▶ | if ($response->{Response}{ResponseStatusCode}==0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 672 | return Future->new->fail( | ||||||||||||||||||||||||||||
| 673 | Net::Async::Webservice::UPS::Exception::UPSError->new({ | ||||||||||||||||||||||||||||
| 674 | error => $response->{Response}{Error} | ||||||||||||||||||||||||||||
| 675 | 2 | }), | |||||||||||||||||||||||||||
| 676 | 'ups', | ||||||||||||||||||||||||||||
| 677 | ); | ||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||
| 679 | 19 | return Future->wrap($response); | |||||||||||||||||||||||||||
| 680 | }, | ||||||||||||||||||||||||||||
| 681 | 22 | ); | |||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | 5 | with 'Net::Async::Webservice::Common::WithRequestWrapper'; | |||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||
| 688 | 0 | ▶ | sub generate_cache_key { | ||||||||||||||||||||||||||
|
Subroutine
generate_cache_key: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 689 | 0 | state $argcheck = compile(Object, Str, ArrayRef[Cacheable],Optional[HashRef]); | |||||||||||||||||||||||||||
| 690 | 0 | my ($self,$kind,$things,$args) = $argcheck->(@_); | |||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||
| 692 | return join ':', | ||||||||||||||||||||||||||||
| 693 | $kind, | ||||||||||||||||||||||||||||
| 694 | 0 | ( map { $_->cache_id } @$things ), | |||||||||||||||||||||||||||
| 695 | ( map { | ||||||||||||||||||||||||||||
| 696 | sprintf '%s:%s', | ||||||||||||||||||||||||||||
| 697 | $_, | ||||||||||||||||||||||||||||
| 698 | 0 | ▶ | ( defined($args->{$_}) ? '"'.$args->{$_}.'"' : 'undef' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 699 | 0 | ▶ | } sort keys %{$args || {}} | ||||||||||||||||||||||||||
|
Condition0%0/2
$args || {}
MC/DC0%0/1
$args || {}
$args
Truth table0%0/2
A
A= $args
| |||||||||||||||||||||||||||||
| 700 | ); | ||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||
| 703 | 0 | ▶ | sub _shipper_from_address { | ||||||||||||||||||||||||||
|
Subroutine
_shipper_from_address: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 704 | 0 | my ($self,$addr) = @_; | |||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||
| 706 | 0 | require Net::Async::Webservice::UPS::Shipper; | |||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||
| 708 | 0 | ▶ | return Net::Async::Webservice::UPS::Shipper->new({ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 709 | address => $addr, | ||||||||||||||||||||||||||||
| 710 | ( $self->account_number ? ( account_number => $self->account_number ) : () ), | ||||||||||||||||||||||||||||
| 711 | }); | ||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||
| 714 | 0 | ▶ | sub _shipper_from_contact { | ||||||||||||||||||||||||||
|
Subroutine
_shipper_from_contact: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 715 | 0 | my ($self,$contact) = @_; | |||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||
| 717 | 0 | ▶ | return $contact if $contact->isa('Net::Async::Webservice::UPS::Shipper'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||
| 719 | 0 | require Net::Async::Webservice::UPS::Shipper; | |||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||
| 721 | 0 | ▶ | return Net::Async::Webservice::UPS::Shipper->new({ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 722 | %$contact, # ugly! | ||||||||||||||||||||||||||||
| 723 | ( $self->account_number ? ( account_number => $self->account_number ) : () ), | ||||||||||||||||||||||||||||
| 724 | }); | ||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||
| 727 | 5 | 1; | |||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||
| 729 | __END__ | ||||||||||||||||||||||||||||