Mailing List Archive

[interchange/gateway_log: 9/11] GatewayLog module improvements
commit c5f8ad059f25ba1cc1635abeb533c5423246b353
Author: Mark Johnson <mark@endpoint.com>
Date: Tue Jan 7 22:11:27 2014 -0500

GatewayLog module improvements

* Switch hash tests from ref() to UNIVSERAL::isa() to keep
blessed hashes from producing false negatives.

* Move major failure log writes from debug to global error.

* Modified DESTROY to call log_it() via eval {} to quiet
any impact of a failed call on parent code and ensure that
any unexpected failure is logged to the global error log.

lib/Vend/Payment/GatewayLog.pm | 29 ++++++++++++++++++++---------
1 files changed, 20 insertions(+), 9 deletions(-)
---
diff --git a/lib/Vend/Payment/GatewayLog.pm b/lib/Vend/Payment/GatewayLog.pm
index 4ae80e3..6bb9081 100644
--- a/lib/Vend/Payment/GatewayLog.pm
+++ b/lib/Vend/Payment/GatewayLog.pm
@@ -25,7 +25,7 @@ sub init {
my $host = `hostname -s`;
chomp ($self->{_source} = $host);
}
-
+
return 1;
}

@@ -73,7 +73,7 @@ sub request {
my $request = shift;
return $self->{__request}
unless $request;
- unless (ref ($request) eq 'HASH') {
+ unless (UNIVERSAL::isa($request, 'HASH')) {
::logDebug(
'Skipping non-HASH request set: received %s (unevals to %s)',
$request,
@@ -91,7 +91,7 @@ sub response {
my $response = shift;
return $self->{__response}
unless $response;
- unless (ref ($response) eq 'HASH') {
+ unless (UNIVERSAL::isa($response, 'HASH')) {
::logDebug(
'Skipping non-HASH response set: received %s (unevals to %s)',
$response,
@@ -135,7 +135,7 @@ sub write {

if ($@) {
my $err = $@;
- ::logDebug(
+ ::logGlobal(
q{Couldn't write to %s: %s -- request: %s -- response: %s},
$self->table,
$err,
@@ -152,22 +152,33 @@ sub write {
}

sub table {
- return shift()->{_log_table};
+ return shift->{_log_table};
}

sub _enabled {
- return shift()->{_enabled};
+ return shift->{_enabled};
}

sub source {
- return shift()->{_source};
+ return shift->{_source};
}

sub DESTROY {
my $self = shift;
+
return 1 unless $self->_enabled;
-#::logDebug('Logging request to database in destructor');
- $self->log_it;
+
+ # Unexpected order of operations causes any evals
+ # within DESTROY to execute after any eval that may
+ # contain the DESTROYed object. Effect is that $@ upon
+ # exit of the containing eval is *not* controlled by
+ # that eval. Localization contains the effect.
+ local $@;
+
+ eval { $self->log_it };
+ ::logGlobal("log_it eval died: $@")
+ if $@;
+
1;
}


_______________________________________________
interchange-cvs mailing list
interchange-cvs@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-cvs