blib/lib/HealthCheck/Diagnostic/DBHPing.pm

filter: Statementstmt 97.6% 42 / 43 Branchbran 92.8% 13 / 14 Conditioncond 54.5% 6 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 88.3% 76 / 86 CC 12 SCAR 14.4
CC
12
Cov
90%
new
6.6
check
6.0
run
4.0
CRAP 4.2
↑ Summary
1 package HealthCheck::Diagnostic::DBHPing;
2  
3 # ABSTRACT: Ping a database handle to check its health
4 2 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 our $VERSION = 'v1.2.5'; # VERSION
6  
7 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use parent 'HealthCheck::Diagnostic';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 ▶sub new {
Subroutine new: called CC=4 SCAR=18.9
Pod documented
15 4 my ($class, @params) = @_;
16  
17 # Allow either a hashref or even-sized list of params
18 my %params = @params == 1 && ( ref $params[0] || '' ) eq 'HASH'
19 0 ▶ ? %{ $params[0] } : @params;
Branch: 1 branch
BranchTrueFalseTotal
@params == 1 && (ref $params[0] || '') eq 'HASH' ? : 0 4 4
Condition20%1/5
@params == 1 and (ref $params[0] || "") eq "HASH"
!ll&&!rl&&r
400
ref $params[0] || ''
l!l
00
MC/DC0%0/2
@params == 1 and (ref $params[0] || "") eq "HASH"
@params == 1 ref $params[0]
Truth table33%1/3
A and B
A= @params == 1B= ref $params[0]
ABresult
0X0
100
111
20  
21 4 return $class->SUPER::new(
22 label => 'dbh_ping',
23 %params
24 );
25 }
26  
27 9 ▶sub check {
Subroutine check: called CC=6 SCAR=17.9
Pod documented
28 9 my ( $self, %params ) = @_;
29  
30 9 my $dbh = $params{dbh};
31 9 ▶ $dbh ||= $self->{dbh} if ref $self;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 4 5 9
Condition66%2/3
$dbh ||= $self->{"dbh"}
l!l&&r!l&&!r
031
MC/DC50%1/2
$dbh ||= $self->{"dbh"}
$dbh $self->{"dbh"}
Truth table66%2/3
A ||= B
A= $dbhB= $self->{"dbh"}
ABresult
1X1
011
000
32 9 ▶ $dbh = $dbh->(%params) if ref $dbh eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $dbh eq "CODE" 3 6 9
33  
34 9 ▶ croak("Valid 'dbh' is required") unless $dbh and do {
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh and do { local $@; local $SIG{"__DIE__"}; eval { do { $dbh->can("ping") } } } 5 4 9
Condition100%3/3
$dbh and do { local $@; local $SIG{"__DIE__"}; eval { do { $dbh->can("ping") } } }
!ll&&!rl&&r
324
MC/DC100%2/2
$dbh and do { local $@; local $SIG{"__DIE__"}; eval { do { $dbh->can("ping") } } }
$dbh do { local $@; local $SIG{"__DIE__"}; eval { do { $dbh->can("ping") } } }
Truth table100%3/3
A and B
A= $dbhB= do { local $@; local $SIG{"__DIE__"}; eval { do { $dbh->can("ping") } } }
ABresult
0X0
100
111
35 6 local $@; local $SIG{__DIE__}; eval { $dbh->can('ping') } };
36  
37 4 my $res = $self->SUPER::check( %params, dbh => $dbh );
38 4 delete $res->{dbh}; # don't include the object in the result
39  
40 4 return $res;
41 }
42  
43 4 ▶sub run {
Subroutine run: called CC=4 SCAR=13.9
Pod documented
44 4 my ( $self, %params ) = @_;
45 4 my $dbh = $params{dbh};
46  
47 4 ▶ my $status = $dbh->ping ? "OK" : "CRITICAL";
Branch: 1 branch
BranchTrueFalseTotal
$dbh->ping ? : 2 2 4
48 4 ▶ my $successful = $status eq "OK" ? "Successful" : "Unsuccessful";
Branch: 1 branch
BranchTrueFalseTotal
$status eq 'OK' ? : 2 2 4
49  
50 4 my $driver = $dbh->{Driver}->{Name};
51 4 my $info = "$successful $driver ping of $dbh->{Name}";
52 4 ▶ $info .= " as $dbh->{Username}" if $dbh->{Username};
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->{"Username"} 2 2 4
53  
54 4 return { status => $status, info => $info };
55 }
56  
57 2 1;
58  
59 __END__
↑ Summary