Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Business::OnlinePayment redefined subroutines, or the little module that doesn't like being used twice

by JPaul (Hermit)
on Oct 03, 2002 at 18:18 UTC ( #202601=perlquestion: print w/replies, xml ) Need Help??

JPaul has asked for the wisdom of the Perl Monks concerning the following question:

Greetings all,
I've recently become involved in a project that requires me use Authorize.Net's payment gateway to process credit cards. Being a good little perler I used the modules that already exist to talk with AuthNet, Business::OnlinePayment and Business::OnlinePayment::AuthorizeNet.
Unfortunately I've discovered an issue that, while not causing the module to die, gives me a bunch of redefine errors that I'm sure shouldn't be.

The code snippet below is missing a bunch of the information you're supposed to pass through, but its not relevant for our immediate purposes.

my $tx = new Business::OnlinePayment("AuthorizeNet"); $tx->content( type => $cardtype, login => $login, password => $pass, amount => $amount, card_number => $ccnum, expiration => $ccexp); $tx->submit(); if($tx->is_success()) { &do_something; } else { &another; } $tx = new Business::OnlinePayment("AuthorizeNet"); $tx->content( type => $cardtype, login => $login, password => $pass, amount => $amount, card_number => $ccnum, expiration => $ccexp); $tx->submit if($tx->is_success()) { &do_something; } else { &another; }
This code is, of course, contrived, and only for demonstration purposes. My actual code has a single instance stored in a subroutine which I call to and pass along the transaction details.
When example is run I get a lovely stack of errors for the second transaction like:
Subroutine server_response redefined at (eval 19) line 1. Subroutine path redefined at (eval 20) line 1. Subroutine require_avs redefined at (eval 21) line 1. Subroutine port redefined at (eval 22) line 1.
Plus a number more I didn't want to spam you all with.

While these errors aren't fatal, I know it shouldn't doing this... Can anyone enlighten me what I can do to the module to "fix" this... Or whether its safe to simply ignore them...

My thanks,
JP
-- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

  • Comment on Business::OnlinePayment redefined subroutines, or the little module that doesn't like being used twice
  • Select or Download Code

Replies are listed 'Best First'.
Re: Business::OnlinePayment redefined subroutines, or the little module that doesn't like being used twice
by perrin (Chancellor) on Oct 03, 2002 at 19:38 UTC
    These look like constant subs being redefined. I think that problem was fixed in later versions of Perl. It shouldn't cause a problem.

    UPDATE: I just looked at the code and I see the problem. Business::OnlinePayment defines some subs using a routine called "build_subs", but doesn't check to see if they have been defined first. It shouldn't do that. Looks like it expected to run in a CGI environment and not be instantiated twice. This won't cause problems, but it will cause warnings. It would be easy to fix, by making minor changes to the new() sub in Business::OnlinePayment.

Re: Business::OnlinePayment redefined subroutines, or the little module that doesn't like being used twice
by derby (Abbot) on Oct 04, 2002 at 00:35 UTC
    perrin is of course right with the redefinition in build_subs. I came across this same issue not quite long and emailed the maintainer. Ivan's not inclined to patch the current release because he'd rather redo the whole thing. If you're interested in this worthy effort, check out his efforts.

    -derby

Re: Business::OnlinePayment redefined subroutines, or the little module that doesn't like being used twice
by JPaul (Hermit) on Oct 04, 2002 at 02:29 UTC
    My thanks Perrin and Derby,
    I appreciate you bothering to look into this on my account, I'm annoyed I didn't look further and spot it myself.
    My fix is simply the below, inside the &build_subs() loop:
    next if exists &$_;
    It appears to work, so I'm hoping this is the correct course of action.

    Thanks again Monks,
    JP

    -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://202601]
Approved by ybiC
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2023-05-31 03:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?