Subject: | "subroutine redefined" warnings in B::OP |
Repeated "subroutine redefined at eval..." warnings appear when more than one Business::OnlinePayment object is created in a single program execution.
Here is an example that demonstrates the problem:
$ perl -MBusiness::OnlinePayment -we 'for( 1..2 ) { \
my $tx= Business::OnlinePayment->new('AuthorizeNet'); } '
Subroutine require_avs redefined at (eval 19) line 1.
Subroutine path redefined at (eval 20) line 1.
Subroutine port redefined at (eval 21) line 1.
Subroutine authorization redefined at (eval 22) line 1.
Subroutine is_success redefined at (eval 23) line 1.
Subroutine result_code redefined at (eval 24) line 1.
Subroutine error_message redefined at (eval 25) line 1.
Subroutine server_response redefined at (eval 26) line 1.
Subroutine server redefined at (eval 27) line 1.
Subroutine transaction_type redefined at (eval 28) line 1.
Subroutine test_transaction redefined at (eval 29) line 1.
Subroutine order_number redefined at (eval 30) line 1.
Subroutine md5 redefined at (eval 31) line 1.
Subroutine avs_code redefined at (eval 32) line 1.
I believe the problem is that the build_subs() routine, which
is called from the new() constructor (and possibly a subclass
set_defaults() method), does not test to see if the supplied
subroutine names have already been defined.
Attached is a patch to address this problem.
System info:
Business::OnlinePayment 2.01
Linux localhost 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux (Red Hat 9)
This is perl, v5.8.0 built for i386-linux-thread-multi
diff -ur Business-OnlinePayment-2.01.orig/OnlinePayment.pm Business-OnlinePayment-2.01/OnlinePayment.pm
--- Business-OnlinePayment-2.01.orig/OnlinePayment.pm 2004-07-03 18:18:28.000000000 -0400
+++ Business-OnlinePayment-2.01/OnlinePayment.pm 2004-07-27 14:05:41.000000000 -0400
@@ -118,6 +118,7 @@
sub build_subs {
my $self = shift;
foreach(@_) {
+ next if $self->can($_);
eval "sub $_ { my \$self = shift; if(\@_) { \$self->{$_} = shift; } return \$self->{$_}; }";
}
}