Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^3: Using Modules

by Anonymous Monk
on Oct 21, 2007 at 04:23 UTC ( #646234=note: print w/replies, xml ) Need Help??

in reply to Re^2: Using Modules
in thread Using Modules

Ok, I did find something that works, partly...

UNIVERSAL::require, did work partly
Here is how I did it:
use UNIVERSAL::require; my $module = 'MA::' . $_madType; $module->require; my $_cardCharged = $module->chargeCard($_mad_merid);
That does run that subroutine, chargeCard.

The problem is that it runs it before anything and everything, so even my $dbh database connection is not set, so I get errors like this:
Can't call method "prepare" on an undefined value at /path/to/modules/ +MA/ line 18.
so I know it is like it is making my module execute before EVERYTHING else.

Is there a way to make this work, where it executes it right where it is at, so that the rest of my code will work with those in there?

I don't usually use my own modules, normally I do everything locally. Am I allowed to use variables I have in my main perl program in modules? Or am I supposed to import them all in, some way?

Thank you all very much for any advice you can be.


Replies are listed 'Best First'.
Re^4: Using Modules
by powerhouse (Friar) on Oct 21, 2007 at 21:00 UTC
    I figured it out...

    I'm not going to use them as modules... Since I have to build the gateway subroutine named chargeCard, I would just name it the name of the file + chargeCard, then when I pull the gateway to use out of the database, I'll call that subroutine that way:
    my ($_merid,$_mertype) = $dbh->selectrow_array(qq{SELECT `id`,`type` F +ROM `merchants` WHERE #SomeWhereStatement#}); require "/path/to/modules/$_mertype.conf"; my $_subvar = $_mertype . "chargeCard"; my $cardCharged = &$_subvar($_merid);
    and that does work... so now all I have to do is when I program each gateway, I just have to add it to the database first, figure out what type I made it then add that type to the forefront of the chargeCard subroutine name. And that will make them all dynamic, where I can use more than one at the same time... in case one gateway declines the transaction for some dumb reason other than no funds available.

    Just thought I'd update this so people do not have to waste their time reading and trying to help me.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://646234]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2019-08-24 20:34 GMT
Find Nodes?
    Voting Booth?

    No recent polls found