blib/lib/ClearPress/driver/Pg.pm

filter: Statementstmt 48.8% 21 / 43 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 54.5% 6 / 11 Podpod 100% 5 / 5 totaltotal 34.7% 32 / 92 CC 12 SCAR 37.1
CC
12
Cov
31%
dbh
90.0
bounded_select
20.0
create
2.0
CRAP 41.0
« bin/clearpress ↑ Summary blib/lib/ClearPress/controller.pm »
1 #########
2 # Author: rmp
3 # Created: 2006-10-31
4 #
5 package ClearPress::driver::Pg;
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use base qw(ClearPress::driver);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our $VERSION = q[2026.07.25];
14  
15 1 Readonly::Scalar our $TYPES => {
16 'primary key' => 'bigint unsigned not null auto_increment primary key',
17 };
18 0 ▶sub dbh {
Subroutine dbh: not called CC=9 SCAR=45.0
Pod documented
19 0 my $self = shift;
20  
21 0 ▶ if(!$self->{dbh} ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dbh"} and $self->{"dbh"}->ping) 0 0 0
Condition0%0/3
$self->{"dbh"} and $self->{"dbh"}->ping
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"dbh"} and $self->{"dbh"}->ping
$self->{"dbh"} $self->{"dbh"}->ping
Truth table0%0/3
A and B
A= $self->{"dbh"}B= $self->{"dbh"}->ping
ABresult
0X0
100
111
22 !$self->{dbh}->ping()) {
23 my $dsn = sprintf q(DBI:Pg:database=%s;host=%s;port=%s),
24 $self->{dbname} || q[],
25 $self->{dbhost} || q[localhost],
26 0 ▶ $self->{dbport} || q[3306];
Condition0%0/6
$self->{'dbname'} || ''
l!l
00
$self->{'dbhost'} || 'localhost'
l!l
00
$self->{'dbport'} || '3306'
l!l
00
MC/DC0%0/1
$self->{'dbname'} || ''
$self->{'dbname'}
MC/DC0%0/1
$self->{'dbhost'} || 'localhost'
$self->{'dbhost'}
MC/DC0%0/1
$self->{'dbport'} || '3306'
$self->{'dbport'}
Truth table0%0/2
A
A= $self->{'dbname'}
Aresult
11
00
Truth table0%0/2
A
A= $self->{'dbhost'}
Aresult
11
00
Truth table0%0/2
A
A= $self->{'dbport'}
Aresult
11
00
27  
28 eval {
29 $self->{dbh} = DBI->connect($dsn,
30 $self->{dbuser} || q[],
31 $self->{dbpass},
32 0 ▶ {RaiseError => 1,
Condition0%0/2
$self->{'dbuser'} || ''
l!l
00
MC/DC0%0/1
$self->{'dbuser'} || ''
$self->{'dbuser'}
Truth table0%0/2
A
A= $self->{'dbuser'}
Aresult
11
00
33 AutoCommit => 0});
34  
35 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->{"dbh"} = "DBI"->connect($dsn, $self->{"dbuser"} || "", $self->{"dbpass"}, {"RaiseError", 1, "AutoCommit", 0}) } } or do { croak(qq[Failed to connect to $dsn using @{[$self->{"dbuser"} || "''"];}\n$ClearPress::driver::Pg::EVAL_ERROR]) } 0 0 0
36 0 ▶ croak qq[Failed to connect to $dsn using @{[$self->{dbuser}||q['']]}\n$EVAL_ERROR];
Condition0%0/2
$self->{'dbuser'} || q['']
l!l
00
MC/DC0%0/1
$self->{'dbuser'} || q['']
$self->{'dbuser'}
Truth table0%0/2
A
A= $self->{'dbuser'}
Aresult
11
00
37 };
38  
39 #########
40 # rollback any junk left behind if this is a cached handle
41 #
42 0 $self->{dbh}->rollback();
43 }
44  
45 0 return $self->{dbh};
46 }
47  
48 0 ▶sub create {
Subroutine create: not called CC=1 SCAR=6.9
Pod documented
49 0 my ($self, $query, @args) = @_;
50 0 my $dbh = $self->dbh();
51  
52 0 $dbh->do($query, {}, @args);
53 0 my $idref = $dbh->selectall_arrayref('SELECT LAST_INSERT_ID()');
54  
55 0 return $idref->[0]->[0];
56 }
57  
58 0 ▶sub create_table {
Subroutine create_table: not called CC=1 SCAR=6.9
Pod documented
59 0 my ($self, $table_name, $ref) = @_;
60 0 return $self->SUPER::create_table($table_name, $ref, { engine=>'InnoDB'});
61 }
62  
63 0 ▶sub types {
Subroutine types: not called CC=1 SCAR=6.9
Pod documented
64 0 return $TYPES;
65 }
66  
67 0 ▶sub bounded_select {
Subroutine bounded_select: not called CC=4 SCAR=30.0
Pod documented
68 0 my ($self, $query, $len, $start) = @_;
69  
70 0 ▶ if(defined $start && defined $len) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $start and defined $len) { } 0 0 0
elsif (defined $len) { } 0 0 0
Condition0%0/3
defined $start and defined $len
!ll&&!rl&&r
000
MC/DC0%0/2
defined $start and defined $len
defined $start defined $len
Truth table0%0/3
A and B
A= defined $startB= defined $len
ABresult
0X0
100
111
71 0 $query .= qq[ LIMIT $start, $len];
72 } elsif(defined $len) {
73 0 $query .= qq[ LIMIT $len];
74 }
75  
76 0 return $query;
77 }
78  
79 1 1;
80 __END__
« bin/clearpress ↑ Summary blib/lib/ClearPress/controller.pm »