| 1 | package IPC::Manager::Base::DBI; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = '0.000010'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Time::HiRes qw/time/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use File::Temp qw/tempfile/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use parent 'IPC::Manager::Client'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | use Object::HashBase qw{ | |||||||||||||||||||||||||||||||||||||||||
| 16 | +dbh | ||||||||||||||||||||||||||||||||||||||||||
| 17 | <user | ||||||||||||||||||||||||||||||||||||||||||
| 18 | <pass | ||||||||||||||||||||||||||||||||||||||||||
| 19 | <attrs | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub dsn { croak "Not Implemented" } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dsn: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub table_sql { croak "Not Implemented" } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_sql: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub escape { '' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
escape: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 14 | ▶ | sub pending_messages { 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pending_messages: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 14 | ▶ | sub ready_messages { $_[0]->_get_message_ids ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ready_messages: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | sub dbh { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 210 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dbh: called CC=13 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 210 | my (%params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 210 | ▶ | if (blessed($this) && $this->{+DBH}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($this) and $this->{"dbh"}
MC/DC100%2/2
builtin::blessed($this) and $this->{"dbh"}
builtin::blessed($this)
$this->{"dbh"}
Truth table100%3/3
A and B
A= builtin::blessed($this)B= $this->{"dbh"}
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 195 | $this->pid_check; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 195 | ▶ | return $this->{+DBH} if $this->{+DBH}->{Active}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | delete $this->{+DBH}; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 15 | my $dsn = $params{dsn}; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 15 | my $user = $params{user}; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 15 | my $pass = $params{pass}; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 15 | my $attrs = $params{attrs}; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 15 | ▶ | if (blessed($this)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 11 | $this->pid_check; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 11 | ▶ | $dsn //= $this->dsn; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$dsn //= $this->dsn
MC/DC0%0/2
$dsn //= $this->dsn
$dsn
$this->dsn
Truth table33%1/3
A //= B
A= $dsnB= $this->dsn
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 11 | ▶ | $user //= $this->user; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$user //= $this->user
MC/DC0%0/2
$user //= $this->user
$user
$this->user
Truth table33%1/3
A //= B
A= $userB= $this->user
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 11 | ▶ | $pass //= $this->pass; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$pass //= $this->pass
MC/DC0%0/2
$pass //= $this->pass
$pass
$this->pass
Truth table33%1/3
A //= B
A= $passB= $this->pass
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 11 | ▶ | $attrs //= $this->attrs; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$attrs //= $this->attrs
MC/DC0%0/2
$attrs //= $this->attrs
$attrs
$this->attrs
Truth table33%1/3
A //= B
A= $attrsB= $this->attrs
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 15 | ▶ | croak "No DSN" unless $dsn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 15 | ▶ | $attrs //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$attrs //= {}
MC/DC0%0/1
$attrs //= {}
$attrs
Truth table50%1/2
A
A= $attrs
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 15 | ▶ | my $dbh = DBI->connect($dsn, $user, $pass, $attrs) or die "Could not connect"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 15 | ▶ | $this->{+DBH} = $dbh if blessed($this); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 15 | return $dbh; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | sub init_db { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_db: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | my $dbh = $this->dbh(@_); | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | for my $sql ($this->table_sql) { | |||||||||||||||||||||||||||||||||||||||||
| 69 | 8 | local $dbh->{PrintWarn} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 8 | ▶ | $dbh->do($sql) or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | ▶ | sub default_attrs {} | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_attrs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | sub init { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 11 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=15 SCAR=36.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 11 | $self->SUPER::init(); | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 11 | ▶ | $self->{+USER} //= delete $self->{username} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$self->{"user"} //= delete $self->{"username"} // ""
delete $self->{"username"} // ""
MC/DC0%0/2
$self->{"user"} //= delete $self->{"username"} // ""
$self->{"user"}
delete $self->{"username"}
Truth table0%0/3
A //= B
A= $self->{"user"}B= delete $self->{"username"}
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 11 | ▶ | $self->{+PASS} //= delete $self->{password} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$self->{"pass"} //= delete $self->{"password"} // ""
delete $self->{"password"} // ""
MC/DC0%0/2
$self->{"pass"} //= delete $self->{"password"} // ""
$self->{"pass"}
delete $self->{"password"}
Truth table0%0/3
A //= B
A= $self->{"pass"}B= delete $self->{"password"}
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 11 | ▶ | $self->{+ATTRS} //= $self->default_attrs; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"attrs"} //= $self->default_attrs
MC/DC0%0/2
$self->{"attrs"} //= $self->default_attrs
$self->{"attrs"}
$self->default_attrs
Truth table33%1/3
A //= B
A= $self->{"attrs"}B= $self->default_attrs
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 11 | my $id = $self->{+ID}; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 11 | my $row = $self->_get_peer($self->{+ID}); | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 11 | ▶ | croak "The '$id' peer does not exist" if $self->{+RECONNECT} && !$row; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"reconnect"} and not $row
MC/DC0%0/2
$self->{"reconnect"} and not $row
$self->{"reconnect"}
not $row
Truth table33%1/3
A and not(B)
A= $self->{"reconnect"}B= not $row
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | croak "Looks like the connection is already running in pid $row->{pid}" | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 11 | ▶ | if $row && $row->{pid} && $self->pid_is_running($row->{pid}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$row and $row->{"pid"} and $self->pid_is_running($row->{"pid"})
$row and $row->{"pid"}
MC/DC0%0/3
$row and $row->{"pid"} and $self->pid_is_running($row->{"pid"})
$row
$row->{"pid"}
$self->pid_is_running($row->{"pid"})
Truth table25%1/4
A and B and C
A= $rowB= $row->{"pid"}C= $self->pid_is_running($row->{"pid"})
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 11 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 11 | my $e = $self->escape; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 11 | ▶ | if ($row) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $sth = $dbh->prepare("UPDATE ipcm_peers SET ${e}active${e} = ?, ${e}pid${e} = ? WHERE ${e}id${e} = ?"); | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $sth->execute(time, $self->{+PID}, $self->{+ID}) or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 11 | ▶ | my $sth = $dbh->prepare("INSERT INTO ipcm_peers(${e}id${e}, ${e}pid${e}, ${e}active${e}) VALUES (?, ?, ?)") or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 11 | ▶ | $sth->execute($id, $self->{+PID}, time) or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | sub all_stats { | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all_stats: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | my $out = {}; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | my $e = $self->escape; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | ▶ | my $sth = $dbh->prepare("SELECT ${e}id${e}, ${e}stats${e} FROM ipcm_peers") or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | ▶ | $sth->execute() or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | ▶ | while (my $row = $sth->fetchrow_arrayref) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 8 | $out->{$row->[0]} = $self->{+SERIALIZER}->deserialize($row->[1]); | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | sub write_stats { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 16 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_stats: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 16 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 16 | my $e = $self->escape; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 16 | ▶ | my $sth = $dbh->prepare("UPDATE ipcm_peers SET ${e}stats${e} = ? WHERE ${e}id${e} = ?") or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 16 | ▶ | $sth->execute($self->{+SERIALIZER}->serialize($self->{+STATS}), $self->{+ID}) or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | sub read_stats { | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_stats: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 6 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 6 | my $e = $self->escape; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 6 | ▶ | my $sth = $dbh->prepare("SELECT ${e}stats${e} FROM ipcm_peers WHERE ${e}id${e} = ?") or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | ▶ | $sth->execute($self->{+ID}) or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 6 | ▶ | my $row = $sth->fetchrow_arrayref or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 6 | return $self->{+SERIALIZER}->deserialize($row->[0]); | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | sub peers { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 21 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
peers: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 21 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 21 | my $e = $self->escape; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 21 | ▶ | my $sth = $dbh->prepare("SELECT ${e}id${e} FROM ipcm_peers WHERE ${e}id${e} != ? AND active IS NOT NULL ORDER BY ${e}id${e} ASC") or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 21 | $sth->execute($self->{+ID}); | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 21 | return map { $_->[0] } @{$sth->fetchall_arrayref([0])}; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | sub peer_pid { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 13 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
peer_pid: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 13 | my ($id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 13 | ▶ | my $row = $self->_get_peer($id) or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 12 | ▶ | return $row->{pid} // undef if $row->{active}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$row->{"pid"} // undef
MC/DC0%0/1
$row->{"pid"} // undef
$row->{"pid"}
Truth table50%1/2
A
A= $row->{"pid"}
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | sub peer_exists { | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
peer_exists: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | my ($id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | ▶ | return $self->_get_peer($id) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | sub _get_peer { | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 25 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_peer: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 25 | my ($id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 25 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 25 | my $e = $self->escape; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 25 | ▶ | my $sth = $dbh->prepare("SELECT * FROM ipcm_peers WHERE ${e}id${e} = ?") or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 25 | $sth->execute($id); | |||||||||||||||||||||||||||||||||||||||||
| 180 | 25 | return $sth->fetchrow_hashref; | |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | sub send_message { | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 29 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_message: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 29 | my $msg = $self->build_message(@_); | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 29 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 29 | my $e = $self->escape; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 29 | ▶ | my $sth = $dbh->prepare("INSERT INTO ipcm_messages(${e}id${e}, ${e}from${e}, ${e}to${e}, ${e}stamp${e}, ${e}broadcast${e}, ${e}content${e}) VALUES (?, ?, ?, ?, ?, ?)") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | $sth->execute( | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 29 | ▶ | @{$msg}{qw/id from to stamp/}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | ($msg->{broadcast} ? 1 : 0), | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 29 | ▶ | $self->{+SERIALIZER}->serialize($msg->{content}), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | ) or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 29 | $self->{+STATS}->{sent}->{$msg->{to}}++; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | sub _get_message_ids { | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 50 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_message_ids: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 50 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 50 | my $e = $self->escape; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 50 | ▶ | my $sth = $dbh->prepare("SELECT ${e}id${e} FROM ipcm_messages WHERE ${e}to${e} = ? ORDER BY ${e}stamp${e} ASC") or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 50 | ▶ | $sth->execute($self->{+ID}) or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 50 | my $ids = [map { $_->[0] } @{$sth->fetchall_arrayref([0])}]; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 50 | ▶ | return $ids if $ids && @$ids; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ids and @$ids
MC/DC50%1/2
$ids and @$ids
$ids
@$ids
Truth table66%2/3
A and B
A= $idsB= @$ids
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 21 | return; | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | sub get_messages { | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 36 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_messages: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 36 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 36 | ▶ | my $ids = $self->_get_message_ids or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 23 | my $e = $self->escape; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 23 | my $where = "FROM ipcm_messages WHERE ${e}id${e} IN (" . join(', ' => map { '?' } 1 .. scalar(@$ids)) . ")"; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 23 | ▶ | my $sth = $dbh->prepare("SELECT * $where") or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 23 | ▶ | $sth->execute(@$ids) or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 23 | my $rows = $sth->fetchall_arrayref({}); | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 23 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 23 | for my $row (@$rows) { | |||||||||||||||||||||||||||||||||||||||||
| 227 | 29 | $row->{content} = $self->{+SERIALIZER}->deserialize($row->{content}); | |||||||||||||||||||||||||||||||||||||||||
| 228 | 29 | $self->{+STATS}->{read}->{$row->{from}}++; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 29 | push @out => IPC::Manager::Message->new($row); | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 23 | ▶ | $sth = $dbh->prepare("DELETE $where") or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 23 | ▶ | $sth->execute(@$ids) or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 23 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | sub requeue_message { | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
requeue_message: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $self->send_message($_) for @_; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | sub pre_disconnect_hook { | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pre_disconnect_hook: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 10 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 10 | my $e = $self->escape; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 10 | ▶ | my $sth = $dbh->prepare("UPDATE ipcm_peers SET ${e}pid${e} = NULL, active = NULL WHERE ${e}id${e} = ?") or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 10 | ▶ | $sth->execute($self->{+ID}) or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | sub pre_suspend_hook { | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pre_suspend_hook: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my $e = $self->escape; | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | my $sth = $dbh->prepare("UPDATE ipcm_peers SET ${e}pid${e} = NULL WHERE ${e}id${e} = ?") or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | $sth->execute($self->{+ID}) or die $dbh->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | __END__ | ||||||||||||||||||||||||||||||||||||||||||