summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorplobbes <plobbes>2006-11-20 04:57:37 +0000
committerplobbes <plobbes>2006-11-20 04:57:37 +0000
commit6e68659b6390c3987587e0c9fcc772b5618356b3 (patch)
treed788b265a885614f5052d176a3ac862634c7e16b
parent417f1443bc69fd3b5c9bce17cfb618d0c7da486f (diff)
* Add Class data %WrappedSubmitClassMethod to remember "wrapped" submits
* Fix new() to check %WrappedSubmitClassMethod to avoid creating deep recursion * Minor documentation change in print statements use ',' instead of '.'
-rw-r--r--OnlinePayment.pm29
1 files changed, 18 insertions, 11 deletions
diff --git a/OnlinePayment.pm b/OnlinePayment.pm
index 28deb6d..5e764a9 100644
--- a/OnlinePayment.pm
+++ b/OnlinePayment.pm
@@ -10,6 +10,9 @@ require 5.005;
$VERSION = '3.00_04';
$VERSION = eval $VERSION; # modperlstyle: convert the string into a number
+# Remember subclasses we have "wrapped" submit() with _pre_submit()
+my %WrappedSubmitClassMethod = ();
+
my %fields = (
authorization => undef,
error_message => undef,
@@ -27,7 +30,6 @@ my %fields = (
transaction_type => undef,
);
-
sub new {
my($class,$processor,%data) = @_;
@@ -55,15 +57,20 @@ sub new {
}
unless ( $subclass->can('submit') eq $class->can('submit') ) {
- no strict 'refs';
- no warnings 'redefine';
my $submit = qualify_to_ref('submit', $subclass);
- $self->{_child_submit} = \&$submit;
- *{"${subclass}::submit"} = sub {
- my $self = shift;
- $self->_pre_submit();
- }
+ # "wrap" submit ONLY once, cache info for later calls to new()
+ if ( ! exists $WrappedSubmitClassMethod{$subclass} ) {
+ no warnings 'redefine';
+ no strict 'refs';
+
+ $WrappedSubmitClassMethod{$subclass} = \&$submit;
+ *{"${subclass}::submit"} = sub {
+ my $self = shift;
+ $self->_pre_submit();
+ }
+ }
+ $self->{_child_submit} = $WrappedSubmitClassMethod{$subclass};
}
return $self;
@@ -89,7 +96,7 @@ sub _risk_detect {
}
}
-sub _pre_submit{
+sub _pre_submit {
my ($self) = @_;
my $fraud_detection = $self->fraud_detect();
@@ -213,9 +220,9 @@ Business::OnlinePayment - Perl extension for online payment processing
$transaction->submit();
if($transaction->is_success()) {
- print "Card processed successfully: ".$transaction->authorization()."\n";
+ print "Card processed successfully: ", $transaction->authorization(), "\n";
} else {
- print "Card was rejected: ".$transaction->error_message()."\n";
+ print "Card was rejected: ", $transaction->error_message(), "\n";
}
=head1 DESCRIPTION