File Coverage

blib/lib/DBIx/CheckConnectivity/Driver.pm
Criterion Covered Total %
statement 26 26 100.0
branch 4 4 100.0
condition 4 6 66.6
subroutine 6 6 100.0
pod 1 1 100.0
total 41 43 95.3


line stmt bran cond sub pod time code
1             package DBIx::CheckConnectivity::Driver;
2              
3 2     2   2090 use warnings;
  2         6  
  2         145  
4 2     2   11 use strict;
  2         3  
  2         205  
5 2     2   11 use Carp;
  2         4  
  2         150  
6              
7 2     2   95 use DBI;
  2         4  
  2         94  
8 2     2   11 use Params::Validate qw/:all/;
  2         4  
  2         1310  
9              
10             sub check_connectivity {
11 10     10 1 17 my $class = shift;
12 10         187 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 10         199 my %args = @_;
22 10         23 my $dsn = $args{dsn};
23 10   50     42 my $user = $args{user} || '';
24 10   100     38 my $password = $args{password} || '';
25              
26 10   50     53 my $attribute = $args{attribute} || { RaiseError => 0, PrintError => 0 };
27 10         62 my ($database) = $dsn =~ m/dbi:(?:\w+):(?:(?:database|dbname)=)?(\w+)/;
28              
29 10         38 my $dbh = DBI->connect( $dsn, $user, $password, $attribute );
30              
31 10 100       5942 return 1 if $dbh;
32             # so we have an err
33 6 100       48 return wantarray ? ( undef, DBI::errstr ) : undef;
34             }
35              
36             1;
37              
38             __END__