| 1 | package Job::Machine::DB; | ||||||||||||||||||||||||||||
| 2 | 2 | $Job::Machine::DB::VERSION = '0.25'; | |||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp qw/croak confess/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use DBI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Data::Serializer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use constant QUEUE_PREFIX => 'jm:'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use constant RESPONSE_PREFIX => 'jmr:'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub new { | ||||||||||||||||||||||||||||
| 14 | 0 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | croak "No connect information" unless $args{dbh} or $args{dsn}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"dbh"} or $args{"dsn"}
MC/DC0%0/2
$args{"dbh"} or $args{"dsn"}
$args{"dbh"}
$args{"dsn"}
Truth table0%0/3
A or B
A= $args{"dbh"}B= $args{"dsn"}
| |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | croak "invalid queue" if ref $args{queue} and ref $args{queue} ne 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $args{"queue"} and ref $args{"queue"} ne "ARRAY"
MC/DC0%0/2
ref $args{"queue"} and ref $args{"queue"} ne "ARRAY"
ref $args{"queue"}
ref $args{"queue"} ne "ARRAY"
Truth table0%0/3
A and B
A= ref $args{"queue"}B= ref $args{"queue"} ne "ARRAY"
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | $args{dbh_inherited} = 1 if $args{dbh}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | $args{user} ||= undef; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"user"} ||= undef
MC/DC0%0/1
$args{"user"} ||= undef
$args{"user"}
Truth table0%0/2
A
A= $args{"user"}
| |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | $args{password} ||= undef; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"password"} ||= undef
MC/DC0%0/1
$args{"password"} ||= undef
$args{"password"}
Truth table0%0/2
A
A= $args{"password"}
| |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $args{db_attr} ||= undef; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"db_attr"} ||= undef
MC/DC0%0/1
$args{"db_attr"} ||= undef
$args{"db_attr"}
Truth table0%0/2
A
A= $args{"db_attr"}
| |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | $args{dbh} ||= DBI->connect($args{dsn},$args{user},$args{password},$args{db_attr}); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{"dbh"} ||= "DBI"->connect($args{"dsn"}, $args{"user"}, $args{"password"}, $args{"db_attr"})
MC/DC0%0/2
$args{"dbh"} ||= "DBI"->connect($args{"dsn"}, $args{"user"}, $args{"password"}, $args{"db_attr"})
$args{"dbh"}
"DBI"->connect($args{"dsn"}, $args{"user"}, $args{"password"}, $args{"db_attr"})
Truth table0%0/3
A ||= B
A= $args{"dbh"}B= "DBI"->connect($args{"dsn"}, $args{"user"}, $args{"password"}, $args{"db_attr"})
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $args{database_schema} ||= 'jobmachine'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"database_schema"} ||= "jobmachine"
MC/DC0%0/1
$args{"database_schema"} ||= "jobmachine"
$args{"database_schema"}
Truth table0%0/2
A
A= $args{"database_schema"}
| |||||||||||||||||||||||||||||
| 24 | 0 | return bless \%args, $class; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub serializer { | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
serializer: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $args = $self->{serializer_args} || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'serializer_args'} || {}
MC/DC0%0/1
$self->{'serializer_args'} || {}
$self->{'serializer_args'}
Truth table0%0/2
A
A= $self->{'serializer_args'}
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $args->{serializer} ||= $self->{serializer} || 'Sereal'; | ||||||||||||||||||||||||||
|
Condition0%0/5
$args->{"serializer"} ||= $self->{"serializer"} || "Sereal"
$self->{'serializer'} || 'Sereal'
MC/DC0%0/2
$args->{"serializer"} ||= $self->{"serializer"} || "Sereal"
$args->{"serializer"}
$self->{'serializer'}
Truth table0%0/3
A ||= B
A= $args->{"serializer"}B= $self->{'serializer'}
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | return $self->{serialize} ||= Data::Serializer->new(%$args); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"serialize"} ||= "Data::Serializer"->new(%$args)
MC/DC0%0/2
$self->{"serialize"} ||= "Data::Serializer"->new(%$args)
$self->{"serialize"}
"Data::Serializer"->new(%$args)
Truth table0%0/3
A ||= B
A= $self->{"serialize"}B= "Data::Serializer"->new(%$args)
| |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub listen { | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
listen: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | my $queue = $args{queue} || return undef; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{'queue'} || (return undef)
MC/DC0%0/1
$args{'queue'} || (return undef)
$args{'queue'}
Truth table0%0/2
A
A= $args{'queue'}
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $prefix = $args{reply} ? RESPONSE_PREFIX : QUEUE_PREFIX; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | for my $q (ref $queue ? @$queue : ($queue)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | $self->{dbh}->do(qq{listen "$prefix$q";}); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub unlisten { | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
unlisten: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $queue = $args{queue} || return undef; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{'queue'} || (return undef)
MC/DC0%0/1
$args{'queue'} || (return undef)
$args{'queue'}
Truth table0%0/2
A
A= $args{'queue'}
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $prefix = $args{reply} ? RESPONSE_PREFIX : QUEUE_PREFIX; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | for my $q (ref $queue ? @$queue : ($queue)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | $self->{dbh}->do(qq{unlisten "$prefix$q";}); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub notify { | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
notify: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $queue = $args{queue} || return undef; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{'queue'} || (return undef)
MC/DC0%0/1
$args{'queue'} || (return undef)
$args{'queue'}
Truth table0%0/2
A
A= $args{'queue'}
| |||||||||||||||||||||||||||||
| 61 | 0 | my $payload = $args{payload}; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $prefix = $args{reply} ? RESPONSE_PREFIX : QUEUE_PREFIX; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | $queue = $prefix . $queue; | |||||||||||||||||||||||||||
| 64 | 0 | my $sql = qq{SELECT pg_notify(?,?)}; | |||||||||||||||||||||||||||
| 65 | 0 | my $task = $self->select_first( | |||||||||||||||||||||||||||
| 66 | sql => $sql, | ||||||||||||||||||||||||||||
| 67 | data => [ $queue, $payload], | ||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | sub get_notification { | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my ($self,$timeout) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_notification: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||
| 75 | 0 | my $notifies = $dbh->func('pg_notifies'); | |||||||||||||||||||||||||||
| 76 | 0 | return $notifies; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub set_listen { | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my ($self,$timeout) = @_; | ||||||||||||||||||||||||||
|
Subroutine
set_listen: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||
| 83 | 0 | my $notifies = $dbh->func('pg_notifies'); | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | if (!$notifies) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | my $fd = $dbh->{pg_socket}; | |||||||||||||||||||||||||||
| 86 | 0 | vec(my $rfds='',$fd,1) = 1; | |||||||||||||||||||||||||||
| 87 | 0 | my $n = select($rfds, undef, undef, $timeout); | |||||||||||||||||||||||||||
| 88 | 0 | $notifies = $dbh->func('pg_notifies'); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return $notifies || [0,0]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$notifies || [0, 0]
MC/DC0%0/1
$notifies || [0, 0]
$notifies
Truth table0%0/2
A
A= $notifies
| |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | sub fetch_work_task { | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
fetch_work_task: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my $queue = ref $self->{queue} ? $self->{queue} : [$self->{queue}]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | $self->{current_table} = 'task'; | |||||||||||||||||||||||||||
| 98 | 0 | my $elems = join(',', ('?') x @$queue); | |||||||||||||||||||||||||||
| 99 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 100 | UPDATE "$self->{database_schema}".$self->{current_table} t | ||||||||||||||||||||||||||||
| 101 | SET status=100, | ||||||||||||||||||||||||||||
| 102 | modified=default | ||||||||||||||||||||||||||||
| 103 | FROM "jobmachine".class cx | ||||||||||||||||||||||||||||
| 104 | WHERE t.class_id = cx.class_id | ||||||||||||||||||||||||||||
| 105 | AND task_id = ( | ||||||||||||||||||||||||||||
| 106 | SELECT min(task_id) | ||||||||||||||||||||||||||||
| 107 | FROM "$self->{database_schema}".$self->{current_table} t | ||||||||||||||||||||||||||||
| 108 | JOIN "jobmachine".class c USING (class_id) | ||||||||||||||||||||||||||||
| 109 | WHERE t.status=0 | ||||||||||||||||||||||||||||
| 110 | AND c.name IN ($elems) | ||||||||||||||||||||||||||||
| 111 | AND (t.run_after IS NULL | ||||||||||||||||||||||||||||
| 112 | OR t.run_after > now()) | ||||||||||||||||||||||||||||
| 113 | ) | ||||||||||||||||||||||||||||
| 114 | AND t.status=0 | ||||||||||||||||||||||||||||
| 115 | RETURNING * | ||||||||||||||||||||||||||||
| 116 | ; | ||||||||||||||||||||||||||||
| 117 | }; | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | my $task = $self->select_first( | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->select_first('sql', $sql, 'data', $queue) || (return)
MC/DC0%0/1
$self->select_first('sql', $sql, 'data', $queue) || (return)
$self->select_first('sql', $sql, 'data', $queue)
Truth table0%0/2
A
A= $self->select_first('sql', $sql, 'data', $queue)
| |||||||||||||||||||||||||||||
| 119 | sql => $sql, | ||||||||||||||||||||||||||||
| 120 | data => $queue | ||||||||||||||||||||||||||||
| 121 | ) || return; | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | $self->{task_id} = $task->{task_id}; | |||||||||||||||||||||||||||
| 124 | 0 | $task->{data} = $self->serializer->deserialize(delete $task->{parameters}); | |||||||||||||||||||||||||||
| 125 | 0 | return $task; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | sub insert_task { | ||||||||||||||||||||||||||||
| 130 | 0 | ▶ | my ($self,$data,$queue) = @_; | ||||||||||||||||||||||||||
|
Subroutine
insert_task: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | 0 | my $class = $self->fetch_class($queue); | |||||||||||||||||||||||||||
| 132 | 0 | $self->{current_table} = 'task'; | |||||||||||||||||||||||||||
| 133 | 0 | my $frozen = $self->serializer->serialize($data); | |||||||||||||||||||||||||||
| 134 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 135 | INSERT INTO "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 136 | (class_id,parameters,status) | ||||||||||||||||||||||||||||
| 137 | VALUES (?,?,?) | ||||||||||||||||||||||||||||
| 138 | RETURNING task_id | ||||||||||||||||||||||||||||
| 139 | }; | ||||||||||||||||||||||||||||
| 140 | 0 | $self->insert(sql => $sql,data => [$class->{class_id},$frozen,0]); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | sub set_task_status { | ||||||||||||||||||||||||||||
| 145 | 0 | ▶ | my ($self,$status) = @_; | ||||||||||||||||||||||||||
|
Subroutine
set_task_status: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 146 | 0 | my $id = $self->task_id; | |||||||||||||||||||||||||||
| 147 | 0 | $self->{current_table} = 'task'; | |||||||||||||||||||||||||||
| 148 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 149 | UPDATE "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 150 | SET status=? | ||||||||||||||||||||||||||||
| 151 | WHERE task_id=? | ||||||||||||||||||||||||||||
| 152 | }; | ||||||||||||||||||||||||||||
| 153 | 0 | $self->update(sql => $sql,data => [$status,$id]); | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | sub fetch_class { | ||||||||||||||||||||||||||||
| 158 | 0 | ▶ | my ($self,$queue) = @_; | ||||||||||||||||||||||||||
|
Subroutine
fetch_class: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | 0 | $self->{current_table} = 'class'; | |||||||||||||||||||||||||||
| 160 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 161 | SELECT * | ||||||||||||||||||||||||||||
| 162 | FROM "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 163 | WHERE name=? | ||||||||||||||||||||||||||||
| 164 | }; | ||||||||||||||||||||||||||||
| 165 | 0 | ▶ | return $self->select_first(sql => $sql,data => [$queue]) || $self->insert_class($queue); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->select_first('sql', $sql, 'data', [$queue]) || $self->insert_class($queue)
MC/DC0%0/2
$self->select_first('sql', $sql, 'data', [$queue]) || $self->insert_class($queue)
$self->select_first('sql', $sql, 'data', [$queue])
$self->insert_class($queue)
Truth table0%0/3
A || B
A= $self->select_first('sql', $sql, 'data', [$queue])B= $self->insert_class($queue)
| |||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | sub fetch_task { | ||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my ($self,$id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
fetch_task: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 171 | 0 | $self->{current_table} = 'task'; | |||||||||||||||||||||||||||
| 172 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 173 | SELECT * | ||||||||||||||||||||||||||||
| 174 | FROM "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 175 | JOIN "$self->{database_schema}".class USING (class_id) | ||||||||||||||||||||||||||||
| 176 | WHERE task_id=? | ||||||||||||||||||||||||||||
| 177 | }; | ||||||||||||||||||||||||||||
| 178 | 0 | ▶ | my $task = $self->select_first(sql => $sql,data => [$id]) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | $task->{frozen} = $task->{parameters}; | |||||||||||||||||||||||||||
| 181 | 0 | $task->{parameters} = $self->serializer->deserialize($task->{parameters}); | |||||||||||||||||||||||||||
| 182 | 0 | return $task; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | sub insert_class { | ||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my ($self,$queue) = @_; | ||||||||||||||||||||||||||
|
Subroutine
insert_class: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 189 | INSERT INTO "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 190 | (name) | ||||||||||||||||||||||||||||
| 191 | VALUES (?) | ||||||||||||||||||||||||||||
| 192 | RETURNING class_id | ||||||||||||||||||||||||||||
| 193 | }; | ||||||||||||||||||||||||||||
| 194 | 0 | $self->select_first(sql => $sql,data => [$queue]); | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | sub insert_result { | ||||||||||||||||||||||||||||
| 199 | 0 | ▶ | my ($self,$data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
insert_result: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 200 | 0 | $self->{current_table} = 'result'; | |||||||||||||||||||||||||||
| 201 | 0 | my @columns = qw/task_id result/; | |||||||||||||||||||||||||||
| 202 | 0 | my @values = ($self->{task_id}); | |||||||||||||||||||||||||||
| 203 | 0 | ▶ | if (ref $data eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 0 | push @columns, 'resulttype'; | |||||||||||||||||||||||||||
| 205 | 0 | my $type = delete $data->{type}; | |||||||||||||||||||||||||||
| 206 | 0 | push @values, $self->serializer->serialize($data), $type; | |||||||||||||||||||||||||||
| 207 | } else { | ||||||||||||||||||||||||||||
| 208 | 0 | push @values, $self->serializer->serialize($data); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | 0 | my $columns = join ', ', @columns; | |||||||||||||||||||||||||||
| 211 | 0 | my $qs = join(',', ('?') x @columns); | |||||||||||||||||||||||||||
| 212 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 213 | INSERT INTO "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 214 | ($columns) | ||||||||||||||||||||||||||||
| 215 | VALUES ($qs) | ||||||||||||||||||||||||||||
| 216 | RETURNING result_id | ||||||||||||||||||||||||||||
| 217 | }; | ||||||||||||||||||||||||||||
| 218 | 0 | $self->insert(sql => $sql,data => \@values); | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | sub fetch_result { | ||||||||||||||||||||||||||||
| 223 | 0 | ▶ | my ($self,$result_id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
fetch_result: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 224 | 0 | $self->{current_table} = 'result'; | |||||||||||||||||||||||||||
| 225 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 226 | SELECT * | ||||||||||||||||||||||||||||
| 227 | FROM "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 228 | WHERE result_id=? | ||||||||||||||||||||||||||||
| 229 | }; | ||||||||||||||||||||||||||||
| 230 | 0 | ▶ | my $result = $self->select_first(sql => $sql,data => [$result_id]) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->select_first('sql', $sql, 'data', [$result_id]) || (return)
MC/DC0%0/1
$self->select_first('sql', $sql, 'data', [$result_id]) || (return)
$self->select_first('sql', $sql, 'data', [$result_id])
Truth table0%0/2
A
A= $self->select_first('sql', $sql, 'data', [$result_id])
| |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 0 | my $r = $self->serializer->deserialize($result->{result}); | |||||||||||||||||||||||||||
| 233 | 0 | $result->{result} = $r; | |||||||||||||||||||||||||||
| 234 | 0 | return $result; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | sub fetch_first_result { | ||||||||||||||||||||||||||||
| 239 | 0 | ▶ | my ($self,$task_id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
fetch_first_result: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 240 | 0 | $self->{current_table} = 'result'; | |||||||||||||||||||||||||||
| 241 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 242 | SELECT * | ||||||||||||||||||||||||||||
| 243 | FROM "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 244 | WHERE task_id=? | ||||||||||||||||||||||||||||
| 245 | ORDER BY result_id DESC | ||||||||||||||||||||||||||||
| 246 | }; | ||||||||||||||||||||||||||||
| 247 | 0 | ▶ | my $result = $self->select_first(sql => $sql,data => [$task_id]) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->select_first('sql', $sql, 'data', [$task_id]) || (return)
MC/DC0%0/1
$self->select_first('sql', $sql, 'data', [$task_id]) || (return)
$self->select_first('sql', $sql, 'data', [$task_id])
Truth table0%0/2
A
A= $self->select_first('sql', $sql, 'data', [$task_id])
| |||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | return $self->serializer->deserialize($result->{result}); | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | sub fetch_results { | ||||||||||||||||||||||||||||
| 254 | 0 | ▶ | my ($self,$id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
fetch_results: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 255 | 0 | $self->{current_table} = 'result'; | |||||||||||||||||||||||||||
| 256 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 257 | SELECT * | ||||||||||||||||||||||||||||
| 258 | FROM "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 259 | WHERE task_id=? | ||||||||||||||||||||||||||||
| 260 | ORDER BY result_id DESC | ||||||||||||||||||||||||||||
| 261 | }; | ||||||||||||||||||||||||||||
| 262 | 0 | ▶ | my $results = $self->select_all(sql => $sql,data => [$id]) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->select_all('sql', $sql, 'data', [$id]) || (return)
MC/DC0%0/1
$self->select_all('sql', $sql, 'data', [$id]) || (return)
$self->select_all('sql', $sql, 'data', [$id])
Truth table0%0/2
A
A= $self->select_all('sql', $sql, 'data', [$id])
| |||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 0 | return [map { {id => $_->{result_id}, type => $_->{resulttype}, result => $self->serializer->deserialize($_->{result}) } } @{ $results } ]; | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | sub get_statuses { | ||||||||||||||||||||||||||||
| 269 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_statuses: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 270 | 0 | $self->{current_table} = 'task'; | |||||||||||||||||||||||||||
| 271 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 272 | SELECT status | ||||||||||||||||||||||||||||
| 273 | FROM "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 274 | GROUP BY status | ||||||||||||||||||||||||||||
| 275 | }; | ||||||||||||||||||||||||||||
| 276 | 0 | ▶ | my $stats = $self->select_all(sql => $sql) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->select_all('sql', $sql) || (return)
MC/DC0%0/1
$self->select_all('sql', $sql) || (return)
$self->select_all('sql', $sql)
Truth table0%0/2
A
A= $self->select_all('sql', $sql)
| |||||||||||||||||||||||||||||
| 277 | 0 | return $stats; | |||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | sub get_classes { | ||||||||||||||||||||||||||||
| 282 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_classes: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 283 | 0 | $self->{current_table} = 'class'; | |||||||||||||||||||||||||||
| 284 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 285 | SELECT * | ||||||||||||||||||||||||||||
| 286 | FROM "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 287 | }; | ||||||||||||||||||||||||||||
| 288 | 0 | ▶ | my $stats = $self->select_all(sql => $sql) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->select_all('sql', $sql) || (return)
MC/DC0%0/1
$self->select_all('sql', $sql) || (return)
$self->select_all('sql', $sql)
Truth table0%0/2
A
A= $self->select_all('sql', $sql)
| |||||||||||||||||||||||||||||
| 289 | 0 | return $stats; | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | sub get_tasks { | ||||||||||||||||||||||||||||
| 294 | 0 | ▶ | my ($self,%args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_tasks: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 295 | 0 | $self->{current_table} = 'task'; | |||||||||||||||||||||||||||
| 296 | 0 | my ($where_clause, @where_args) = $self->where_clause($args{where}); | |||||||||||||||||||||||||||
| 297 | 0 | my $order_by = $self->order_by($args{order_by}); | |||||||||||||||||||||||||||
| 298 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 299 | SELECT * | ||||||||||||||||||||||||||||
| 300 | FROM "$self->{database_schema}".$self->{current_table} t | ||||||||||||||||||||||||||||
| 301 | JOIN "$self->{database_schema}".class c USING (class_id) | ||||||||||||||||||||||||||||
| 302 | $where_clause | ||||||||||||||||||||||||||||
| 303 | $order_by | ||||||||||||||||||||||||||||
| 304 | }; | ||||||||||||||||||||||||||||
| 305 | 0 | ▶ | my $tasks = $self->select_all(sql => $sql,data => \@where_args) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->select_all('sql', $sql, 'data', \@where_args) || (return)
MC/DC0%0/1
$self->select_all('sql', $sql, 'data', \@where_args) || (return)
$self->select_all('sql', $sql, 'data', \@where_args)
Truth table0%0/2
A
A= $self->select_all('sql', $sql, 'data', \@where_args)
| |||||||||||||||||||||||||||||
| 306 | 0 | return $tasks; | |||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | sub revive_tasks { | ||||||||||||||||||||||||||||
| 311 | 0 | ▶ | my ($self,$max) = @_; | ||||||||||||||||||||||||||
|
Subroutine
revive_tasks: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 312 | 0 | $self->{current_table} = 'task'; | |||||||||||||||||||||||||||
| 313 | 0 | my $status = 100; | |||||||||||||||||||||||||||
| 314 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 315 | UPDATE "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 316 | SET status=0 | ||||||||||||||||||||||||||||
| 317 | WHERE status=? | ||||||||||||||||||||||||||||
| 318 | AND modified < now() - INTERVAL '$max seconds' | ||||||||||||||||||||||||||||
| 319 | }; | ||||||||||||||||||||||||||||
| 320 | 0 | my $result = $self->do(sql => $sql,data => [$status]); | |||||||||||||||||||||||||||
| 321 | 0 | return $result; | |||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | sub fail_tasks { | ||||||||||||||||||||||||||||
| 326 | 0 | ▶ | my ($self,$retries) = @_; | ||||||||||||||||||||||||||
|
Subroutine
fail_tasks: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 327 | 0 | $self->{current_table} = 'result'; | |||||||||||||||||||||||||||
| 328 | 0 | my $limit = 100; | |||||||||||||||||||||||||||
| 329 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 330 | SELECT task_id | ||||||||||||||||||||||||||||
| 331 | FROM "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 332 | GROUP BY task_id | ||||||||||||||||||||||||||||
| 333 | HAVING count(*)>? | ||||||||||||||||||||||||||||
| 334 | LIMIT ? | ||||||||||||||||||||||||||||
| 335 | }; | ||||||||||||||||||||||||||||
| 336 | 0 | ▶ | my $result = $self->select_all(sql => $sql,data => [$retries,$limit]) || return 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->select_all('sql', $sql, 'data', [$retries, $limit]) || (return 0)
MC/DC0%0/1
$self->select_all('sql', $sql, 'data', [$retries, $limit]) || (return 0)
$self->select_all('sql', $sql, 'data', [$retries, $limit])
Truth table0%0/2
A
A= $self->select_all('sql', $sql, 'data', [$retries, $limit])
| |||||||||||||||||||||||||||||
| 337 | 0 | ▶ | return 0 unless @$result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 0 | my $task_ids = join ',',map {$_->{task_id}} @$result; | |||||||||||||||||||||||||||
| 340 | 0 | $self->{current_table} = 'task'; | |||||||||||||||||||||||||||
| 341 | 0 | my $status = 900; | |||||||||||||||||||||||||||
| 342 | 0 | $sql = qq{ | |||||||||||||||||||||||||||
| 343 | UPDATE "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 344 | SET status=? | ||||||||||||||||||||||||||||
| 345 | WHERE task_id IN ($task_ids) | ||||||||||||||||||||||||||||
| 346 | }; | ||||||||||||||||||||||||||||
| 347 | 0 | $self->do(sql => $sql,data => [$status]); | |||||||||||||||||||||||||||
| 348 | 0 | return scalar @$result; | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | sub remove_tasks { | ||||||||||||||||||||||||||||
| 353 | 0 | ▶ | my ($self,$after) = @_; | ||||||||||||||||||||||||||
|
Subroutine
remove_tasks: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 354 | 0 | ▶ | return 0 unless $after; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 0 | $self->{current_table} = 'task'; | |||||||||||||||||||||||||||
| 357 | 0 | my $limit = 100; | |||||||||||||||||||||||||||
| 358 | 0 | my $sql = qq{ | |||||||||||||||||||||||||||
| 359 | DELETE FROM "$self->{database_schema}".$self->{current_table} | ||||||||||||||||||||||||||||
| 360 | WHERE modified < now() - INTERVAL '$after days' | ||||||||||||||||||||||||||||
| 361 | }; | ||||||||||||||||||||||||||||
| 362 | 0 | my $result = $self->do(sql => $sql,data => []); | |||||||||||||||||||||||||||
| 363 | 0 | return $result; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | sub select_first { | ||||||||||||||||||||||||||||
| 368 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
select_first: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 369 | 0 | ▶ | my $sth = $self->dbh->prepare($args{sql}) || return 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->dbh->prepare($args{'sql'}) || (return 0)
MC/DC0%0/1
$self->dbh->prepare($args{'sql'}) || (return 0)
$self->dbh->prepare($args{'sql'})
Truth table0%0/2
A
A= $self->dbh->prepare($args{'sql'})
| |||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | 0 | ▶ | unless($sth->execute(@{$args{data}})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 372 | 0 | my @c = caller; | |||||||||||||||||||||||||||
| 373 | 0 | print STDERR "File: $c[1] line $c[2]\n"; | |||||||||||||||||||||||||||
| 374 | 0 | ▶ | print STDERR $args{sql}."\n" if($args{sql}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | 0 | return 0; | |||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | 0 | my $r = $sth->fetchrow_hashref(); | |||||||||||||||||||||||||||
| 378 | 0 | $sth->finish(); | |||||||||||||||||||||||||||
| 379 | 0 | return ( $r ); | |||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | sub select_all { | ||||||||||||||||||||||||||||
| 384 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
select_all: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 385 | 0 | ▶ | my $sth = $self->dbh->prepare($args{sql}) || return 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->dbh->prepare($args{'sql'}) || (return 0)
MC/DC0%0/1
$self->dbh->prepare($args{'sql'}) || (return 0)
$self->dbh->prepare($args{'sql'})
Truth table0%0/2
A
A= $self->dbh->prepare($args{'sql'})
| |||||||||||||||||||||||||||||
| 386 | 0 | ▶ | $self->set_bind_type($sth,$args{data} || []); | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{'data'} || []
MC/DC0%0/1
$args{'data'} || []
$args{'data'}
Truth table0%0/2
A
A= $args{'data'}
| |||||||||||||||||||||||||||||
| 387 | 0 | ▶ | unless($sth->execute(@{$args{data}})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 388 | 0 | my @c = caller; | |||||||||||||||||||||||||||
| 389 | 0 | print STDERR "File: $c[1] line $c[2]\n"; | |||||||||||||||||||||||||||
| 390 | 0 | ▶ | print STDERR $args{sql}."\n" if($args{sql}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 391 | 0 | return 0; | |||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | 0 | my @result; | |||||||||||||||||||||||||||
| 394 | 0 | ▶ | while( my $r = $sth->fetchrow_hashref) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 395 | 0 | push(@result,$r); | |||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||
| 397 | 0 | $sth->finish(); | |||||||||||||||||||||||||||
| 398 | 0 | return ( \@result ); | |||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | sub set_bind_type { | ||||||||||||||||||||||||||||
| 402 | 0 | ▶ | my ($self,$sth,$data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
set_bind_type: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 403 | 0 | for my $i (0..scalar(@$data)-1) { | |||||||||||||||||||||||||||
| 404 | 0 | ▶ | next unless(ref($data->[$i])); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 0 | $sth->bind_param($i+1, undef, $data->[$i]->[1]); | |||||||||||||||||||||||||||
| 407 | 0 | $data->[$i] = $data->[$i]->[0]; | |||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||
| 409 | 0 | return; | |||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | sub do { | ||||||||||||||||||||||||||||
| 413 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
do: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 414 | 0 | ▶ | my $sth = $self->dbh->prepare($args{sql}) || return 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->dbh->prepare($args{'sql'}) || (return 0)
MC/DC0%0/1
$self->dbh->prepare($args{'sql'}) || (return 0)
$self->dbh->prepare($args{'sql'})
Truth table0%0/2
A
A= $self->dbh->prepare($args{'sql'})
| |||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 0 | $sth->execute(@{$args{data}}); | |||||||||||||||||||||||||||
| 417 | 0 | my $rows = $sth->rows; | |||||||||||||||||||||||||||
| 418 | 0 | $sth->finish(); | |||||||||||||||||||||||||||
| 419 | 0 | return $rows; | |||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | sub insert { | ||||||||||||||||||||||||||||
| 423 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
insert: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 424 | 0 | ▶ | my $sth = $self->dbh->prepare($args{sql}) || return 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->dbh->prepare($args{'sql'}) || (return 0)
MC/DC0%0/1
$self->dbh->prepare($args{'sql'}) || (return 0)
$self->dbh->prepare($args{'sql'})
Truth table0%0/2
A
A= $self->dbh->prepare($args{'sql'})
| |||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 0 | $sth->execute(@{$args{data}}); | |||||||||||||||||||||||||||
| 427 | 0 | my $retval = $sth->fetch()->[0]; | |||||||||||||||||||||||||||
| 428 | 0 | $sth->finish(); | |||||||||||||||||||||||||||
| 429 | 0 | return $retval; | |||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | sub update { | ||||||||||||||||||||||||||||
| 433 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
update: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 434 | 0 | $self->do(@_); | |||||||||||||||||||||||||||
| 435 | 0 | return; | |||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | sub dbh { | ||||||||||||||||||||||||||||
| 439 | 0 | ▶ | return $_[0]->{dbh} || confess "No database handle"; | ||||||||||||||||||||||||||
|
Subroutine
dbh: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/3
$_[0]{'dbh'} || confess('No database handle')
MC/DC0%0/2
$_[0]{'dbh'} || confess('No database handle')
$_[0]{'dbh'}
confess('No database handle')
Truth table0%0/3
A || B
A= $_[0]{'dbh'}B= confess('No database handle')
| |||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | sub task_id { | ||||||||||||||||||||||||||||
| 443 | 0 | ▶ | return $_[0]->{task_id} || confess "No task id"; | ||||||||||||||||||||||||||
|
Subroutine
task_id: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/3
$_[0]{'task_id'} || confess('No task id')
MC/DC0%0/2
$_[0]{'task_id'} || confess('No task id')
$_[0]{'task_id'}
confess('No task id')
Truth table0%0/3
A || B
A= $_[0]{'task_id'}B= confess('No task id')
| |||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | sub disconnect { | ||||||||||||||||||||||||||||
| 447 | 0 | ▶ | return $_[0]->{dbh}->disconnect if $_[0]->{dbh}; | ||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | sub DESTROY { | ||||||||||||||||||||||||||||
| 451 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 452 | 0 | ▶ | $self->disconnect() unless $self->{dbh_inherited}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 453 | 0 | return; | |||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | sub where_clause { | ||||||||||||||||||||||||||||
| 458 | 0 | ▶ | my ($self, $where) = @_; | ||||||||||||||||||||||||||
|
Subroutine
where_clause: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 459 | 0 | my $where_clause = join(' AND ', ("$_ = ?") x keys %$where); | |||||||||||||||||||||||||||
| 460 | 0 | ▶ | $where_clause = "WHERE $where_clause" if $where_clause; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 461 | 0 | return $where_clause, values %$where; | |||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | sub order_by { | ||||||||||||||||||||||||||||
| 466 | 0 | ▶ | my ($self, $order) = @_; | ||||||||||||||||||||||||||
|
Subroutine
order_by: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 467 | 0 | ▶ | return unless ref $order eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | 0 | my $order_by = join(',', ("$_") x keys %$order); | |||||||||||||||||||||||||||
| 470 | 0 | ▶ | $order_by = "ORDER BY $order_by" if $order_by; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 471 | 0 | return $order_by; | |||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | 2 | 1; | |||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | __END__ | ||||||||||||||||||||||||||||