From 81afca64157ecbca5ef6bee0a5310ac733200a7c Mon Sep 17 00:00:00 2001 From: levinse Date: Sat, 27 Nov 2010 02:49:35 +0000 Subject: [PATCH] Change most dies to returns, change debug prints to warns --- lib/Net/Ikano.pm | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/lib/Net/Ikano.pm b/lib/Net/Ikano.pm index acbc6c2..de40912 100644 --- a/lib/Net/Ikano.pm +++ b/lib/Net/Ikano.pm @@ -145,9 +145,9 @@ sub req_ORDER { my @validOrderTypes = qw( NEW CHANGE CANCEL ); - die "invalid order data" unless defined $args->{orderType} + return "invalid order data" unless defined $args->{orderType} && defined $args->{ProductCustomId} && defined $args->{DSLPhoneNumber}; - die "invalid order type ".$args->{orderType} + return "invalid order type ".$args->{orderType} unless grep($_ eq $args->{orderType}, @validOrderTypes); # XXX: rewrite this uglyness? @@ -166,14 +166,14 @@ sub req_ORDER { sub resp_ORDER { my ($self, $resphash, $reqhash) = (shift, shift); - die "invalid order response" unless defined $resphash->{OrderResponse}; + return "invalid order response" unless defined $resphash->{OrderResponse}; return $resphash->{OrderResponse}; } sub req_CANCEL { my ($self, $args) = (shift, shift); - die "no order id for cancel" unless defined $args->{OrderId}; + return "no order id for cancel" unless defined $args->{OrderId}; return Cancel => { OrderId => [ $args->{OrderId} ], @@ -182,14 +182,14 @@ sub req_CANCEL { sub resp_CANCEL { my ($self, $resphash, $reqhash) = (shift, shift); - die "invalid cancel response" unless defined $resphash->{OrderResponse}; + return "invalid cancel response" unless defined $resphash->{OrderResponse}; return $resphash->{OrderResponse}; } sub req_ORDERSTATUS { my ($self, $args) = (shift, shift); - die "ORDERSTATUS is supported by OrderId only" + return "ORDERSTATUS is supported by OrderId only" if defined $args->{PhoneNumber} || !defined $args->{OrderId}; return OrderStatus => { @@ -199,13 +199,13 @@ sub req_ORDERSTATUS { sub resp_ORDERSTATUS { my ($self, $resphash, $reqhash) = (shift, shift); - die "invalid order response" unless defined $resphash->{OrderResponse}; + return "invalid order response" unless defined $resphash->{OrderResponse}; return $resphash->{OrderResponse}; } sub req_ACCOUNTSTATUSCHANGE { my ($self, $args) = (shift, shift); - die "invalid account status change request" unless defined $args->{type} + return "invalid account status change request" unless defined $args->{type} && defined $args->{DSLServiceId} && defined $args->{DSLPhoneNumber}; return AccountStatusChange => { @@ -217,7 +217,7 @@ sub req_ACCOUNTSTATUSCHANGE { sub resp_ACCOUNTSTATUSCHANGE { my ($self, $resphash, $reqhash) = (shift, shift); - die "invalid account status change response" + return "invalid account status change response" unless defined $resphash->{AccountStatusChangeResponse} && defined $resphash->{AccountStatusChangeResponse}->{Customer}; return $resphash->{AccountStatusChangeResponse}->{Customer}; @@ -225,7 +225,7 @@ sub resp_ACCOUNTSTATUSCHANGE { sub req_CUSTOMERLOOKUP { my ($self, $args) = (shift, shift); - die "invalid customer lookup request" unless defined $args->{PhoneNumber}; + return "invalid customer lookup request" unless defined $args->{PhoneNumber}; return CustomerLookup => { PhoneNumber => [ $args->{PhoneNumber} ], }; @@ -233,7 +233,7 @@ sub req_CUSTOMERLOOKUP { sub resp_CUSTOMERLOOKUP { my ($self, $resphash, $reqhash) = (shift, shift); - die "invalid customer lookup response" + return "invalid customer lookup response" unless defined $resphash->{CustomerLookupResponse} && defined $resphash->{CustomerLookupResponse}->{Customer}; return $resphash->{CustomerLookupResponse}->{Customer}; @@ -241,7 +241,7 @@ sub resp_CUSTOMERLOOKUP { sub req_PASSWORDCHANGE { my ($self, $args) = (shift, shift); - die "invalid arguments to PASSWORDCHANGE" + return "invalid arguments to PASSWORDCHANGE" unless defined $args->{DSLPhoneNumber} && defined $args->{NewPassword}; return PasswordChange => { @@ -252,7 +252,8 @@ sub req_PASSWORDCHANGE { sub resp_PASSWORDCHANGE { my ($self, $resphash, $reqhash) = (shift, shift); - die "invalid change password response" unless defined $resphash->{ChangePasswordResponse}; + return "invalid change password response" + unless defined $resphash->{ChangePasswordResponse}; return $resphash->{ChangePasswordResponse}; } @@ -273,7 +274,7 @@ sub req_PREQUAL { sub resp_PREQUAL { my ($self, $resphash, $reqhash) = (shift, shift); - die "invalid prequal response" unless defined $resphash->{PreQualResponse}; + return "invalid prequal response" unless defined $resphash->{PreQualResponse}; return $resphash->{PreQualResponse}; } @@ -309,25 +310,30 @@ sub AUTOLOAD { # XXX: validate against their schema to ensure we're not sending invalid XML? - print "DEBUG REQUEST\n\tHASH:\n ".Dumper($reqhash)."\n\tXML:\n $reqxml \n\n" if $self->{debug}; + warn "DEBUG REQUEST\n\tHASH:\n ".Dumper($reqhash)."\n\tXML:\n $reqxml \n\n" + if $self->{debug}; my $ua = LWP::UserAgent->new; - die "posting disabled for testing" if $self->{reqpreviewonly}; + return "posting disabled for testing" if $self->{reqpreviewonly}; my $resp = $ua->post($URL, Content_Type => 'text/xml', Content => $reqxml); - die $resp->status_line unless $resp->is_success; + return "invalid HTTP response from Ikano: " . $resp->status_line + unless $resp->is_success; my $respxml = $resp->decoded_content; my $resphash = $xs->XMLin($respxml); - print "DEBUG RESPONSE\n\tHASH:\n ".Dumper($resphash)."\n\tXML:\n $respxml" if $self->{debug}; + warn "DEBUG RESPONSE\n\tHASH:\n ".Dumper($resphash)."\n\tXML:\n $respxml" + if $self->{debug}; # XXX: validate against their schema to ensure they didn't send us invalid XML? - die "invalid response" unless defined $resphash->{responseid} - && defined $resphash->{version} && defined $resphash->{type}; + return "invalid response received from Ikano" + unless defined $resphash->{responseid} && defined $resphash->{version} + && defined $resphash->{type}; - die "FAILURE response received: ".$resphash->{FailureResponse}->{FailureMessage} + return "FAILURE response received from Ikano: " + . $resphash->{FailureResponse}->{FailureMessage} if $resphash->{type} eq 'FAILURE'; my $validRespTypes = { @@ -340,7 +346,7 @@ sub AUTOLOAD { 'CUSTOMERLOOKUP' => qw( CUSTOMERLOOKUP ), }; - die "invalid response type for request type" + return "invalid response type ".$resphash->{type}." for request type $cmd" unless grep( $_ eq $resphash->{type}, $validRespTypes->{$cmd}); return $self->$respsub($resphash,$reqhash); -- 2.11.0