Howdy list!
Within a module function that can be exported I use a function, say header() from CGI.
IN that module I have to have
use CGI qw(header);
OK super.
What about if I have a function I export that uses a function from say, the DBI
module, and the
first argument sent to it is the Data Base Handle Variable like so:
Script:
use DBI;
use MyFunkyModule qw(databasestuff);
my $dbh DBI->connect.....
print databasestuff($dbh,$query);
MyFunkyModule.pm:
sub databasestuff {
my $dbh = shift;
my $query = shift;
return $dbh->do($query);
}
(I realize that in this case I might As well just do do() but it's just an example to
illustrate the idea)
Would I still have to have use DBI; in the package MyFunkyModule; in MyFunkyModule.pm?
Basically I'd like to export functions that use uncommon modules.
I'd like those functions to fail with an error if they don't have them installed or
give they are given a bad object, IE like if $dbh was a simple string in my example
above..
I supposed I could do and eval on the module inside the function:
sub databasestuff {
eval { use DBI; };
die "You need DBI installed to use this function $@" if($@);
my $dbh = shift;
my $query = shift;
return $dbh->do($query);
}
(Yes I know DBI is a standard module, I'm just using it as an example since most
people know how to use it)
But if the just sending $dbh part of the object would work so I wouldn't have to use()
it in MyFunkyModule.pm that'd be great.
Make sense?
TIA
Dan
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]