Friday, January 12, 2007

Net::UPS Patch

Perl is such a great environment because when you need to do something like develop an interface to the UPS XML services, and you start mucking around with LWP and wonder why their service doesn't expect POST to have key=>value pairs, you suddenly realize someone has written Net::UPS and the problem has already been solved.

The 0.4 version of Net::UPS, however, doesn't deal with the new "your prices may vary" warning UPS attaches to every query as a warning. The following simple patch, similar but somewhat simpler and more general, than one already submitted to the module's author, works to remedy the situation:

--- /usr/local/lib/perl5/site_perl/5.8.8/Net/UPS.orig Fri Jan 12 20:56:28 2007
+++ /usr/local/lib/perl5/site_perl/5.8.8/Net/UPS.pm Fri Jan 12 20:54:10 2007
@@ -307,7 +307,10 @@
KeyAttr => [],
ForceArray => ['RatedPackage', 'RatedShipment']);
if ( my $error = $response->{Response}->{Error} ) {
- return $self->set_error( $error->{ErrorDescription} );
+ $self->set_error( $error->{ErrorDescription} );
+ if ( $error->{ErrorSeverity} eq 'Hard' ) {
+ return $self->set_error( $error->{ErrorDescription} );
+ }
}
my @services;
for (my $i=0; $i < @{$response->{RatedShipment}}; $i++ ) {

No comments: