CheckConnectivity/Driver.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 47 CC 3 SCAR 17.5
CC
3
Cov
0%
check_connectivity
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.8
1 package DBIx::CheckConnectivity::Driver;
2  
3 use warnings;
4 use strict;
5 use Carp;
6  
7 use DBI;
8 use Params::Validate qw/:all/;
9  
10 sub check_connectivity {
11 my $class = shift;
12 validate(
13 @_,
14 {
15 dsn => { type => SCALAR, regex => qr/^dbi:/ },
16 user => 0,
17 password => 0,
18 attribute => { type => HASHREF, optional => 1 },
19 }
20 );
21 my %args = @_;
22 my $dsn = $args{dsn};
23 my $user = $args{user} || '';
24 my $password = $args{password} || '';
25  
26 my $attribute = $args{attribute} || { RaiseError => 0, PrintError => 0 };
27 my ($database) = $dsn =~ m/dbi:(?:\w+):(?:(?:database|dbname)=)?(\w+)/;
28  
29 my $dbh = DBI->connect( $dsn, $user, $password, $attribute );
30  
31 return 1 if $dbh;
32 # so we have an err
33 return wantarray ? ( undef, DBI::errstr ) : undef;
34 }
35  
36 1;
37  
38 __END__