| 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
Condition20%1/5
@params == 1 and (ref $params[0] || "") eq "HASH"
ref $params[0] || ''
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]
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$dbh ||= $self->{"dbh"}
MC/DC50%1/2
$dbh ||= $self->{"dbh"}
$dbh
$self->{"dbh"}
Truth table66%2/3
A ||= B
A= $dbhB= $self->{"dbh"}
| |||||||||||||||||||||||||||||||||
| 32 | 9 | ▶ | $dbh = $dbh->(%params) if ref $dbh eq 'CODE'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 9 | ▶ | croak("Valid 'dbh' is required") unless $dbh and do { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$dbh and do {
local $@;
local $SIG{"__DIE__"};
eval {
do {
$dbh->can("ping")
}
}
}
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")
}
}
}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 48 | 4 | ▶ | my $successful = $status eq "OK" ? "Successful" : "Unsuccessful"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 4 | return { status => $status, info => $info }; | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 2 | 1; | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | __END__ | ||||||||||||||||||||||||||||||||