| 1 | package DBIx::CheckConnectivity; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | use Carp; | ||
| 6 | |||
| 7 | our $VERSION = '0.02'; | ||
| 8 | |||
| 9 | use base 'Exporter'; | ||
| 10 | |||
| 11 | our @EXPORT = qw/check_connectivity/; | ||
| 12 | |||
| 13 | use DBI; | ||
| 14 | use Params::Validate qw/:all/; | ||
| 15 | use UNIVERSAL::require; | ||
| 16 | |||
| 17 | sub check_connectivity { | ||
| 18 | validate( | ||
| 19 | @_, | ||
| 20 | { | ||
| 21 | dsn => { type => SCALAR, regex => qr/^dbi:/ }, | ||
| 22 | user => 0, | ||
| 23 | password => 0, | ||
| 24 | attribute => { type => HASHREF, optional => 1 }, | ||
| 25 | } | ||
| 26 | ); | ||
| 27 | my %args = @_; | ||
| 28 | my $dsn = $args{dsn}; | ||
| 29 | |||
| 30 | my ( $driver ) = $dsn =~ m/dbi:(\w+):/; | ||
| 31 | my $driver_module = __PACKAGE__ . '::Driver::' . $driver; | ||
| 32 | $driver_module->require | ||
| 33 | or confess "$driver is not supported yet, sorry"; | ||
| 34 | $driver_module->check_connectivity( @_ ); | ||
| 35 | |||
| 36 | } | ||
| 37 | |||
| 38 | 1; | ||
| 39 | |||
| 40 | __END__ |