On Mon, Jul 21, 2003 at 02:38:39PM -0400, Jonathan I. Nori wrote:Well, available_drivers() lists drivers whose files are available, but doesn't actually show which drivers are installed. For example, if someone mistakenly just copies files into an install directory without doing a full install, those files will show in the available_drivers list even though the module isn't installed. Try putting an empty Oracle.pm in your DBD directory and available_dirvers() will show the Oracle driver as installed. It can't really be any other way since the method would have to actually require each driver to see if it was installed and most people won't want all drivers required into their programs :-)
Is there any way for me to find out rather easily which
DBI/DBD Perl modules are installed on their servers?
According to the DBI documentation, DBI->available_drivers does what you want.
The sub below does require all drivers and checks to see which DBDs actually run and lists their versions as well as reporting about the OS, Perl version and the status of DBI::PurePerl (to warn if Perl itself hasn't been fully installed). If called in array context, it returns the list just like available_drivers() does but only for drivers that are installed. In scalar context it returns a hash of driver names and version numbers like so:
DBD::ExampleP : 11.10
DBD::ODBC : 1.02
DBD::Pg : 1.21
DBI : 1.37
OS : cygwin
Perl : 5.006001# start
my $version = installed_versions();
for my $mod(sort keys %$version ) {
printf "%20s : %s\n", $mod, $version->{$mod};
}
my @installed_drivers = installed_versions();
print "@installed_drivers";sub installed_versions {
my %version;
eval {
$ENV{DBI_PUREPERL}=1;
require DBI;
};
die $@ if $@;
if ($DBI::PurePerl) {
my $shut_up_warnings = $DBI::PurePerl;
$version{"DBI::PurePerl"} = $DBI::VERSION;
$version{DBI} = 'NOT installed';
}
else {
$version{DBI} = $DBI::VERSION;
}
for my $driver(DBI->available_drivers) {
eval {
require "DBD/$driver.pm";
};
next if $@;
my $vers = ${"DBD::$driver" . '::VERSION'};
$version{"DBD::$driver"} = $vers if $vers;
}
if (wantarray) {
delete $version{DBI};
my @mods = map {s/DBD:://;$_} sort keys %version;
return @mods;
}
$version{OS} = $^O;
$version{Perl} = $];
return \%version;
}
#endEnjoy!
-- Jeff
