On Thu, Aug 02, 2001 at 09:44:00AM -0400, [EMAIL PROTECTED] wrote:
> Can I test for the existence of a method without actually calling it?
Yes, see my first question, and the solution to the problem.
> Basically what I'm trying to do is to verify that $dbh is still a valid
> handle.
This sounds something like an XY problem; you have a problem, X, and think Y
will solve it. See the discussion below on what you mean by "valid".
> I want to use this as an assertion test at the start of a function.
>
> # verify that the $dbh is valid
> if ( !defined($dbh->disconnect() ) )
> {
> print "dbh is invalid\n" ;
> exit 1
> }
>
> # $dbh is valid so we can safely disconnect
> $dbh->disconnect()
What do you mean by "valid"?
Are you trying to verify $dbh is an object that has a disconnect() method in
its class?
if (ref($dbh) && UNIVERSAL::can($dbh, "disconnect")) {
# $dbh is an object with a disconnect() method
}
Are you trying to verify $dbh is a DBI object? This is difficult, you'd
probably have to check a few methods to make sure it looks like a DBI
object, and then assume it is. The problem is DBI objects aren't blessed
into the DBI class, nor are they subclasses of DBI, so it makes it difficult
to check with, say, UNIVERSAL::isa.
Are you trying to verify $dbh is still connected to the database? Use
$dbh->ping.
Why are you putting a disconnect call at the beginning of a function being
passed a database handle?
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]