From: plobbes Date: Mon, 20 Nov 2006 04:57:37 +0000 (+0000) Subject: * Add Class data %WrappedSubmitClassMethod to remember "wrapped" submits X-Git-Tag: BUSINESS_ONLINEPAYMENT_3_00_05~7 X-Git-Url: http://git.freeside.biz/gitweb/?p=Business-OnlinePayment.git;a=commitdiff_plain;h=6e68659b6390c3987587e0c9fcc772b5618356b3 * 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 '.' --- 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