blib/lib/Langertha/Holmgang/Sim/Linux/Postgres.pm

filter: Statementstmt 81.5% 1092 / 1339 Branchbran 63.2% 663 / 1048 Conditioncond 47.9% 490 / 1021 MC/DCmcdc 18.8% 103 / 548 Subroutinesub 94.1% 64 / 68 Podpod 100% 3 / 3 totaltotal 59.9% 2415 / 4027 CC 992 SCAR 55.9
CC
992
Cov
66%
_meta
827.8
psql
703.4
_view
623.7
CRAP 268.9
« blib/lib/Langertha/Holmgang/Sim/Linux/Git.pm ↑ Summary blib/lib/Langertha/Holmgang/Expectation.pm »
1 package Langertha::Holmgang::Sim::Linux::Postgres;
2 # ABSTRACT: PostgreSQL on a simulated Linux server — psql, an SQL subset, pg_hba, settings, slots
3  
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Digest::MD5 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Langertha::Holmgang::Sim::Linux::Calendar ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Time::Local ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 our $VERSION = '0.001';
14  
15  
16 4 my $JSON = JSON::MaybeXS->new( canonical => 1 );
17  
18 # Simulationszeit (UTC-Sekunden) fuer now(); Zeitstempel als Text wie psql sie zeigt
19 4 our $NOW = 1792828800; # 2026-10-24 08:00:00 UTC
20 1556 ▶sub _ts { my @t = gmtime( $_[0] ); return sprintf '%04d-%02d-%02d %02d:%02d:%02d+00', $t[5] + 1900, $t[4] + 1, @t[ 3, 2, 1, 0 ] }
Subroutine _ts: called CC=1 SCAR=0.0
21 192 ▶sub _epoch {
Subroutine _epoch: called CC=5 SCAR=17.8
22 192 my ($v) = @_;
23 192 ▶ return undef unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 192 192
24 192 ▶ if ( $v =~ /\A(\d{4})-(\d\d)-(\d\d)[ T](\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:([+-])(\d\d))?/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /\A(\d{4})-(\d\d)-(\d\d)[ T](\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:([+-])(\d\d))?/) 192 0 192
25 192 my $e = Time::Local::timegm( $6, $5, $4, $3, $2 - 1, $1 );
26 192 ▶ $e -= ( $7 eq '+' ? 1 : -1 ) * $8 * 3600 if defined $7;
Branch: 2 branches
BranchTrueFalseTotal
if defined $7 192 0 192
$7 eq '+' ? : 192 0 192
27 192 return $e;
28 }
29 0 return undef;
30 }
31  
32 4 our @GAPS;
33  
34 # Kontext der Einstellungen: postmaster (Neustart) / sighup (reload) / user.
35 4 our %CONTEXT = (
36 max_connections => 'postmaster', shared_buffers => 'postmaster', listen_addresses => 'postmaster',
37 superuser_reserved_connections => 'postmaster', max_wal_senders => 'postmaster', max_replication_slots => 'postmaster',
38 port => 'postmaster', wal_level => 'postmaster', fsync => 'sighup', autovacuum => 'sighup',
39 max_slot_wal_keep_size => 'sighup', wal_keep_size => 'sighup', max_wal_size => 'sighup',
40 autovacuum_vacuum_scale_factor => 'sighup', autovacuum_naptime => 'sighup', log_min_duration_statement => 'superuser',
41 idle_in_transaction_session_timeout => 'user', work_mem => 'user', statement_timeout => 'user',
42 synchronous_commit => 'user', full_page_writes => 'sighup', password_encryption => 'user',
43 );
44  
45 # Spalten der echten Katalog-Sichten (PostgreSQL 15); fehlt eine davon in der Nachbildung, ist das eine Luecke.
46 4 our %REAL_COLS = map { my ( $v, @c ) = split ' '; ( $v => { map { $_ => 1 } @c } ) } split /\n/, <<'EOT';
47 pg_stat_activity datid datname pid leader_pid usesysid usename application_name client_addr client_hostname client_port backend_start xact_start query_start state_change wait_event_type wait_event state backend_xid backend_xmin query_id query backend_type
48 pg_stat_user_tables relid schemaname relname seq_scan seq_tup_read idx_scan idx_tup_fetch n_tup_ins n_tup_upd n_tup_del n_tup_hot_upd n_live_tup n_dead_tup n_mod_since_analyze n_ins_since_vacuum last_vacuum last_autovacuum last_analyze last_autoanalyze vacuum_count autovacuum_count analyze_count autoanalyze_count
49 pg_settings name setting unit category short_desc extra_desc context vartype source min_val max_val enumvals boot_val reset_val sourcefile sourceline pending_restart
50 pg_replication_slots slot_name plugin slot_type datoid database temporary active active_pid xmin catalog_xmin restart_lsn confirmed_flush_lsn wal_status safe_wal_size two_phase
51 pg_roles rolname rolsuper rolinherit rolcreaterole rolcreatedb rolcanlogin rolreplication rolconnlimit rolpassword rolvaliduntil rolbypassrls rolconfig oid
52 pg_file_settings sourcefile sourceline seqno name setting applied error
53 pg_authid oid rolname rolsuper rolinherit rolcreaterole rolcreatedb rolcanlogin rolreplication rolbypassrls rolconnlimit rolpassword rolvaliduntil
54 pg_database oid datname datdba encoding datlocprovider datistemplate datallowconn datconnlimit datfrozenxid datminmxid dattablespace datcollate datctype daticulocale datcollversion datacl
55 pg_tables schemaname tablename tableowner tablespace hasindexes hasrules hastriggers rowsecurity
56 pg_hba_file_rules line_number type database user_name address netmask auth_method options error
57 pg_class oid relname relnamespace reltype reloftype relowner relam relfilenode reltablespace relpages reltuples relallvisible reltoastrelid relhasindex relisshared relpersistence relkind relnatts relchecks relhasrules relhastriggers relhassubclass relrowsecurity relforcerowsecurity relispopulated relreplident relispartition relrewrite relfrozenxid relminmxid relacl reloptions relpartbound
58 EOT
59  
60 29 ▶sub _bytes {
Subroutine _bytes: called CC=4 SCAR=14.6
61 29 my ($v) = @_;
62 29 ▶ return 0 unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 29 29
63 29 ▶ return $v if $v =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /\A\d+\z/ 0 29 29
64 29 my %u = ( K => 1024, M => 1024**2, G => 1024**3, T => 1024**4 );
65 29 ▶ return $v =~ /\A(\d+(?:\.\d+)?)\s*([KMGT])B?\z/i ? int( $1 * $u{ uc $2 } ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /\A(\d+(?:\.\d+)?)\s*([KMGT])B?\z/i ? : 29 0 29
66 }
67  
68 2 ▶sub _pretty {
Subroutine _pretty: called CC=5 SCAR=16.8
69 2 my ($b) = @_;
70 2 ▶ return "$b bytes" if $b < 10240;
Branch: 1 branch
BranchTrueFalseTotal
if $b < 10240 0 2 2
71 2 for my $u ( [ TB => 1024**4 ], [ GB => 1024**3 ], [ MB => 1024**2 ], [ kB => 1024 ] ) {
72 5 ▶ return int( $b / $u->[1] + 0.5 ) . " $u->[0]" if $b >= 10 * $u->[1] || $u->[0] eq 'kB';
Branch: 1 branch
BranchTrueFalseTotal
if $b >= 10 * $$u[1] or $$u[0] eq "kB" 2 3 5
Condition66%2/3
$b >= 10 * $$u[1] or $$u[0] eq "kB"
l!l&&r!l&&!r
203
MC/DC50%1/2
$b >= 10 * $$u[1] or $$u[0] eq "kB"
$b >= 10 * $$u[1] $$u[0] eq "kB"
Truth table66%2/3
A or B
A= $b >= 10 * $$u[1]B= $$u[0] eq "kB"
ABresult
1X1
011
000
73 }
74 0 return "$b bytes";
75 }
76  
77 # --- Konfiguration ------------------------------------------------------------
78  
79 # Einstellungen von PostgreSQL 15: Typ, Einheit, Vorgabe (in der Einheit), Kategorie.
80 # pg_settings zeigt diese mit source default, wenn der Zustand sie nicht fuehrt.
81 4 our %GUC = map { my ( $n, $t, $u, $b, @c ) = split /\|/; ( $n => { vartype => $t, unit => $u, boot => $b, category => join( '|', @c ) } ) } split /\n/, <<'EOT';
82 listen_addresses|string||localhost|Connections and Authentication / Connection Settings
83 port|integer||5432|Connections and Authentication / Connection Settings
84 max_connections|integer||100|Connections and Authentication / Connection Settings
85 superuser_reserved_connections|integer||3|Connections and Authentication / Connection Settings
86 password_encryption|enum||scram-sha-256|Connections and Authentication / Authentication
87 shared_buffers|integer|8kB|16384|Resource Usage / Memory
88 work_mem|integer|kB|4096|Resource Usage / Memory
89 maintenance_work_mem|integer|kB|65536|Resource Usage / Memory
90 effective_cache_size|integer|8kB|524288|Query Tuning / Planner Cost Constants
91 random_page_cost|real||4|Query Tuning / Planner Cost Constants
92 wal_level|enum||replica|Write-Ahead Log / Settings
93 fsync|bool||on|Write-Ahead Log / Settings
94 synchronous_commit|enum||on|Write-Ahead Log / Settings
95 full_page_writes|bool||on|Write-Ahead Log / Settings
96 checkpoint_timeout|integer|s|300|Write-Ahead Log / Checkpoints
97 max_wal_size|integer|MB|1024|Write-Ahead Log / Checkpoints
98 max_wal_senders|integer||10|Replication / Sending Servers
99 max_replication_slots|integer||10|Replication / Sending Servers
100 wal_keep_size|integer|MB|0|Replication / Sending Servers
101 max_slot_wal_keep_size|integer|MB|-1|Replication / Sending Servers
102 autovacuum|bool||on|Autovacuum
103 autovacuum_naptime|integer|s|60|Autovacuum
104 autovacuum_vacuum_scale_factor|real||0.2|Autovacuum
105 log_min_duration_statement|integer|ms|-1|Reporting and Logging / When to Log
106 log_min_messages|enum||warning|Reporting and Logging / When to Log
107 log_statement|enum||none|Reporting and Logging / What to Log
108 log_lock_waits|bool||off|Reporting and Logging / What to Log
109 log_line_prefix|string||%m [%p] %q%u@%d |Reporting and Logging / What to Log
110 statement_timeout|integer|ms|0|Client Connection Defaults / Statement Behavior
111 lock_timeout|integer|ms|0|Client Connection Defaults / Statement Behavior
112 idle_in_transaction_session_timeout|integer|ms|0|Client Connection Defaults / Statement Behavior
113 deadlock_timeout|integer|ms|1000|Lock Management
114 EOT
115  
116 # Wert in der Grundeinheit der Einstellung, wie pg_settings.setting ("16MB" -> 16384 bei kB)
117 392 ▶sub _guc_base {
Subroutine _guc_base: called CC=11 SCAR=27.4
118 392 my ( $name, $v ) = @_;
119 392 ▶ my $u = ( $GUC{$name} || {} )->{unit} // '';
Condition50%2/4
($Langertha::Holmgang::Sim::Linux::Postgres::GUC{$name} || {})->{"unit"} // ""
l!l
3920
$Langertha::Holmgang::Sim::Linux::Postgres::GUC{$name} || {}
l!l
3920
MC/DC0%0/1
($Langertha::Holmgang::Sim::Linux::Postgres::GUC{$name} || {})->{"unit"} // ""
$Langertha::Holmgang::Sim::Linux::Postgres::GUC{$name}
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::Postgres::GUC{$name}
Aresult
11
00
120 392 ▶ return $v unless length $u && defined $v && $v =~ /\A\s*(-?\d+(?:\.\d+)?)\s*([a-zA-Z]+)\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless length $u and defined $v and $v =~ /\A\s*(-?\d+(?:\.\d+)?)\s*([a-zA-Z]+)\s*\z/ 360 32 392
Condition83%5/6
length $u and defined $v and $v =~ /\A\s*(-?\d+(?:\.\d+)?)\s*([a-zA-Z]+)\s*\z/
!ll&&!rl&&r
22413632
length $u and defined $v
!ll&&!rl&&r
2240168
MC/DC66%2/3
length $u and defined $v and $v =~ /\A\s*(-?\d+(?:\.\d+)?)\s*([a-zA-Z]+)\s*\z/
length $u defined $v $v =~ /\A\s*(-?\d+(?:\.\d+)?)\s*([a-zA-Z]+)\s*\z/
Truth table75%3/4
A and B and C
A= length $uB= defined $vC= $v =~ /\A\s*(-?\d+(?:\.\d+)?)\s*([a-zA-Z]+)\s*\z/
ABCresult
0XX0
10X0
1100
1111
121 32 my ( $n, $vu ) = ( $1, $2 );
122 32 my %mem = ( B => 1 / 1024, kB => 1, MB => 1024, GB => 1024**2, TB => 1024**3 );
123 32 my %time = ( us => 0.001, ms => 1, s => 1000, min => 60000, h => 3600000, d => 86400000 );
124 32 ▶ if ( $u =~ /\A(\d*)(kB|MB)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\A(\d*)(kB|MB)\z/) 32 0 32
125 32 ▶ my $base = ( length $1 ? $1 : 1 ) * $mem{$2};
Branch: 1 branch
BranchTrueFalseTotal
length $1 ? : 20 12 32
126 32 ▶ return defined $mem{$vu} ? int( $n * $mem{$vu} / $base ) : $v;
Branch: 1 branch
BranchTrueFalseTotal
defined $mem{$vu} ? : 32 0 32
127 }
128 0 ▶ my $base = $time{$u} // return $v;
Condition0%0/2
$time{$u} // (return $v)
l!l
00
MC/DC0%0/1
$time{$u} // (return $v)
$time{$u}
Truth table0%0/2
A
A= $time{$u}
Aresult
11
00
129 0 ▶ return defined $time{$vu} ? int( $n * $time{$vu} / $base ) : $v;
Branch: 1 branch
BranchTrueFalseTotal
defined $time{$vu} ? : 0 0 0
130 }
131  
132 # Millisekunden eines Zeitwerts (log_min_duration_statement: "250", "250ms", "1s")
133 4 ▶sub _ms { my ($v) = @_; return undef unless defined $v; return $v =~ /\A\s*-?\d+\s*\z/ ? 0 + $v : _guc_base( 'deadlock_timeout', $v ) }
Subroutine _ms: called CC=3 SCAR=11.7
Branch: 2 branches
BranchTrueFalseTotal
unless defined $v 0 4 4
$v =~ /\A\s*-?\d+\s*\z/ ? : 4 0 4
134  
135 53 ▶sub _file {
Subroutine _file: called CC=5 SCAR=17.1
136 53 my ( $dev, $path ) = @_;
137 53 ▶ my $f = ( $dev->{files} || {} )->{ $path // '' };
Condition100%4/4
$$dev{'files'} || {}
l!l
476
$path // ""
l!l
476
MC/DC100%1/1
$$dev{'files'} || {}
$$dev{'files'}
MC/DC100%1/1
$path // ""
$path
Truth table100%2/2
A
A= $$dev{'files'}
Aresult
11
00
Truth table100%2/2
A
A= $path
Aresult
11
00
138 53 ▶ return ref $f eq 'HASH' ? $f->{content} // '' : $f;
Branch: 1 branch
BranchTrueFalseTotal
ref $f eq 'HASH' ? : 0 53 53
Condition0%0/2
$$f{"content"} // ""
l!l
00
MC/DC0%0/1
$$f{"content"} // ""
$$f{"content"}
Truth table0%0/2
A
A= $$f{"content"}
Aresult
11
00
139 }
140  
141 3 ▶sub _set_file {
Subroutine _set_file: called CC=2 SCAR=7.4
142 3 my ( $dev, $path, $text ) = @_;
143 3 my $f = $dev->{files}{$path};
144 0 ▶ if ( ref $f eq 'HASH' ) { $f->{content} = $text } else { $dev->{files}{$path} = $text }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $f eq 'HASH') { } 0 3 3
145 }
146  
147 26 ▶sub _conf_values {
Subroutine _conf_values: called CC=5 SCAR=16.1
148 26 my ($text) = @_;
149 26 my %v;
150 26 ▶ for my $l ( split /\n/, $text // '' ) {
Condition100%2/2
$text // ""
l!l
224
MC/DC100%1/1
$text // ""
$text
Truth table100%2/2
A
A= $text
Aresult
11
00
151 84 $l =~ s/#.*//;
152 84 ▶ next unless $l =~ /\A\s*([a-z_]+)\s*=?\s*(?:'([^']*)'|(\S+))/;
Branch: 1 branch
BranchTrueFalseTotal
unless $l =~ /\A\s*([a-z_]+)\s*=?\s*(?:'([^']*)'|(\S+))/ 15 69 84
153 69 ▶ $v{$1} = defined $2 ? $2 : $3;
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 21 48 69
154 }
155 26 return \%v;
156 }
157  
158 8 ▶sub _file_settings {
Subroutine _file_settings: called CC=1 SCAR=0.0
159 8 my ( $pg, $dev ) = @_;
160 8 return { %{ _conf_values( _file( $dev, $pg->{conf} ) ) }, %{ _conf_values( _file( $dev, $pg->{auto_conf} ) ) } };
161 }
162  
163 12 ▶sub _norm_val { my ($v) = @_; $v = lc $v; return { true => 'on', yes => 'on', 1 => 'on', false => 'off', no => 'off', 0 => 'off' }->{$v} // $v }
Subroutine _norm_val: called CC=2 SCAR=7.6
Condition33%1/3
{"true", "on", "yes", "on", 1, "on", "false", "off", "no", "off", 0, "off"}->{$v} // $v
l!l&&r!l&&!r
0120
MC/DC0%0/2
{"true", "on", "yes", "on", 1, "on", "false", "off", "no", "off", 0, "off"}->{$v} // $v
{"true", "on", "yes", "on", 1, "on", "false", "off", "no", "off", 0, "off"}->{$v} $v
Truth table33%1/3
A // B
A= {"true", "on", "yes", "on", 1, "on", "false", "off", "no", "off", 0, "off"}->{$v}B= $v
ABresult
1X1
011
000
164  
165 # reload: sighup-Einstellungen und pg_hba neu; postmaster-Einstellungen nur bei $restart.
166 8 ▶sub _apply_config {
Subroutine _apply_config: called CC=15 SCAR=27.3
167 8 my ( $dev, $restart ) = @_;
168 8 my $pg = $dev->{postgres};
169 8 my $want = _file_settings( $pg, $dev );
170 8 ▶ my $s = $pg->{settings} //= {};
Condition50%1/2
$$pg{"settings"} //= {}
l!l
80
MC/DC0%0/1
$$pg{"settings"} //= {}
$$pg{"settings"}
Truth table50%1/2
A
A= $$pg{"settings"}
Aresult
11
00
171 8 my %pending;
172 8 for my $k ( sort keys %$want ) {
173 27 ▶ next unless exists $s->{$k} || exists $CONTEXT{$k}; # z. B. data_directory: nicht gefuehrt
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$s{$k} or exists $Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$k} 0 27 27
Condition33%1/3
exists $$s{$k} or exists $Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$k}
l!l&&r!l&&!r
2700
MC/DC0%0/2
exists $$s{$k} or exists $Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$k}
exists $$s{$k} exists $Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$k}
Truth table33%1/3
A or B
A= exists $$s{$k}B= exists $Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$k}
ABresult
1X1
011
000
174 27 ▶ my $ctx = $CONTEXT{$k} // 'sighup';
Condition100%2/2
$Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$k} // "sighup"
l!l
261
MC/DC100%1/1
$Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$k} // "sighup"
$Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$k}
Truth table100%2/2
A
A= $Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$k}
Aresult
11
00
175 27 my $v = $want->{$k};
176 27 ▶ $v = _norm_val($v) if defined $s->{$k} && $s->{$k} =~ /\A(?:on|off)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $$s{$k} and $$s{$k} =~ /\A(?:on|off)\z/ 11 16 27
Condition66%2/3
defined $$s{$k} and $$s{$k} =~ /\A(?:on|off)\z/
!ll&&!rl&&r
01611
MC/DC50%1/2
defined $$s{$k} and $$s{$k} =~ /\A(?:on|off)\z/
defined $$s{$k} $$s{$k} =~ /\A(?:on|off)\z/
Truth table66%2/3
A and B
A= defined $$s{$k}B= $$s{$k} =~ /\A(?:on|off)\z/
ABresult
0X0
100
111
177 27 ▶ next if defined $s->{$k} && "$s->{$k}" eq "$v";
Branch: 1 branch
BranchTrueFalseTotal
if defined $$s{$k} and "$$s{$k}" eq "$v" 22 5 27
Condition66%2/3
defined $$s{$k} and "$$s{$k}" eq "$v"
!ll&&!rl&&r
0522
MC/DC50%1/2
defined $$s{$k} and "$$s{$k}" eq "$v"
defined $$s{$k} "$$s{$k}" eq "$v"
Truth table66%2/3
A and B
A= defined $$s{$k}B= "$$s{$k}" eq "$v"
ABresult
0X0
100
111
178 5 ▶ if ( $ctx eq 'postmaster' && !$restart ) { $pending{$k} = 1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx eq "postmaster" and not $restart) 2 3 5
Condition100%3/3
$ctx eq "postmaster" and not $restart
!ll&&!rl&&r
212
MC/DC100%2/2
$ctx eq "postmaster" and not $restart
$ctx eq "postmaster" not $restart
Truth table100%3/3
A and not(B)
A= $ctx eq "postmaster"B= not $restart
ABresult
0X0
100
111
179 3 ▶ $s->{$k} = $v =~ /\A\d+\z/ ? 0 + $v : $v;
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /\A\d+\z/ ? : 2 1 3
180 }
181 8 ▶ if ( %pending ) { $pg->{pending_restart} = [ sort keys %pending ] }
Branch: 1 branch
BranchTrueFalseTotal
if (%pending) { } 2 6 8
182 6 else { delete $pg->{pending_restart} }
183 8 my $hba = _file( $dev, $pg->{hba} );
184 8 ▶ $pg->{hba_loaded} = [ grep { length } map { s/#.*//r =~ s/\A\s+|\s+\z//gr =~ s/\s+/ /gr } split /\n/, $hba ] if defined $hba;
Branch: 1 branch
BranchTrueFalseTotal
if defined $hba 6 2 8
185 8 return;
186 }
187  
188  
189 9 ▶sub service_event {
Subroutine service_event: called CC=33 SCAR=42.6
Pod documented
190 9 my ( $dev, $name, $verb, $state, $host ) = @_;
191 9 my $pg = $dev->{postgres};
192 9 ▶ if ( $pg && ( $pg->{service} // '' ) eq $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pg and ($$pg{"service"} // "") eq $name) 7 2 9
Condition60%3/5
$pg and ($$pg{"service"} // "") eq $name
!ll&&!rl&&r
207
$$pg{"service"} // ""
l!l
70
MC/DC50%1/2
$pg and ($$pg{"service"} // "") eq $name
$pg $$pg{"service"}
Truth table66%2/3
A and B
A= $pgB= $$pg{"service"}
ABresult
0X0
100
111
193 7 ▶ if ( $verb eq 'reload' ) { _apply_config( $dev, 0 ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($verb eq 'reload') { } 4 3 7
elsif ($verb eq 'stop') { } 1 2 3
194 # Herunterfahren: Checkpoint, alle Verbindungen enden
195 1 ▶ elsif ( $verb eq 'stop' ) { _checkpoint( $pg, $dev ); $pg->{activity} = [] if @{ $pg->{activity} || [] } }
Branch: 1 branch
BranchTrueFalseTotal
if @{$$pg{"activity"} or [];} 1 0 1
Condition50%1/2
$$pg{'activity'} || []
l!l
10
MC/DC0%0/1
$$pg{'activity'} || []
$$pg{'activity'}
Truth table50%1/2
A
A= $$pg{'activity'}
Aresult
11
00
196 2 ▶ else { _checkpoint( $pg, $dev ); _apply_config( $dev, 1 ); $pg->{activity} = [] if @{ $pg->{activity} || [] } }
Branch: 1 branch
BranchTrueFalseTotal
if @{$$pg{"activity"} or [];} 1 1 2
Condition50%1/2
$$pg{'activity'} || []
l!l
20
MC/DC0%0/1
$$pg{'activity'} || []
$$pg{'activity'}
Truth table50%1/2
A
A= $$pg{'activity'}
Aresult
11
00
197 }
198 # Clients: ein Dienst mit pg_connect verbindet sich nach (Neu-)Start neu
199 9 ▶ my $svc = ( $dev->{services} || {} )->{$name} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $svc = ($$dev{"services"} || {})->{$name} or return 9 0 9
Condition50%1/2
$$dev{'services'} || {}
l!l
90
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
200 9 ▶ my $c = $svc->{pg_connect} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $c = $$svc{"pg_connect"} or return 2 7 9
201 2 ▶ my $srv = $state->{ $c->{server} // '' };
Condition50%1/2
$$c{"server"} // ""
l!l
20
MC/DC0%0/1
$$c{"server"} // ""
$$c{"server"}
Truth table50%1/2
A
A= $$c{"server"}
Aresult
11
00
202 2 ▶ return unless ref $srv eq 'HASH' && $srv->{postgres};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $srv eq "HASH" and $$srv{"postgres"} 0 2 2
Condition33%1/3
ref $srv eq "HASH" and $$srv{"postgres"}
!ll&&!rl&&r
002
MC/DC0%0/2
ref $srv eq "HASH" and $$srv{"postgres"}
ref $srv eq "HASH" $$srv{"postgres"}
Truth table33%1/3
A and B
A= ref $srv eq "HASH"B= $$srv{"postgres"}
ABresult
0X0
100
111
203 2 ▶ my $act = $srv->{postgres}{activity} //= [];
Condition50%1/2
$$srv{"postgres"}{"activity"} //= []
l!l
20
MC/DC0%0/1
$$srv{"postgres"}{"activity"} //= []
$$srv{"postgres"}{"activity"}
Truth table50%1/2
A
A= $$srv{"postgres"}{"activity"}
Aresult
11
00
204 2 ▶ my @keep = grep { !( ( $_->{host} // '' ) eq ( $host // '' ) && ( $_->{service} // '' ) eq $name ) } @$act;
Condition44%4/9
($$_{'host'} // '') eq ($host // '') && ($$_{'service'} // '') eq $name
!ll&&!rl&&r
002
$$_{"host"} // ""
l!l
20
$host // ""
l!l
20
$$_{"service"} // ""
l!l
20
MC/DC0%0/2
($$_{'host'} // '') eq ($host // '') && ($$_{'service'} // '') eq $name
$$_{"host"} $$_{"service"}
MC/DC0%0/1
$host // ""
$host
Truth table33%1/3
A && B
A= $$_{"host"}B= $$_{"service"}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $host
Aresult
11
00
205 2 ▶ @$act = @keep if @keep != @$act;
Branch: 1 branch
BranchTrueFalseTotal
if @keep != @$act 2 0 2
206 2 ▶ return if $verb eq 'stop';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "stop" 0 2 2
207 2 ▶ my $text = _file( $dev, $c->{file} ) // '';
Condition50%1/2
_file($dev, $$c{"file"}) // ""
l!l
20
MC/DC0%0/1
_file($dev, $$c{"file"}) // ""
_file($dev, $$c{"file"})
Truth table50%1/2
A
A= _file($dev, $$c{"file"})
Aresult
11
00
208 2 ▶ my ($port) = $c->{port_regex} && $text =~ /$c->{port_regex}/ ? ($1) : ( $c->{port} // 5432 );
Branch: 1 branch
BranchTrueFalseTotal
$$c{'port_regex'} && $text =~ /$$c{'port_regex'}/ ? : 2 0 2
Condition20%1/5
$$c{"port_regex"} and $text =~ /$$c{"port_regex"}/
!ll&&!rl&&r
002
$$c{"port"} // 5432
l!l
00
MC/DC0%0/2
$$c{"port_regex"} and $text =~ /$$c{"port_regex"}/
$$c{"port_regex"} $text =~ /$$c{"port_regex"}/
MC/DC0%0/1
$$c{"port"} // 5432
$$c{"port"}
Truth table33%1/3
A and B
A= $$c{"port_regex"}B= $text =~ /$$c{"port_regex"}/
ABresult
0X0
100
111
Truth table0%0/2
A
A= $$c{"port"}
Aresult
11
00
209 2 ▶ my $n = ( $c->{per_port} || {} )->{$port} // 0;
Condition50%2/4
($$c{"per_port"} || {})->{$port} // 0
l!l
20
$$c{'per_port'} || {}
l!l
20
MC/DC0%0/1
($$c{"per_port"} || {})->{$port} // 0
$$c{'per_port'}
Truth table50%1/2
A
A= $$c{'per_port'}
Aresult
11
00
210 push @$act, { pid => $c->{pid} // 5001, ( $n > 1 ? ( count => $n ) : () ), usename => $c->{user}, datname => $c->{db},
211 2 ▶ client_addr => $c->{addr}, application_name => $c->{application_name} // $name, state => 'idle', host => $host, service => $name } if $n;
Branch: 2 branches
BranchTrueFalseTotal
if $n 1 1 2
$n > 1 ? : 1 0 1
Condition40%2/5
$$c{"pid"} // 5001
l!l
10
$$c{"application_name"} // $name
l!l&&r!l&&!r
010
MC/DC0%0/1
$$c{"pid"} // 5001
$$c{"pid"}
MC/DC0%0/2
$$c{"application_name"} // $name
$$c{"application_name"} $name
Truth table50%1/2
A
A= $$c{"pid"}
Aresult
11
00
Truth table33%1/3
A // B
A= $$c{"application_name"}B= $name
ABresult
1X1
011
000
212 2 return;
213 }
214  
215 # Verbindungen: Eintraege mit count stehen fuer so viele gleiche ab pid.
216 102 ▶sub _activity_rows {
Subroutine _activity_rows: called CC=3 SCAR=11.0
217 102 my ($pg) = @_;
218 102 ▶ return map { my $a = $_; map { { %$a, pid => $a->{pid} + $_ } } 0 .. ( $a->{count} // 1 ) - 1 } @{ $pg->{activity} || [] };
Condition75%3/4
$$a{"count"} // 1
l!l
74560
$$pg{'activity'} || []
l!l
1020
MC/DC100%1/1
$$a{"count"} // 1
$$a{"count"}
MC/DC0%0/1
$$pg{'activity'} || []
$$pg{'activity'}
Truth table100%2/2
A
A= $$a{"count"}
Aresult
11
00
Truth table50%1/2
A
A= $$pg{'activity'}
Aresult
11
00
219 }
220  
221 62 ▶sub _activity_n { my ($pg) = @_; my $n = 0; $n += $_->{count} // 1 for @{ $pg->{activity} || [] }; return $n }
Subroutine _activity_n: called CC=4 SCAR=13.9
Condition75%3/4
$$pg{'activity'} || []
l!l
4814
$$_{"count"} // 1
l!l
430
MC/DC100%1/1
$$pg{'activity'} || []
$$pg{'activity'}
MC/DC0%0/1
$$_{"count"} // 1
$$_{"count"}
Truth table100%2/2
A
A= $$pg{'activity'}
Aresult
11
00
Truth table50%1/2
A
A= $$_{"count"}
Aresult
11
00
222  
223 # --- Rollen und Rechte --------------------------------------------------------
224  
225 277 ▶sub _role { my ( $pg, $r ) = @_; return $pg->{roles}{$r} }
Subroutine _role: called CC=1 SCAR=0.0
226  
227 214 ▶sub _is_super { my ( $pg, $r ) = @_; my $x = _role( $pg, $r ); return $x && $x->{superuser} ? 1 : 0 }
Subroutine _is_super: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
$x && $$x{'superuser'} ? : 202 12 214
Condition66%2/3
$x and $$x{"superuser"}
!ll&&!rl&&r
012202
MC/DC50%1/2
$x and $$x{"superuser"}
$x $$x{"superuser"}
Truth table66%2/3
A and B
A= $xB= $$x{"superuser"}
ABresult
0X0
100
111
228  
229 11 ▶sub _memberships {
Subroutine _memberships: called CC=6 SCAR=22.9
230 11 my ( $pg, $r ) = @_;
231 11 my %seen = ( $r => 1 );
232 11 my @todo = ($r);
233 11 ▶ while ( defined( my $x = shift @todo ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $x = shift @todo)) 11 11 22
234 11 ▶ for my $g ( sort keys %{ $pg->{members} || {} } ) {
Condition50%1/2
$$pg{'members'} || {}
l!l
011
MC/DC0%0/1
$$pg{'members'} || {}
$$pg{'members'}
Truth table50%1/2
A
A= $$pg{'members'}
Aresult
11
00
235 0 ▶ next unless grep { $_ eq $x } @{ $pg->{members}{$g} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $x;} @{$$pg{"members"}{$g};} 0 0 0
236 0 ▶ push @todo, $g unless $seen{$g}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$g}++ 0 0 0
237 }
238 }
239 11 return keys %seen;
240 }
241  
242 33 ▶sub _has_priv {
Subroutine _has_priv: called CC=14 SCAR=28.4
243 33 my ( $pg, $user, $obj, $priv ) = @_;
244 33 ▶ return 1 if _is_super( $pg, $user );
Branch: 1 branch
BranchTrueFalseTotal
if _is_super($pg, $user) 25 8 33
245 my $owner = $obj =~ /\Atable:(.+)\z/ ? ( $pg->{tables}{$1} || {} )->{owner}
246 : $obj =~ /\Aschema:(.+)\z/ ? ( $pg->{schemas}{$1} || {} )->{owner}
247 8 ▶ : $obj =~ /\Adatabase:(.+)\z/ ? ( $pg->{databases}{$1} || {} )->{owner} : undef;
Branch: 3 branches
BranchTrueFalseTotal
$obj =~ /\Atable:(.+)\z/ ? : 2 6 8
$obj =~ /\Aschema:(.+)\z/ ? : 1 5 6
$obj =~ /\Adatabase:(.+)\z/ ? : 5 0 5
Condition50%3/6
$$pg{'tables'}{$1} || {}
l!l
20
$$pg{'schemas'}{$1} || {}
l!l
10
$$pg{'databases'}{$1} || {}
l!l
50
MC/DC0%0/1
$$pg{'tables'}{$1} || {}
$$pg{'tables'}{$1}
MC/DC0%0/1
$$pg{'schemas'}{$1} || {}
$$pg{'schemas'}{$1}
MC/DC0%0/1
$$pg{'databases'}{$1} || {}
$$pg{'databases'}{$1}
Truth table50%1/2
A
A= $$pg{'tables'}{$1}
Aresult
11
00
Truth table50%1/2
A
A= $$pg{'schemas'}{$1}
Aresult
11
00
Truth table50%1/2
A
A= $$pg{'databases'}{$1}
Aresult
11
00
248 8 my @who = ( _memberships( $pg, $user ), 'PUBLIC' );
249 8 ▶ return 1 if defined $owner && grep { $_ eq $owner } @who;
Branch: 1 branch
BranchTrueFalseTotal
if defined $owner and grep {$_ eq $owner;} @who 0 8 8
Condition33%1/3
defined $owner and grep {$_ eq $owner;} @who
!ll&&!rl&&r
080
MC/DC0%0/2
defined $owner and grep {$_ eq $owner;} @who
defined $owner grep {$_ eq $owner;} @who
Truth table33%1/3
A and B
A= defined $ownerB= grep {$_ eq $owner;} @who
ABresult
0X0
100
111
250 8 ▶ my $g = ( $pg->{grants} || {} )->{$obj} || {};
Condition50%2/4
($$pg{'grants'} || {})->{$obj} || {}
l!l
80
$$pg{'grants'} || {}
l!l
80
MC/DC0%0/1
($$pg{'grants'} || {})->{$obj} || {}
$$pg{'grants'}
Truth table50%1/2
A
A= $$pg{'grants'}
Aresult
11
00
251 8 ▶ return scalar grep { my $w = $_; grep { $_ eq $priv || $_ eq 'ALL' } @{ $g->{$w} || [] } } @who;
Condition80%4/5
$_ eq $priv || $_ eq 'ALL'
l!l&&r!l&&!r
702
$$g{$w} || []
l!l
88
MC/DC50%1/2
$_ eq $priv || $_ eq 'ALL'
$_ eq $priv $_ eq 'ALL'
MC/DC100%1/1
$$g{$w} || []
$$g{$w}
Truth table66%2/3
A || B
A= $_ eq $privB= $_ eq 'ALL'
ABresult
1X1
011
000
Truth table100%2/2
A
A= $$g{$w}
Aresult
11
00
252 }
253  
254 # --- Verbindung ---------------------------------------------------------------
255  
256 26 ▶sub _ip_of {
Subroutine _ip_of: called CC=7 SCAR=22.5
257 26 my ($dev) = @_;
258 26 ▶ for my $i ( sort keys %{ $dev->{interfaces} || {} } ) {
Condition50%1/2
$$dev{'interfaces'} || {}
l!l
260
MC/DC0%0/1
$$dev{'interfaces'} || {}
$$dev{'interfaces'}
Truth table50%1/2
A
A= $$dev{'interfaces'}
Aresult
11
00
259 26 ▶ next if $i eq 'lo';
Branch: 1 branch
BranchTrueFalseTotal
if $i eq "lo" 0 26 26
260 26 ▶ my ($a) = @{ $dev->{interfaces}{$i}{addr} || [] };
Condition50%1/2
$$dev{'interfaces'}{$i}{'addr'} || []
l!l
260
MC/DC0%0/1
$$dev{'interfaces'}{$i}{'addr'} || []
$$dev{'interfaces'}{$i}{'addr'}
Truth table50%1/2
A
A= $$dev{'interfaces'}{$i}{'addr'}
Aresult
11
00
261 26 ▶ return $1 if defined $a && $a =~ m{\A([\d.]+)/};
Branch: 1 branch
BranchTrueFalseTotal
if defined $a and $a =~ m[\A([\d.]+)/] 26 0 26
Condition33%1/3
defined $a and $a =~ m[\A([\d.]+)/]
!ll&&!rl&&r
0026
MC/DC0%0/2
defined $a and $a =~ m[\A([\d.]+)/]
defined $a $a =~ m[\A([\d.]+)/]
Truth table33%1/3
A and B
A= defined $aB= $a =~ m[\A([\d.]+)/]
ABresult
0X0
100
111
262 }
263 0 return '127.0.0.1';
264 }
265  
266 11 ▶sub _in_cidr {
Subroutine _in_cidr: called CC=5 SCAR=17.0
267 11 my ( $ip, $cidr ) = @_;
268 11 my ( $net, $len ) = split m{/}, $cidr;
269 11 ▶ $len //= 32;
Condition50%1/2
$len //= 32
l!l
110
MC/DC0%0/1
$len //= 32
$len
Truth table50%1/2
A
A= $len
Aresult
11
00
270 11 ▶ my $n = sub { my $x = 0; $x = $x * 256 + $_ for split /\./, $_[0]; $x };
Subroutine __ANON__: called CC=2 SCAR=6.9
271 11 ▶ return 0 unless $ip =~ /\A[\d.]+\z/ && $net =~ /\A[\d.]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $ip =~ /\A[\d.]+\z/ and $net =~ /\A[\d.]+\z/ 0 11 11
Condition33%1/3
$ip =~ /\A[\d.]+\z/ and $net =~ /\A[\d.]+\z/
!ll&&!rl&&r
0011
MC/DC0%0/2
$ip =~ /\A[\d.]+\z/ and $net =~ /\A[\d.]+\z/
$ip =~ /\A[\d.]+\z/ $net =~ /\A[\d.]+\z/
Truth table33%1/3
A and B
A= $ip =~ /\A[\d.]+\z/B= $net =~ /\A[\d.]+\z/
ABresult
0X0
100
111
272 11 ▶ my $mask = $len ? ( 0xffffffff << ( 32 - $len ) ) & 0xffffffff : 0;
Branch: 1 branch
BranchTrueFalseTotal
$len ? : 11 0 11
273 11 return ( $n->($ip) & $mask ) == ( $n->($net) & $mask );
274 }
275  
276 # erste passende pg_hba-Zeile: ( methode, zeilennummer ) oder ()
277 67 ▶sub _hba_match {
Subroutine _hba_match: called CC=25 SCAR=38.4
278 67 my ( $pg, $kind, $db, $user, $ip ) = @_;
279 67 my $i = 0;
280 67 ▶ for my $l ( @{ $pg->{hba_loaded} || [] } ) {
Condition50%1/2
$$pg{'hba_loaded'} || []
l!l
670
MC/DC0%0/1
$$pg{'hba_loaded'} || []
$$pg{'hba_loaded'}
Truth table50%1/2
A
A= $$pg{'hba_loaded'}
Aresult
11
00
281 87 $i++;
282 87 my @f = split / /, $l;
283 87 my $type = shift @f;
284 87 ▶ next unless $kind eq 'local' ? $type eq 'local' : $type =~ /\Ahost(?:ssl)?\z/;
Branch: 2 branches
BranchTrueFalseTotal
unless $kind eq "local" ? $type eq "local" : $type =~ /\Ahost(?:ssl)?\z/ 10 77 87
$kind eq 'local' ? : 66 21 87
285 77 my ( $dbs, $users ) = ( shift @f, shift @f );
286 77 ▶ my $addr = $type eq 'local' ? undef : shift @f;
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'local' ? : 66 11 77
287 77 ▶ $addr .= '/' . _masklen( shift @f ) if defined $addr && $addr !~ m{/|\A(?:all|samehost|samenet)\z} && @f && $f[0] =~ /\A\d+\.\d+\.\d+\.\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $addr and not $addr =~ m[/|\A(?:all|samehost|samenet)\z] and @f and $f[0] =~ /\A\d+\.\d+\.\d+\.\d+\z/ 0 77 77
Condition44%4/9
defined $addr and not $addr =~ m[/|\A(?:all|samehost|samenet)\z] and @f and $f[0] =~ /\A\d+\.\d+\.\d+\.\d+\z/
!ll&&!rl&&r
7700
defined $addr and not $addr =~ m[/|\A(?:all|samehost|samenet)\z] and @f
!ll&&!rl&&r
7700
defined $addr and not $addr =~ m[/|\A(?:all|samehost|samenet)\z]
!ll&&!rl&&r
66110
MC/DC0%0/4
defined $addr and not $addr =~ m[/|\A(?:all|samehost|samenet)\z] and @f and $f[0] =~ /\A\d+\.\d+\.\d+\.\d+\z/
defined $addr not $addr =~ m[/|\A(?:all|samehost|samenet)\z] @f $f[0] =~ /\A\d+\.\d+\.\d+\.\d+\z/
Truth table40%2/5
A and not(B) and C and D
A= defined $addrB= not $addr =~ m[/|\A(?:all|samehost|samenet)\z]C= @fD= $f[0] =~ /\A\d+\.\d+\.\d+\.\d+\z/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
288 77 ▶ my $method = shift(@f) // 'reject';
Condition50%1/2
shift @f // "reject"
l!l
770
MC/DC0%0/1
shift @f // "reject"
shift @f
Truth table50%1/2
A
A= shift @f
Aresult
11
00
289 77 ▶ next unless grep { $_ eq 'all' || $_ eq $db || ( $_ eq 'sameuser' && $db eq $user ) } split /,/, $dbs;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "all" or $_ eq $db or $_ eq "sameuser" and $db eq $user;} split(/,/, $dbs, 0) 0 77 77
Condition33%3/9
$_ eq 'all' || $_ eq $db || $_ eq 'sameuser' && $db eq $user
l!l&&r!l&&!r
7700
$_ eq "all" or $_ eq $db
l!l&&r!l&&!r
7520
$_ eq "sameuser" and $db eq $user
!ll&&!rl&&r
000
MC/DC0%0/4
$_ eq 'all' || $_ eq $db || $_ eq 'sameuser' && $db eq $user
$_ eq "all" $_ eq $db $_ eq "sameuser" $db eq $user
Truth table40%2/5
A or B || C and D
A= $_ eq "all"B= $_ eq $dbC= $_ eq "sameuser"D= $db eq $user
ABCDresult
1XXX1
01XX1
00111
000X0
00100
290 0 ▶ next unless grep { $_ eq 'all' || $_ eq $user || ( /\A\+(.+)\z/ && grep { $_ eq $1 } _memberships( $pg, $user ) ) } split /,/, $users;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "all" or $_ eq $user or /\A\+(.+)\z/ and grep {$_ eq $1;} _memberships($pg, $user);} split(/,/, $users, 0) 4 73 77
Condition66%6/9
$_ eq 'all' || $_ eq $user || /\A\+(.+)\z/ && grep({$_ eq $1;} _memberships($pg, $user))
l!l&&r!l&&!r
7304
$_ eq "all" or $_ eq $user
l!l&&r!l&&!r
13604
/\A\+(.+)\z/ and grep {$_ eq $1;} _memberships($pg, $user)
!ll&&!rl&&r
400
MC/DC50%2/4
$_ eq 'all' || $_ eq $user || /\A\+(.+)\z/ && grep({$_ eq $1;} _memberships($pg, $user))
$_ eq "all" $_ eq $user /\A\+(.+)\z/ grep {$_ eq $1;} _memberships($pg, $user)
Truth table60%3/5
A or B || C and D
A= $_ eq "all"B= $_ eq $userC= /\A\+(.+)\z/D= grep {$_ eq $1;} _memberships($pg, $user)
ABCDresult
1XXX1
01XX1
00111
000X0
00100
291 73 ▶ if ( defined $addr ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $addr) 11 62 73
292 11 ▶ next unless $addr eq 'all' || $addr eq 'samehost' && $ip eq '127.0.0.1' || $addr =~ m{/} && _in_cidr( $ip, $addr );
Branch: 1 branch
BranchTrueFalseTotal
unless $addr eq "all" or $addr eq "samehost" and $ip eq "127.0.0.1" or $addr =~ m[/] and _in_cidr($ip, $addr) 6 5 11
Condition50%6/12
$addr eq "all" or $addr eq "samehost" and $ip eq "127.0.0.1" or $addr =~ m[/] and _in_cidr($ip, $addr)
l!l&&r!l&&!r
056
$addr eq "all" or $addr eq "samehost" and $ip eq "127.0.0.1"
l!l&&r!l&&!r
0011
$addr eq "samehost" and $ip eq "127.0.0.1"
!ll&&!rl&&r
1100
$addr =~ m[/] and _in_cidr($ip, $addr)
!ll&&!rl&&r
065
MC/DC20%1/5
$addr eq "all" or $addr eq "samehost" and $ip eq "127.0.0.1" or $addr =~ m[/] and _in_cidr($ip, $addr)
$addr eq "all" $addr eq "samehost" $ip eq "127.0.0.1" $addr =~ m[/] _in_cidr($ip, $addr)
Truth table25%2/8
A or B and C or D and E
A= $addr eq "all"B= $addr eq "samehost"C= $ip eq "127.0.0.1"D= $addr =~ m[/]E= _in_cidr($ip, $addr)
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
293 }
294 67 return ( $method, $i );
295 }
296 0 return ();
297 }
298  
299 0 ▶sub _masklen { my ($m) = @_; my $n = 0; $n += unpack( '%32b*', pack( 'C', $_ ) ) for split /\./, $m; return $n }
Subroutine _masklen: not called CC=2 SCAR=17.9
300  
301 # Verbindung aufbauen: ( undef, $sitzung ) oder ( fehlertext )
302 67 ▶sub _connect {
Subroutine _connect: called CC=34 SCAR=41.2
303 67 my ( $srv, $o ) = @_;
304 67 my $pg = $srv->{postgres};
305 67 ▶ my $svc = ( $srv->{services} || {} )->{ $pg->{service} // '' };
Condition50%2/4
$$srv{'services'} || {}
l!l
670
$$pg{"service"} // ""
l!l
670
MC/DC0%0/1
$$srv{'services'} || {}
$$srv{'services'}
MC/DC0%0/1
$$pg{"service"} // ""
$$pg{"service"}
Truth table50%1/2
A
A= $$srv{'services'}
Aresult
11
00
Truth table50%1/2
A
A= $$pg{"service"}
Aresult
11
00
306 my $where = $o->{remote}
307 67 ▶ ? qq{connection to server at "$o->{hostname}" ($o->{server_ip}), port $o->{port} failed}
Branch: 1 branch
BranchTrueFalseTotal
$$o{'remote'} ? : 5 62 67
308 : qq{connection to server on socket "/var/run/postgresql/.s.PGSQL.$o->{port}" failed};
309 return "psql: error: $where: Connection refused\n\tIs the server running on that host and accepting TCP/IP connections?"
310 67 ▶ if $o->{remote} && !( $svc && $svc->{active} );
Branch: 1 branch
BranchTrueFalseTotal
if $$o{"remote"} and not $svc && $$svc{"active"} 0 67 67
Condition50%3/6
$$o{"remote"} and not $svc && $$svc{"active"}
!ll&&!rl&&r
6250
$svc && $$svc{'active'}
!ll&&!rl&&r
005
MC/DC0%0/3
$$o{"remote"} and not $svc && $$svc{"active"}
$$o{"remote"} $svc $$svc{'active'}
Truth table50%2/4
A and not(B && C)
A= $$o{"remote"}B= $svcC= $$svc{'active'}
ABCresult
0XX0
1110
10X1
1101
311 return "psql: error: $where: No such file or directory\n\tIs the server running locally and accepting connections on that socket?"
312 67 ▶ unless $svc && $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $svc and $$svc{"active"} 0 67 67
Condition33%1/3
$svc and $$svc{"active"}
!ll&&!rl&&r
0067
MC/DC0%0/2
$svc and $$svc{"active"}
$svc $$svc{"active"}
Truth table33%1/3
A and B
A= $svcB= $$svc{"active"}
ABresult
0X0
100
111
313 67 my ( $user, $db ) = ( $o->{user}, $o->{db} );
314 67 ▶ my $enc = $o->{remote} ? 'SSL encryption' : 'no encryption';
Branch: 1 branch
BranchTrueFalseTotal
$$o{'remote'} ? : 5 62 67
315 67 ▶ my ( $method ) = _hba_match( $pg, $o->{remote} ? 'host' : 'local', $db, $user, $o->{client_ip} );
Branch: 1 branch
BranchTrueFalseTotal
$$o{'remote'} ? : 5 62 67
316 67 ▶ my $who = $o->{remote} ? qq{host "$o->{client_ip}", } : '';
Branch: 1 branch
BranchTrueFalseTotal
$$o{'remote'} ? : 5 62 67
317 67 ▶ return qq{psql: error: $where: FATAL: no pg_hba.conf entry for ${who}user "$user", database "$db", $enc} unless $method;
Branch: 1 branch
BranchTrueFalseTotal
unless $method 0 67 67
318 67 ▶ return qq{psql: error: $where: FATAL: pg_hba.conf rejects connection for ${who}user "$user", database "$db", $enc}
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "reject" 4 63 67
319 if $method eq 'reject';
320 63 my $role = _role( $pg, $user );
321 63 ▶ if ( $method eq 'peer' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($method eq 'peer') { } 59 4 63
elsif ($method =~ /\A(?:md5|scram-sha-256|password)\z/) { } 1 3 4
322 59 ▶ return qq{psql: error: $where: FATAL: role "$user" does not exist} unless $role;
Branch: 1 branch
BranchTrueFalseTotal
unless $role 1 58 59
323 58 ▶ return qq{psql: error: $where: FATAL: Peer authentication failed for user "$user"} if ( $o->{os_user} // 'root' ) ne $user;
Branch: 1 branch
BranchTrueFalseTotal
if ($$o{"os_user"} // "root") ne $user 0 58 58
Condition50%1/2
$$o{"os_user"} // "root"
l!l
580
MC/DC0%0/1
$$o{"os_user"} // "root"
$$o{"os_user"}
Truth table50%1/2
A
A= $$o{"os_user"}
Aresult
11
00
324 }
325 elsif ( $method =~ /\A(?:md5|scram-sha-256|password)\z/ ) {
326 1 ▶ return qq{psql: error: $where: FATAL: password authentication failed for user "$user"} unless $role && $role->{password};
Branch: 1 branch
BranchTrueFalseTotal
unless $role and $$role{"password"} 0 1 1
Condition33%1/3
$role and $$role{"password"}
!ll&&!rl&&r
001
MC/DC0%0/2
$role and $$role{"password"}
$role $$role{"password"}
Truth table33%1/3
A and B
A= $roleB= $$role{"password"}
ABresult
0X0
100
111
327 }
328 62 ▶ return qq{psql: error: $where: FATAL: role "$user" does not exist} unless $role;
Branch: 1 branch
BranchTrueFalseTotal
unless $role 0 62 62
329 62 ▶ return qq{psql: error: $where: FATAL: role "$user" is not permitted to log in} unless $role->{login} || $role->{superuser};
Branch: 1 branch
BranchTrueFalseTotal
unless $$role{"login"} or $$role{"superuser"} 0 62 62
Condition33%1/3
$$role{"login"} or $$role{"superuser"}
l!l&&r!l&&!r
6200
MC/DC0%0/2
$$role{"login"} or $$role{"superuser"}
$$role{"login"} $$role{"superuser"}
Truth table33%1/3
A or B
A= $$role{"login"}B= $$role{"superuser"}
ABresult
1X1
011
000
330 62 ▶ return qq{psql: error: $where: FATAL: database "$db" does not exist} unless ( $pg->{databases} || {} )->{$db} || $db eq 'postgres';
Branch: 1 branch
BranchTrueFalseTotal
unless ($$pg{"databases"} || {})->{$db} or $db eq "postgres" 0 62 62
Condition60%3/5
($$pg{"databases"} || {})->{$db} or $db eq "postgres"
l!l&&r!l&&!r
29330
$$pg{'databases'} || {}
l!l
620
MC/DC0%0/2
($$pg{"databases"} || {})->{$db} or $db eq "postgres"
$$pg{'databases'} $db eq "postgres"
Truth table33%1/3
A or B
A= $$pg{'databases'}B= $db eq "postgres"
ABresult
1X1
011
000
331 62 my $n = _activity_n($pg);
332 62 ▶ my $max = $pg->{settings}{max_connections} // 100;
Condition50%1/2
$$pg{"settings"}{"max_connections"} // 100
l!l
620
MC/DC0%0/1
$$pg{"settings"}{"max_connections"} // 100
$$pg{"settings"}{"max_connections"}
Truth table50%1/2
A
A= $$pg{"settings"}{"max_connections"}
Aresult
11
00
333 62 ▶ my $res = $pg->{settings}{superuser_reserved_connections} // 3;
Condition100%2/2
$$pg{"settings"}{"superuser_reserved_connections"} // 3
l!l
4517
MC/DC100%1/1
$$pg{"settings"}{"superuser_reserved_connections"} // 3
$$pg{"settings"}{"superuser_reserved_connections"}
Truth table100%2/2
A
A= $$pg{"settings"}{"superuser_reserved_connections"}
Aresult
11
00
334 62 ▶ return "psql: error: $where: FATAL: sorry, too many clients already" if $n >= $max;
Branch: 1 branch
BranchTrueFalseTotal
if $n >= $max 0 62 62
335 return "psql: error: $where: FATAL: remaining connection slots are reserved for non-replication superuser connections"
336 62 ▶ if $n >= $max - $res && !$role->{superuser};
Branch: 1 branch
BranchTrueFalseTotal
if $n >= $max - $res and not $$role{"superuser"} 0 62 62
Condition33%1/3
$n >= $max - $res and not $$role{"superuser"}
!ll&&!rl&&r
6200
MC/DC0%0/2
$n >= $max - $res and not $$role{"superuser"}
$n >= $max - $res not $$role{"superuser"}
Truth table33%1/3
A and not(B)
A= $n >= $max - $resB= not $$role{"superuser"}
ABresult
0X0
100
111
337 62 ▶ return qq{psql: error: $where: FATAL: permission denied for database "$db"\nDETAIL: User does not have CONNECT privilege.}
Branch: 1 branch
BranchTrueFalseTotal
if $db ne "postgres" and not _has_priv($pg, $user, "database:$db", "CONNECT") 0 62 62
Condition66%2/3
$db ne "postgres" and not _has_priv($pg, $user, "database:$db", "CONNECT")
!ll&&!rl&&r
33290
MC/DC0%0/2
$db ne "postgres" and not _has_priv($pg, $user, "database:$db", "CONNECT")
$db ne "postgres" not _has_priv($pg, $user, "database:$db", "CONNECT")
Truth table66%2/3
A and not(B)
A= $db ne "postgres"B= not _has_priv($pg, $user, "database:$db", "CONNECT")
ABresult
0X0
100
111
338 if $db ne 'postgres' && !_has_priv( $pg, $user, "database:$db", 'CONNECT' );
339 62 return ( undef, { user => $user, db => $db } );
340 }
341  
342  
343 67 ▶sub psql {
Subroutine psql: called CC=82 SCAR=65.6
Pod documented
344 67 my ( $dev, $av, $ctx, $os_user ) = @_;
345 67 ▶ $os_user //= 'root';
Condition50%1/2
$os_user //= "root"
l!l
670
MC/DC0%0/1
$os_user //= "root"
$os_user
Truth table50%1/2
A
A= $os_user
Aresult
11
00
346 67 my %o = ( user => $os_user, port => 5432 );
347 67 my ( @cmds, $list, %fmt, $db );
348 67 my @a = @$av;
349 67 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 146 67 213
350 146 my $x = shift @a;
351 146 ▶ if ( $x eq '-c' || $x eq '--command' ) { push @cmds, shift(@a) // '' }
Branch: 19 branches
BranchTrueFalseTotal
if ($x eq '-c' or $x eq '--command') { } 73 73 146
elsif ($x =~ /\A--command=(.*)\z/s) { } 0 73 73
elsif ($x =~ /\A-c(.+)\z/s) { } 0 73 73
elsif ($x eq '-U' or $x eq '--username') { } 8 65 73
elsif ($x =~ /\A-U(.+)\z/ or $x =~ /\A--username=(.+)\z/) { } 0 65 65
elsif ($x eq '-d' or $x eq '--dbname') { } 27 38 65
elsif ($x =~ /\A-d(.+)\z/ or $x =~ /\A--dbname=(.+)\z/) { } 0 38 38
elsif ($x eq '-h' or $x eq '--host') { } 5 33 38
elsif ($x =~ /\A-h(.+)\z/ or $x =~ /\A--host=(.+)\z/) { } 0 33 33
elsif ($x eq '-p' or $x eq '--port') { } 0 33 33
elsif ($x =~ /\A-p(\d+)\z/ or $x =~ /\A--port=(\d+)\z/) { } 0 33 33
elsif ($x eq '-l' or $x eq '--list') { } 0 33 33
elsif ($x eq '-f' or $x eq '--file') { } 0 33 33
elsif ($x =~ /\A-([tAxXqwW]+)\z/) { } 27 6 33
elsif ($x =~ /\A--(?:tuples-only|no-align|expanded|no-psqlrc|quiet)\z/) { } 0 6 6
elsif ($x =~ /\A-v\z|\A--set\z/) { } 0 6 6
elsif ($x =~ m[\Apostgres(?:ql)?://(?:([^:\@/]+)(?::[^\@/]*)?@)?([^:/?]+)?(?::(\d+))?(?:/([^?]+))?]) { } 0 6 6
elsif ($x =~ /\A\s*\w+\s*=/ and not $x =~ /\A-/) { } 1 5 6
elsif (not $x =~ /\A-/) { } 5 0 5
Condition60%3/5
$x eq "-c" or $x eq "--command"
l!l&&r!l&&!r
73073
shift @a // ""
l!l
730
MC/DC50%1/2
$x eq "-c" or $x eq "--command"
$x eq "-c" $x eq "--command"
MC/DC0%0/1
shift @a // ""
shift @a
Truth table66%2/3
A or B
A= $x eq "-c"B= $x eq "--command"
ABresult
1X1
011
000
Truth table50%1/2
A
A= shift @a
Aresult
11
00
352 0 elsif ( $x =~ /\A--command=(.*)\z/s ) { push @cmds, $1 }
353 0 elsif ( $x =~ /\A-c(.+)\z/s ) { push @cmds, $1 }
354 8 ▶ elsif ( $x eq '-U' || $x eq '--username' ) { $o{user} = shift @a }
Condition66%2/3
$x eq "-U" or $x eq "--username"
l!l&&r!l&&!r
8065
MC/DC50%1/2
$x eq "-U" or $x eq "--username"
$x eq "-U" $x eq "--username"
Truth table66%2/3
A or B
A= $x eq "-U"B= $x eq "--username"
ABresult
1X1
011
000
355 0 ▶ elsif ( $x =~ /\A-U(.+)\z/ || $x =~ /\A--username=(.+)\z/ ) { $o{user} = $1 }
Condition33%1/3
$x =~ /\A-U(.+)\z/ or $x =~ /\A--username=(.+)\z/
l!l&&r!l&&!r
0065
MC/DC0%0/2
$x =~ /\A-U(.+)\z/ or $x =~ /\A--username=(.+)\z/
$x =~ /\A-U(.+)\z/ $x =~ /\A--username=(.+)\z/
Truth table33%1/3
A or B
A= $x =~ /\A-U(.+)\z/B= $x =~ /\A--username=(.+)\z/
ABresult
1X1
011
000
356 27 ▶ elsif ( $x eq '-d' || $x eq '--dbname' ) { $db = shift @a }
Condition66%2/3
$x eq "-d" or $x eq "--dbname"
l!l&&r!l&&!r
27038
MC/DC50%1/2
$x eq "-d" or $x eq "--dbname"
$x eq "-d" $x eq "--dbname"
Truth table66%2/3
A or B
A= $x eq "-d"B= $x eq "--dbname"
ABresult
1X1
011
000
357 0 ▶ elsif ( $x =~ /\A-d(.+)\z/ || $x =~ /\A--dbname=(.+)\z/ ) { $db = $1 }
Condition33%1/3
$x =~ /\A-d(.+)\z/ or $x =~ /\A--dbname=(.+)\z/
l!l&&r!l&&!r
0038
MC/DC0%0/2
$x =~ /\A-d(.+)\z/ or $x =~ /\A--dbname=(.+)\z/
$x =~ /\A-d(.+)\z/ $x =~ /\A--dbname=(.+)\z/
Truth table33%1/3
A or B
A= $x =~ /\A-d(.+)\z/B= $x =~ /\A--dbname=(.+)\z/
ABresult
1X1
011
000
358 5 ▶ elsif ( $x eq '-h' || $x eq '--host' ) { $o{host} = shift @a }
Condition66%2/3
$x eq "-h" or $x eq "--host"
l!l&&r!l&&!r
5033
MC/DC50%1/2
$x eq "-h" or $x eq "--host"
$x eq "-h" $x eq "--host"
Truth table66%2/3
A or B
A= $x eq "-h"B= $x eq "--host"
ABresult
1X1
011
000
359 0 ▶ elsif ( $x =~ /\A-h(.+)\z/ || $x =~ /\A--host=(.+)\z/ ) { $o{host} = $1 }
Condition33%1/3
$x =~ /\A-h(.+)\z/ or $x =~ /\A--host=(.+)\z/
l!l&&r!l&&!r
0033
MC/DC0%0/2
$x =~ /\A-h(.+)\z/ or $x =~ /\A--host=(.+)\z/
$x =~ /\A-h(.+)\z/ $x =~ /\A--host=(.+)\z/
Truth table33%1/3
A or B
A= $x =~ /\A-h(.+)\z/B= $x =~ /\A--host=(.+)\z/
ABresult
1X1
011
000
360 0 ▶ elsif ( $x eq '-p' || $x eq '--port' ) { $o{port} = shift @a }
Condition33%1/3
$x eq "-p" or $x eq "--port"
l!l&&r!l&&!r
0033
MC/DC0%0/2
$x eq "-p" or $x eq "--port"
$x eq "-p" $x eq "--port"
Truth table33%1/3
A or B
A= $x eq "-p"B= $x eq "--port"
ABresult
1X1
011
000
361 0 ▶ elsif ( $x =~ /\A-p(\d+)\z/ || $x =~ /\A--port=(\d+)\z/ ) { $o{port} = $1 }
Condition33%1/3
$x =~ /\A-p(\d+)\z/ or $x =~ /\A--port=(\d+)\z/
l!l&&r!l&&!r
0033
MC/DC0%0/2
$x =~ /\A-p(\d+)\z/ or $x =~ /\A--port=(\d+)\z/
$x =~ /\A-p(\d+)\z/ $x =~ /\A--port=(\d+)\z/
Truth table33%1/3
A or B
A= $x =~ /\A-p(\d+)\z/B= $x =~ /\A--port=(\d+)\z/
ABresult
1X1
011
000
362 0 ▶ elsif ( $x eq '-l' || $x eq '--list' ) { $list = 1 }
Condition33%1/3
$x eq "-l" or $x eq "--list"
l!l&&r!l&&!r
0033
MC/DC0%0/2
$x eq "-l" or $x eq "--list"
$x eq "-l" $x eq "--list"
Truth table33%1/3
A or B
A= $x eq "-l"B= $x eq "--list"
ABresult
1X1
011
000
363 0 ▶ elsif ( $x eq '-f' || $x eq '--file' ) { push @GAPS, 'psql -f'; return ( '', 0 ) }
Condition33%1/3
$x eq "-f" or $x eq "--file"
l!l&&r!l&&!r
0033
MC/DC0%0/2
$x eq "-f" or $x eq "--file"
$x eq "-f" $x eq "--file"
Truth table33%1/3
A or B
A= $x eq "-f"B= $x eq "--file"
ABresult
1X1
011
000
364 27 elsif ( $x =~ /\A-([tAxXqwW]+)\z/ ) { $fmt{$_} = 1 for split //, $1 }
365 0 ▶ elsif ( $x =~ /\A--(?:tuples-only|no-align|expanded|no-psqlrc|quiet)\z/ ) { $fmt{ { 'tuples-only' => 't', 'no-align' => 'A', expanded => 'x' }->{ substr $x, 2 } // 'X' } = 1 }
Condition0%0/2
{"tuples-only", "t", "no-align", "A", "expanded", "x"}->{substr $x, 2} // "X"
l!l
00
MC/DC0%0/1
{"tuples-only", "t", "no-align", "A", "expanded", "x"}->{substr $x, 2} // "X"
{"tuples-only", "t", "no-align", "A", "expanded", "x"}->{substr $x, 2}
Truth table0%0/2
A
A= {"tuples-only", "t", "no-align", "A", "expanded", "x"}->{substr $x, 2}
Aresult
11
00
366 0 elsif ( $x =~ /\A-v\z|\A--set\z/ ) { shift @a }
367 elsif ( $x =~ /\Apostgres(?:ql)?:\/\/(?:([^:@\/]+)(?::[^@\/]*)?@)?([^:\/?]+)?(?::(\d+))?(?:\/([^?]+))?/ ) {
368 0 ▶ $o{user} = $1 if defined $1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $1 0 0 0
369 0 ▶ $o{host} = $2 if defined $2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $2 0 0 0
370 0 ▶ $o{port} = $3 if defined $3;
Branch: 1 branch
BranchTrueFalseTotal
if defined $3 0 0 0
371 0 ▶ $db = $4 if defined $4;
Branch: 1 branch
BranchTrueFalseTotal
if defined $4 0 0 0
372 }
373 ▶ elsif ( $x =~ /\A\s*\w+\s*=/ && $x !~ /\A-/ ) { # libpq: "host=db1 dbname=appdb user=report"
Condition66%2/3
$x =~ /\A\s*\w+\s*=/ and not $x =~ /\A-/
!ll&&!rl&&r
501
MC/DC50%1/2
$x =~ /\A\s*\w+\s*=/ and not $x =~ /\A-/
$x =~ /\A\s*\w+\s*=/ not $x =~ /\A-/
Truth table66%2/3
A and not(B)
A= $x =~ /\A\s*\w+\s*=/B= not $x =~ /\A-/
ABresult
0X0
100
111
374 1 my %kv = $x =~ /(\w+)\s*=\s*('(?:[^'\\]|\\.)*'|\S*)/g;
375 1 s/\A'|'\z//g for values %kv;
376 1 ▶ $o{host} = $kv{host} // $kv{hostaddr} if defined( $kv{host} // $kv{hostaddr} );
Branch: 1 branch
BranchTrueFalseTotal
if defined($kv{"host"} // $kv{"hostaddr"}) 0 1 1
Condition16%1/6
$kv{"host"} // $kv{"hostaddr"}
l!l&&r!l&&!r
001
$kv{"host"} // $kv{"hostaddr"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$kv{"host"} // $kv{"hostaddr"}
$kv{"host"} $kv{"hostaddr"}
MC/DC0%0/2
$kv{"host"} // $kv{"hostaddr"}
$kv{"host"} $kv{"hostaddr"}
Truth table33%1/3
A // B
A= $kv{"host"}B= $kv{"hostaddr"}
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $kv{"host"}B= $kv{"hostaddr"}
ABresult
1X1
011
000
377 1 ▶ $o{port} = $kv{port} if defined $kv{port};
Branch: 1 branch
BranchTrueFalseTotal
if defined $kv{"port"} 0 1 1
378 1 ▶ $o{user} = $kv{user} if defined $kv{user};
Branch: 1 branch
BranchTrueFalseTotal
if defined $kv{"user"} 1 0 1
379 1 ▶ $db = $kv{dbname} if defined $kv{dbname};
Branch: 1 branch
BranchTrueFalseTotal
if defined $kv{"dbname"} 1 0 1
380 }
381 0 ▶ elsif ( $x !~ /\A-/ ) { if ( !defined $db ) { $db = $x } else { $o{user} = $x } }
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $db) { } 5 0 5
382 0 else { return ( "psql: error: unrecognized option '$x'\nTry \"psql --help\" for more information.", 0 ) }
383 }
384 0 ▶ if ( !@cmds && !$list ) { push @GAPS, 'psql (interaktiv)'; return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (@cmds or $list) 0 67 67
Condition33%1/3
@cmds or $list
l!l&&r!l&&!r
6700
MC/DC0%0/2
@cmds or $list
@cmds $list
Truth table33%1/3
A or B
A= @cmdsB= $list
ABresult
1X1
011
000
385 67 ▶ $o{db} = $db // $o{user};
Condition66%2/3
$db // $o{"user"}
l!l&&r!l&&!r
33340
MC/DC0%0/2
$db // $o{"user"}
$db $o{"user"}
Truth table66%2/3
A // B
A= $dbB= $o{"user"}
ABresult
1X1
011
000
386 67 ▶ $o{db} = 'postgres' if $list && !defined $db;
Branch: 1 branch
BranchTrueFalseTotal
if $list and not defined $db 0 67 67
Condition33%1/3
$list and not defined $db
!ll&&!rl&&r
6700
MC/DC0%0/2
$list and not defined $db
$list not defined $db
Truth table33%1/3
A and not(B)
A= $listB= not defined $db
ABresult
0X0
100
111
387 67 $o{os_user} = $os_user;
388  
389 # Ziel: eigener Server (Socket oder eigene Adresse) oder ein anderes Geraet
390 67 my $srv = $dev;
391 67 ▶ if ( defined $o{host} && $o{host} !~ m{\A/} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o{"host"} and not $o{"host"} =~ m[\A/]) 5 62 67
Condition66%2/3
defined $o{"host"} and not $o{"host"} =~ m[\A/]
!ll&&!rl&&r
6205
MC/DC50%1/2
defined $o{"host"} and not $o{"host"} =~ m[\A/]
defined $o{"host"} not $o{"host"} =~ m[\A/]
Truth table66%2/3
A and not(B)
A= defined $o{"host"}B= not $o{"host"} =~ m[\A/]
ABresult
0X0
100
111
392 5 my $h = $o{host};
393 5 ▶ my $self = $h eq 'localhost' || $h eq '127.0.0.1' || $h eq ( $ctx->{host} // '' ) || $h eq _ip_of($dev);
Condition36%4/11
$h eq 'localhost' || $h eq '127.0.0.1' || $h eq ($$ctx{'host'} // '') || $h eq _ip_of($dev)
l!l&&r!l&&!r
005
$h eq "localhost" or $h eq "127.0.0.1" or $h eq ($$ctx{"host"} // "")
l!l&&r!l&&!r
005
$h eq "localhost" or $h eq "127.0.0.1"
l!l&&r!l&&!r
005
$$ctx{"host"} // ""
l!l
50
MC/DC0%0/4
$h eq 'localhost' || $h eq '127.0.0.1' || $h eq ($$ctx{'host'} // '') || $h eq _ip_of($dev)
$h eq "localhost" $h eq "127.0.0.1" $h eq ($$ctx{"host"} // "") $h eq _ip_of($dev)
MC/DC0%0/1
$$ctx{"host"} // ""
$$ctx{"host"}
Truth table20%1/5
A or B or C || D
A= $h eq "localhost"B= $h eq "127.0.0.1"C= $h eq ($$ctx{"host"} // "")D= $h eq _ip_of($dev)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
Truth table50%1/2
A
A= $$ctx{"host"}
Aresult
11
00
394 5 ▶ if ( !$self ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self) { } 5 0 5
395 5 ▶ my ($name) = grep { $_ eq $h || _ip_of( $ctx->{state}{$_} ) eq $h } grep { ref $ctx->{state}{$_} eq 'HASH' && ( $ctx->{state}{$_}{type} // '' ) eq 'linux' } sort keys %{ $ctx->{state} || {} };
Condition60%6/10
$_ eq $h || _ip_of($$ctx{'state'}{$_}) eq $h
l!l&&r!l&&!r
4110
ref $$ctx{'state'}{$_} eq 'HASH' && ($$ctx{'state'}{$_}{'type'} // '') eq 'linux'
!ll&&!rl&&r
0015
$$ctx{"state"}{$_}{"type"} // ""
l!l
150
$$ctx{'state'} || {}
l!l
50
MC/DC100%2/2
$_ eq $h || _ip_of($$ctx{'state'}{$_}) eq $h
$_ eq $h _ip_of($$ctx{'state'}{$_}) eq $h
MC/DC0%0/2
ref $$ctx{'state'}{$_} eq 'HASH' && ($$ctx{'state'}{$_}{'type'} // '') eq 'linux'
ref $$ctx{'state'}{$_} eq 'HASH' $$ctx{"state"}{$_}{"type"}
MC/DC0%0/1
$$ctx{'state'} || {}
$$ctx{'state'}
Truth table100%3/3
A || B
A= $_ eq $hB= _ip_of($$ctx{'state'}{$_}) eq $h
ABresult
1X1
011
000
Truth table33%1/3
A && B
A= ref $$ctx{'state'}{$_} eq 'HASH'B= $$ctx{"state"}{$_}{"type"}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$ctx{'state'}
Aresult
11
00
396 5 ▶ return ( qq{psql: error: could not translate host name "$h" to address: Name or service not known}, 0 ) unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 5 5
397 5 $srv = $ctx->{state}{$name};
398 5 @o{qw( remote hostname server_ip client_ip )} = ( 1, $h, _ip_of($srv), _ip_of($dev) );
399 }
400 0 else { @o{qw( remote hostname server_ip client_ip )} = ( 1, $h, '127.0.0.1', '127.0.0.1' ) }
401 }
402 67 my $pg = $srv->{postgres};
403 67 ▶ if ( !$pg || ( $pg->{port} // 5432 ) != $o{port} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $pg or ($$pg{"port"} // 5432) != $o{"port"}) 0 67 67
Condition40%2/5
not $pg or ($$pg{"port"} // 5432) != $o{"port"}
l!l&&r!l&&!r
0067
$$pg{"port"} // 5432
l!l
670
MC/DC0%0/2
not $pg or ($$pg{"port"} // 5432) != $o{"port"}
not $pg $$pg{"port"}
Truth table33%1/3
not(A) or B
A= not $pgB= $$pg{"port"}
ABresult
1X1
011
000
404 0 ▶ if ( $pg && $o{port} == ( $pg->{pooler_port} // 0 ) ) { push @GAPS, 'psql über pgbouncer'; return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($pg and $o{"port"} == ($$pg{"pooler_port"} // 0)) 0 0 0
Condition0%0/5
$pg and $o{"port"} == ($$pg{"pooler_port"} // 0)
!ll&&!rl&&r
000
$$pg{"pooler_port"} // 0
l!l
00
MC/DC0%0/2
$pg and $o{"port"} == ($$pg{"pooler_port"} // 0)
$pg $o{"port"} == ($$pg{"pooler_port"} // 0)
MC/DC0%0/1
$$pg{"pooler_port"} // 0
$$pg{"pooler_port"}
Truth table0%0/3
A and B
A= $pgB= $o{"port"} == ($$pg{"pooler_port"} // 0)
ABresult
0X0
100
111
Truth table0%0/2
A
A= $$pg{"pooler_port"}
Aresult
11
00
405 0 ▶ my $where = $o{remote} ? qq{connection to server at "$o{hostname}" ($o{server_ip}), port $o{port} failed} : qq{connection to server on socket "/var/run/postgresql/.s.PGSQL.$o{port}" failed};
Branch: 1 branch
BranchTrueFalseTotal
$o{'remote'} ? : 0 0 0
406 0 ▶ return ( "psql: error: $where: " . ( $o{remote} ? "Connection refused\n\tIs the server running on that host and accepting TCP/IP connections?" : "No such file or directory\n\tIs the server running locally and accepting connections on that socket?" ), 0 );
Branch: 1 branch
BranchTrueFalseTotal
$o{'remote'} ? : 0 0 0
407 }
408 67 my ( $err, $sess ) = _connect( $srv, \%o );
409 67 ▶ return ( $err, 0 ) if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 5 62 67
410 62 $sess->{fmt} = \%fmt;
411 62 $sess->{srv} = $srv;
412 62 ▶ return _out( _list_dbs( $pg, $sess ) ) if $list;
Branch: 1 branch
BranchTrueFalseTotal
if $list 0 62 62
413 62 my ( @out, $ok );
414 62 $ok = 1;
415 62 for my $c (@cmds) {
416 68 for my $st ( _split_sql($c) ) {
417 68 my ( $t, $k ) = _statement( $pg, $sess, $st );
418 68 ▶ push @out, $t if defined $t && length $t;
Branch: 1 branch
BranchTrueFalseTotal
if defined $t and length $t 60 8 68
Condition66%2/3
defined $t and length $t
!ll&&!rl&&r
0860
MC/DC50%1/2
defined $t and length $t
defined $t length $t
Truth table66%2/3
A and B
A= defined $tB= length $t
ABresult
0X0
100
111
419 68 ▶ if ( !$k ) { $ok = 0; last }
Branch: 1 branch
BranchTrueFalseTotal
unless ($k) 11 57 68
420 }
421 68 ▶ last unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 11 57 68
422 }
423 62 return ( join( "\n", @out ), $ok );
424 }
425  
426 0 ▶sub _out { return ( $_[0], 1 ) }
Subroutine _out: not called CC=1 SCAR=6.9
427  
428 68 ▶sub _split_sql {
Subroutine _split_sql: called CC=9 SCAR=23.7
429 68 my ($s) = @_;
430 68 my ( @out, $cur, $q ) = ( (), '', '' );
431 68 for my $ch ( split //, $s ) {
432 3493 ▶ if ($q) { $cur .= $ch; $q = '' if $ch eq $q; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($q) 251 3242 3493
if $ch eq $q 29 222 251
433 3242 ▶ if ( $ch eq "'" || $ch eq '"' ) { $q = $ch; $cur .= $ch; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "'" or $ch eq "\"") 29 3213 3242
Condition66%2/3
$ch eq "'" or $ch eq "\""
l!l&&r!l&&!r
2903213
MC/DC50%1/2
$ch eq "'" or $ch eq "\""
$ch eq "'" $ch eq "\""
Truth table66%2/3
A or B
A= $ch eq "'"B= $ch eq "\""
ABresult
1X1
011
000
434 0 ▶ if ( $ch eq ';' ) { push @out, $cur; $cur = ''; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq ";") 0 3213 3213
435 0 ▶ if ( $ch eq "\n" && $cur =~ /\A\s*\\/ ) { push @out, $cur; $cur = ''; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\n" and $cur =~ /\A\s*\\/) 0 3213 3213
Condition33%1/3
$ch eq "\n" and $cur =~ /\A\s*\\/
!ll&&!rl&&r
321300
MC/DC0%0/2
$ch eq "\n" and $cur =~ /\A\s*\\/
$ch eq "\n" $cur =~ /\A\s*\\/
Truth table33%1/3
A and B
A= $ch eq "\n"B= $cur =~ /\A\s*\\/
ABresult
0X0
100
111
436 3213 $cur .= $ch;
437 }
438 68 push @out, $cur;
439 68 return grep {/\S/} map { s/\A\s+|\s+\z//gr } @out;
440 }
441  
442 # --- Ausgabe wie psql --------------------------------------------------------
443  
444 39 ▶sub _table {
Subroutine _table: called CC=23 SCAR=36.3
445 39 my ( $sess, $cols, $rows, %o ) = @_;
446 39 ▶ my $f = $sess->{fmt} || {};
Condition50%1/2
$$sess{'fmt'} || {}
l!l
390
MC/DC0%0/1
$$sess{'fmt'} || {}
$$sess{'fmt'}
Truth table50%1/2
A
A= $$sess{'fmt'}
Aresult
11
00
447 39 ▶ my @r = map { [ map { defined $_ ? "$_" : '' } @$_ ] } @$rows;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 189 2 191
448 39 ▶ if ( $f->{x} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$f{"x"}) 0 39 39
449 0 my $w = 0;
450 0 ▶ for (@$cols) { $w = length if length > $w }
Branch: 1 branch
BranchTrueFalseTotal
if length $_ > $w 0 0 0
451 0 my @l;
452 0 my $i = 0;
453 0 for my $row (@r) {
454 0 $i++;
455 0 ▶ push @l, "-[ RECORD $i ]" . ( '-' x ( $w + 2 ) ) unless $f->{t};
Branch: 1 branch
BranchTrueFalseTotal
unless $$f{"t"} 0 0 0
456 0 push @l, sprintf( "%-${w}s | %s", $cols->[$_], $row->[$_] ) for 0 .. $#$cols;
457 }
458 0 ▶ return join "\n", @l ? @l : $f->{t} ? () : '(0 rows)';
Branch: 2 branches
BranchTrueFalseTotal
@l ? : 0 0 0
$$f{'t'} ? : 0 0 0
459 }
460 39 ▶ if ( $f->{A} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$f{"A"}) 26 13 39
461 28 ▶ return join "\n", ( $f->{t} ? () : join( '|', @$cols ) ), ( map { join '|', @$_ } @r ),
Branch: 2 branches
BranchTrueFalseTotal
$$f{'t'} ? : 26 0 26
@r == 1 ? : 0 0 0
462 26 ▶ ( $f->{t} ? () : '(' . @r . ' row' . ( @r == 1 ? '' : 's' ) . ')' );
Branch: 1 branch
BranchTrueFalseTotal
$$f{'t'} ? : 26 0 26
463 }
464 # wie psql: Kopf zentriert, Zahlen rechtsbuendig, letzte Spalte ohne Fuellung rechts
465 13 my @w = map { length $cols->[$_] } 0 .. $#$cols;
466 13 ▶ for my $row (@r) { for ( 0 .. $#$cols ) { $w[$_] = length $row->[$_] if length $row->[$_] > $w[$_] } }
Branch: 1 branch
BranchTrueFalseTotal
if length $$row[$_] > $w[$_] 5 120 125
467 13 ▶ my @num = $o{text} ? () : map { my $i = $_; @r && !grep { $_->[$i] !~ /\A-?\d+(?:\.\d+)?\z/ } @r } 0 .. $#$cols;
Branch: 1 branch
BranchTrueFalseTotal
$o{'text'} ? : 1 12 13
Condition100%3/3
@r && !grep({not $$_[$i] =~ /\A-?\d+(?:\.\d+)?\z/;} @r)
!ll&&!rl&&r
5153
MC/DC100%2/2
@r && !grep({not $$_[$i] =~ /\A-?\d+(?:\.\d+)?\z/;} @r)
@r !grep({not $$_[$i] =~ /\A-?\d+(?:\.\d+)?\z/;} @r)
Truth table100%3/3
A && not(B)
A= @rB= !grep({not $$_[$i] =~ /\A-?\d+(?:\.\d+)?\z/;} @r)
ABresult
0X0
100
111
468 111 ▶ my $line = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
469 111 my ($v) = @_;
470 my $t = join '|', map {
471 111 ▶ my $x = $num[$_] ? sprintf( "%$w[$_]s", $v->[$_] ) : $_ == $#$cols ? $v->[$_] : sprintf( "%-$w[$_]s", $v->[$_] );
Branch: 2 branches
BranchTrueFalseTotal
$num[$_] ? : 4 121 125
$_ == $cols->$#* ? : 107 14 121
472 125 ▶ ' ' . $x . ( $_ == $#$cols ? '' : ' ' );
Branch: 1 branch
BranchTrueFalseTotal
$_ == $cols->$#* ? : 111 14 125
473 } 0 .. $#$cols;
474 111 return $t;
475 13 };
476 13 my @l;
477 13 ▶ if ( !$f->{t} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$f{"t"}) 13 0 13
478 13 push @l, join '|', map { my $p = $w[$_] - length $cols->[$_]; ' ' . ( ' ' x int( $p / 2 ) ) . $cols->[$_] . ( ' ' x ( $p - int( $p / 2 ) ) ) . ' ' } 0 .. $#$cols;
479 13 push @l, join '+', map { '-' x ( $_ + 2 ) } @w;
480 }
481 13 push @l, map { $line->($_) } @r;
482 13 ▶ push @l, '(' . @r . ' row' . ( @r == 1 ? '' : 's' ) . ')' unless $f->{t};
Branch: 2 branches
BranchTrueFalseTotal
unless $$f{"t"} 13 0 13
@r == 1 ? : 7 6 13
483 13 return join "\n", @l;
484 }
485  
486 0 ▶sub _list_dbs {
Subroutine _list_dbs: not called CC=4 SCAR=30.0
487 0 my ( $pg, $sess ) = @_;
488 0 ▶ my @db = ( 'postgres', sort keys %{ $pg->{databases} || {} } );
Condition0%0/2
$$pg{'databases'} || {}
l!l
00
MC/DC0%0/1
$$pg{'databases'} || {}
$$pg{'databases'}
Truth table0%0/2
A
A= $$pg{'databases'}
Aresult
11
00
489 0 my %seen;
490 return _table( $sess, [qw( Name Owner Encoding Collate Ctype )],
491 0 ▶ [ map { [ $_, ( $pg->{databases}{$_} || {} )->{owner} // 'postgres', 'UTF8', 'C.UTF-8', 'C.UTF-8' ] } grep { !$seen{$_}++ } @db ] );
Condition0%0/4
($$pg{"databases"}{$_} || {})->{"owner"} // "postgres"
l!l
00
$$pg{'databases'}{$_} || {}
l!l
00
MC/DC0%0/1
($$pg{"databases"}{$_} || {})->{"owner"} // "postgres"
$$pg{'databases'}{$_}
Truth table0%0/2
A
A= $$pg{'databases'}{$_}
Aresult
11
00
492 }
493  
494 # --- Sichten -----------------------------------------------------------------
495  
496 4 ▶sub _wal_needed {
Subroutine _wal_needed: called CC=6 SCAR=19.6
497 4 my ($pg) = @_;
498 4 my $keep = 0;
499 4 ▶ for my $s ( values %{ $pg->{slots} || {} } ) {
Condition50%1/2
$$pg{'slots'} || {}
l!l
40
MC/DC0%0/1
$$pg{'slots'} || {}
$$pg{'slots'}
Truth table50%1/2
A
A= $$pg{'slots'}
Aresult
11
00
500 7 my $r = _bytes( $s->{retained} );
501 7 ▶ $keep = $r if $r > $keep && !$s->{invalidated};
Branch: 1 branch
BranchTrueFalseTotal
if $r > $keep and not $$s{"invalidated"} 7 0 7
Condition33%1/3
$r > $keep and not $$s{"invalidated"}
!ll&&!rl&&r
007
MC/DC0%0/2
$r > $keep and not $$s{"invalidated"}
$r > $keep not $$s{"invalidated"}
Truth table33%1/3
A and not(B)
A= $r > $keepB= not $$s{"invalidated"}
ABresult
0X0
100
111
502 }
503 4 ▶ return _bytes( $pg->{wal_base} // '1G' ) + $keep;
Condition50%1/2
$$pg{"wal_base"} // "1G"
l!l
40
MC/DC0%0/1
$$pg{"wal_base"} // "1G"
$$pg{"wal_base"}
Truth table50%1/2
A
A= $$pg{"wal_base"}
Aresult
11
00
504 }
505  
506 30 ▶sub _view {
Subroutine _view: called CC=125 SCAR=64.4
507 30 my ( $pg, $sess, $name ) = @_;
508 30 my $db = $sess->{db};
509 30 ▶ if ( $name eq 'pg_stat_activity' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_stat_activity") 5 25 30
510 485 ▶ return [ map { my $a = $_; +{ ( map { $_ => $a->{$_} } qw( pid usename datname client_addr application_name state ) ),
Branch: 3 branches
BranchTrueFalseTotal
($$a{'state'} // '') =~ /\A(?:active|idle in transaction)/ ? : 5 480 485
($$a{'state'} // '') =~ /\Aidle/ ? : 480 5 485
($$a{'state'} // '') =~ /\Aidle/ ? : 480 5 485
Condition38%10/26
$$a{"backend_start"} // _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 86400)
l!l&&r!l&&!r
04850
$$a{"state_change"} // _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 180)
l!l&&r!l&&!r
04850
($$a{"query_start"} // $$a{"state_change"}) // _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 180)
l!l&&r!l&&!r
04850
$$a{"query_start"} // $$a{"state_change"}
l!l&&r!l&&!r
00485
$$a{"state"} // ""
l!l
4850
($$a{"xact_start"} // $$a{"state_change"}) // _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 180)
l!l&&r!l&&!r
050
$$a{"xact_start"} // $$a{"state_change"}
l!l&&r!l&&!r
005
$$a{"state"} // ""
l!l
4850
$$a{"state"} // ""
l!l
4850
$$a{"query"} // ""
l!l
0485
MC/DC0%0/2
$$a{"backend_start"} // _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 86400)
$$a{"backend_start"} _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 86400)
MC/DC0%0/2
$$a{"state_change"} // _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 180)
$$a{"state_change"} _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 180)
MC/DC0%0/3
($$a{"query_start"} // $$a{"state_change"}) // _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 180)
$$a{"query_start"} $$a{"state_change"} _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 180)
MC/DC0%0/1
$$a{"state"} // ""
$$a{"state"}
MC/DC0%0/3
($$a{"xact_start"} // $$a{"state_change"}) // _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 180)
$$a{"xact_start"} $$a{"state_change"} _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 180)
MC/DC0%0/1
$$a{"state"} // ""
$$a{"state"}
MC/DC0%0/1
$$a{"state"} // ""
$$a{"state"}
MC/DC0%0/1
$$a{"query"} // ""
$$a{"query"}
Truth table33%1/3
A // B
A= $$a{"backend_start"}B= _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 86400)
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $$a{"state_change"}B= _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 180)
ABresult
1X1
011
000
Truth table25%1/4
A // B // C
A= $$a{"query_start"}B= $$a{"state_change"}C= _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 180)
ABCresult
1XX1
01X1
0011
0000
Truth table50%1/2
A
A= $$a{"state"}
Aresult
11
00
Truth table25%1/4
A // B // C
A= $$a{"xact_start"}B= $$a{"state_change"}C= _ts($Langertha::Holmgang::Sim::Linux::Postgres::NOW - 180)
ABCresult
1XX1
01X1
0011
0000
Truth table50%1/2
A
A= $$a{"state"}
Aresult
11
00
Truth table50%1/2
A
A= $$a{"state"}
Aresult
11
00
Truth table50%1/2
A
A= $$a{"query"}
Aresult
11
00
511 backend_start => $a->{backend_start} // _ts( $NOW - 86400 ), state_change => $a->{state_change} // _ts( $NOW - 180 ),
512 query_start => $a->{query_start} // $a->{state_change} // _ts( $NOW - 180 ),
513 xact_start => ( $a->{state} // '' ) =~ /\A(?:active|idle in transaction)/ ? $a->{xact_start} // $a->{state_change} // _ts( $NOW - 180 ) : undef,
514 wait_event_type => ( $a->{state} // '' ) =~ /\Aidle/ ? 'Client' : undef, wait_event => ( $a->{state} // '' ) =~ /\Aidle/ ? 'ClientRead' : undef,
515 485 query => $a->{query} // '', backend_type => 'client backend', client_port => 50000 + ( $a->{pid} % 10000 ) } }
516 5 _activity_rows($pg), { pid => 9999, usename => $sess->{user}, datname => $db, application_name => 'psql', state => 'active' } ];
517 }
518 25 ▶ if ( $name eq 'pg_replication_slots' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_replication_slots") 1 24 25
519 2 return [ map { my $s = $pg->{slots}{$_};
520 { slot_name => $_, slot_type => $s->{type} // 'physical', active => $s->{active} ? 't' : 'f',
521 active_pid => $s->{active} ? $s->{active_pid} // 3121 : undef, temporary => 'f', safe_wal_size => undef,
522 restart_lsn => $s->{restart_lsn} // '0/3000000', wal_status => $s->{invalidated} ? 'lost' : _bytes( $s->{retained} ) > 10 * 1024**3 ? 'extended' : 'reserved',
523 1 ▶ _retained => _bytes( $s->{retained} ) } } sort keys %{ $pg->{slots} || {} } ];
Branch: 4 branches
BranchTrueFalseTotal
$$s{'active'} ? : 1 1 2
$$s{'active'} ? : 1 1 2
$$s{'invalidated'} ? : 0 2 2
_bytes($$s{'retained'}) > 10737418240 ? : 1 1 2
Condition50%4/8
$$s{"type"} // "physical"
l!l
02
$$s{"active_pid"} // 3121
l!l
01
$$s{"restart_lsn"} // "0/3000000"
l!l
02
$$pg{'slots'} || {}
l!l
10
MC/DC0%0/1
$$s{"type"} // "physical"
$$s{"type"}
MC/DC0%0/1
$$s{"active_pid"} // 3121
$$s{"active_pid"}
MC/DC0%0/1
$$s{"restart_lsn"} // "0/3000000"
$$s{"restart_lsn"}
MC/DC0%0/1
$$pg{'slots'} || {}
$$pg{'slots'}
Truth table50%1/2
A
A= $$s{"type"}
Aresult
11
00
Truth table50%1/2
A
A= $$s{"active_pid"}
Aresult
11
00
Truth table50%1/2
A
A= $$s{"restart_lsn"}
Aresult
11
00
Truth table50%1/2
A
A= $$pg{'slots'}
Aresult
11
00
524 }
525 24 ▶ if ( $name eq 'pg_stat_user_tables' || $name eq 'pg_tables' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_stat_user_tables" or $name eq "pg_tables") 3 21 24
Condition66%2/3
$name eq "pg_stat_user_tables" or $name eq "pg_tables"
l!l&&r!l&&!r
3021
MC/DC50%1/2
$name eq "pg_stat_user_tables" or $name eq "pg_tables"
$name eq "pg_stat_user_tables" $name eq "pg_tables"
Truth table66%2/3
A or B
A= $name eq "pg_stat_user_tables"B= $name eq "pg_tables"
ABresult
1X1
011
000
526 3 my @t;
527 3 ▶ for my $k ( sort keys %{ $pg->{tables} || {} } ) {
Condition50%1/2
$$pg{'tables'} || {}
l!l
30
MC/DC0%0/1
$$pg{'tables'} || {}
$$pg{'tables'}
Truth table50%1/2
A
A= $$pg{'tables'}
Aresult
11
00
528 6 my ( $d, $s, $t ) = split /\./, $k, 3;
529 6 ▶ next unless $d eq $db;
Branch: 1 branch
BranchTrueFalseTotal
unless $d eq $db 0 6 6
530 6 my $x = $pg->{tables}{$k};
531 push @t, $name eq 'pg_tables'
532 ? { schemaname => $s, tablename => $t, tableowner => $x->{owner} }
533 : { relid => "$s.$t", schemaname => $s, relname => $t, n_live_tup => $x->{n_live_tup} // 0, n_dead_tup => $x->{n_dead_tup} // 0,
534 last_vacuum => $x->{last_vacuum}, last_autovacuum => $x->{last_autovacuum}, last_analyze => $x->{last_analyze},
535 last_autoanalyze => $x->{last_autoanalyze}, autovacuum_count => $x->{autovacuum_count} // 0, _size => _bytes( $x->{size} ),
536 6 ▶ _reloptions => $x->{reloptions} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'pg_tables' ? : 0 6 6
Condition50%4/8
$$x{"n_live_tup"} // 0
l!l
60
$$x{"n_dead_tup"} // 0
l!l
60
$$x{"autovacuum_count"} // 0
l!l
06
$$x{'reloptions'} || []
l!l
60
MC/DC0%0/1
$$x{"n_live_tup"} // 0
$$x{"n_live_tup"}
MC/DC0%0/1
$$x{"n_dead_tup"} // 0
$$x{"n_dead_tup"}
MC/DC0%0/1
$$x{"autovacuum_count"} // 0
$$x{"autovacuum_count"}
MC/DC0%0/1
$$x{'reloptions'} || []
$$x{'reloptions'}
Truth table50%1/2
A
A= $$x{"n_live_tup"}
Aresult
11
00
Truth table50%1/2
A
A= $$x{"n_dead_tup"}
Aresult
11
00
Truth table50%1/2
A
A= $$x{"autovacuum_count"}
Aresult
11
00
Truth table50%1/2
A
A= $$x{'reloptions'}
Aresult
11
00
537 }
538 3 return \@t;
539 }
540 21 ▶ if ( $name eq 'pg_settings' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_settings") 5 16 21
541 0 ▶ my %p = map { $_ => 1 } @{ $pg->{pending_restart} || [] };
Condition50%1/2
$$pg{'pending_restart'} || []
l!l
05
MC/DC0%0/1
$$pg{'pending_restart'} || []
$$pg{'pending_restart'}
Truth table50%1/2
A
A= $$pg{'pending_restart'}
Aresult
11
00
542 # Herkunft: die Datei, deren Zeile den laufenden Wert traegt (auto.conf vor postgresql.conf)
543 my @src = map {
544 10 my $f = $_;
545 10 my $n = 0;
546 10 ▶ my %line = map { $n++; /\A\s*([a-z_]+)\s*=/ ? ( $1 => $n ) : () } split /\n/, _file( $sess->{srv}, $f ) // '';
Branch: 1 branch
BranchTrueFalseTotal
/\A\s*([a-z_]+)\s*=/ ? : 36 8 44
Condition50%1/2
_file($$sess{"srv"}, $f) // ""
l!l
100
MC/DC0%0/1
_file($$sess{"srv"}, $f) // ""
_file($$sess{"srv"}, $f)
Truth table50%1/2
A
A= _file($$sess{"srv"}, $f)
Aresult
11
00
547 10 [ $f, _conf_values( _file( $sess->{srv}, $f ) ), \%line ];
548 5 } grep {defined} @{$pg}{qw( auto_conf conf )};
549 5 ▶ my %all = ( %GUC, %{ $pg->{settings} || {} } );
Condition50%1/2
$$pg{'settings'} || {}
l!l
50
MC/DC0%0/1
$$pg{'settings'} || {}
$$pg{'settings'}
Truth table50%1/2
A
A= $$pg{'settings'}
Aresult
11
00
550 return [ map {
551 5 my $k = $_;
552 160 ▶ my $g = $GUC{$k} || {};
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::Postgres::GUC{$k} || {}
l!l
1600
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::Postgres::GUC{$k} || {}
$Langertha::Holmgang::Sim::Linux::Postgres::GUC{$k}
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::Postgres::GUC{$k}
Aresult
11
00
553 160 ▶ my $val = exists( ( $pg->{settings} || {} )->{$k} ) ? $pg->{settings}{$k} : $g->{boot};
Branch: 1 branch
BranchTrueFalseTotal
exists(($$pg{'settings'} || {})->{$k}) ? : 31 129 160
Condition50%1/2
$$pg{'settings'} || {}
l!l
1600
MC/DC0%0/1
$$pg{'settings'} || {}
$$pg{'settings'}
Truth table50%1/2
A
A= $$pg{'settings'}
Aresult
11
00
554 160 ▶ my ($s) = exists( ( $pg->{settings} || {} )->{$k} ) ? grep { defined $_->[1]{$k} && _guc_base( $k, $_->[1]{$k} ) eq _guc_base( $k, $val ) } @src : ();
Branch: 1 branch
BranchTrueFalseTotal
exists(($$pg{'settings'} || {})->{$k}) ? : 31 129 160
Condition80%4/5
$$pg{'settings'} || {}
l!l
1600
defined $$_[1]{$k} && _guc_base($k, $$_[1]{$k}) eq _guc_base($k, $val)
!ll&&!rl&&r
26729
MC/DC0%0/1
$$pg{'settings'} || {}
$$pg{'settings'}
MC/DC100%2/2
defined $$_[1]{$k} && _guc_base($k, $$_[1]{$k}) eq _guc_base($k, $val)
defined $$_[1]{$k} _guc_base($k, $$_[1]{$k}) eq _guc_base($k, $val)
Truth table50%1/2
A
A= $$pg{'settings'}
Aresult
11
00
Truth table100%3/3
A && B
A= defined $$_[1]{$k}B= _guc_base($k, $$_[1]{$k}) eq _guc_base($k, $val)
ABresult
0X0
100
111
555 { name => $k, setting => _guc_base( $k, $val ), unit => length( $g->{unit} // '' ) ? $g->{unit} : undef, context => $CONTEXT{$k} // 'sighup',
556 vartype => $g->{vartype} // 'string', category => $g->{category}, short_desc => undef, extra_desc => undef,
557 boot_val => $g->{boot}, reset_val => _guc_base( $k, $val ), min_val => undef, max_val => undef, enumvals => undef,
558 source => $s ? 'configuration file' : 'default', sourcefile => $s ? $s->[0] : undef, sourceline => $s ? $s->[2]{$k} : undef,
559 160 ▶ pending_restart => $p{$k} ? 't' : 'f' }
Branch: 5 branches
BranchTrueFalseTotal
length($$g{'unit'} // '') ? : 70 90 160
$s ? : 29 131 160
$s ? : 29 131 160
$s ? : 29 131 160
$p{$k} ? : 0 160 160
Condition66%4/6
$$g{"unit"} // ""
l!l
1600
$Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$k} // "sighup"
l!l
11050
$$g{"vartype"} // "string"
l!l
1600
MC/DC0%0/1
$$g{"unit"} // ""
$$g{"unit"}
MC/DC100%1/1
$Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$k} // "sighup"
$Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$k}
MC/DC0%0/1
$$g{"vartype"} // "string"
$$g{"vartype"}
Truth table50%1/2
A
A= $$g{"unit"}
Aresult
11
00
Truth table100%2/2
A
A= $Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$k}
Aresult
11
00
Truth table50%1/2
A
A= $$g{"vartype"}
Aresult
11
00
560 } sort keys %all ];
561 }
562 16 ▶ if ( $name eq 'pg_file_settings' ) { # jede Zeile der Dateien; wirksam ist die letzte je Name
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_file_settings") 2 14 16
563 2 ▶ die "permission denied for view pg_file_settings\n" unless _is_super( $pg, $sess->{user} );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_super($pg, $$sess{"user"}) 0 2 2
564 2 my @r;
565 2 my $seq = 0;
566 2 for my $f ( grep {defined} @{$pg}{qw( conf auto_conf )} ) {
567 4 my $n = 0;
568 4 ▶ for my $l ( split /\n/, _file( $sess->{srv}, $f ) // '' ) {
Condition50%1/2
_file($$sess{"srv"}, $f) // ""
l!l
40
MC/DC0%0/1
_file($$sess{"srv"}, $f) // ""
_file($$sess{"srv"}, $f)
Truth table50%1/2
A
A= _file($$sess{"srv"}, $f)
Aresult
11
00
569 20 $n++;
570 20 ( my $x = $l ) =~ s/#.*//;
571 20 ▶ next unless $x =~ /\A\s*([a-z_]+)\s*=?\s*(?:'([^']*)'|(\S+))/;
Branch: 1 branch
BranchTrueFalseTotal
unless $x =~ /\A\s*([a-z_]+)\s*=?\s*(?:'([^']*)'|(\S+))/ 4 16 20
572 16 ▶ push @r, { sourcefile => $f, sourceline => $n, seqno => ++$seq, name => $1, setting => $2 // $3, applied => 'f', error => undef };
Condition66%2/3
$2 // $3
l!l&&r!l&&!r
6100
MC/DC0%0/2
$2 // $3
$2 $3
Truth table66%2/3
A // B
A= $2B= $3
ABresult
1X1
011
000
573 }
574 }
575 2 my %last;
576 2 $last{ $_->{name} } = $_ for @r;
577 2 for my $x ( values %last ) {
578 0 ▶ if ( ( $CONTEXT{ $x->{name} } // '' ) eq 'postmaster' && grep { $_ eq $x->{name} } @{ $pg->{pending_restart} || [] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$$x{'name'}} // '') eq 'postmaster' and grep {$_ eq $$x{'name'};} @{$$pg{'pending_restart'} or [];}) { } 0 14 14
Condition71%5/7
($Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$$x{"name"}} // "") eq "postmaster" and grep {$_ eq $$x{"name"};} @{$$pg{"pending_restart"} or [];}
!ll&&!rl&&r
680
$Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$$x{"name"}} // ""
l!l
122
$$pg{'pending_restart'} || []
l!l
08
MC/DC0%0/2
($Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$$x{"name"}} // "") eq "postmaster" and grep {$_ eq $$x{"name"};} @{$$pg{"pending_restart"} or [];}
$Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$$x{"name"}} grep {$_ eq $$x{"name"};} @{$$pg{"pending_restart"} or [];}
MC/DC0%0/1
$$pg{'pending_restart'} || []
$$pg{'pending_restart'}
Truth table66%2/3
A and B
A= $Langertha::Holmgang::Sim::Linux::Postgres::CONTEXT{$$x{"name"}}B= grep {$_ eq $$x{"name"};} @{$$pg{"pending_restart"} or [];}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$pg{'pending_restart'}
Aresult
11
00
579 0 $x->{error} = 'setting could not be applied';
580 }
581 14 else { $x->{applied} = 't' }
582 }
583 2 return \@r;
584 }
585 14 ▶ if ( $name eq 'pg_authid' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_authid") 2 12 14
586 2 ▶ die "permission denied for table pg_authid\n" unless _is_super( $pg, $sess->{user} );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_super($pg, $$sess{"user"}) 0 2 2
587 4 return [ map { my $r = $pg->{roles}{$_};
588 { oid => $_, rolname => $_, rolsuper => $r->{superuser} ? 't' : 'f', rolcanlogin => ( $r->{login} || $r->{superuser} ) ? 't' : 'f',
589 rolcreaterole => $r->{createrole} ? 't' : 'f', rolcreatedb => $r->{createdb} ? 't' : 'f', rolinherit => 't',
590 rolreplication => $r->{replication} ? 't' : 'f', rolbypassrls => $r->{bypassrls} ? 't' : 'f', rolconnlimit => -1, rolvaliduntil => undef,
591 4 ▶ rolpassword => $r->{password} ? 'SCRAM-SHA-256$4096:' . substr( Digest::MD5::md5_base64("salz:$_"), 0, 22 ) . '==$'
Branch: 7 branches
BranchTrueFalseTotal
$$r{'superuser'} ? : 2 2 4
$$r{'login'} || $$r{'superuser'} ? : 4 0 4
$$r{'createrole'} ? : 0 4 4
$$r{'createdb'} ? : 0 4 4
$$r{'replication'} ? : 0 4 4
$$r{'bypassrls'} ? : 0 4 4
$$r{'password'} ? : 2 2 4
Condition33%1/3
$$r{"login"} or $$r{"superuser"}
l!l&&r!l&&!r
400
MC/DC0%0/2
$$r{"login"} or $$r{"superuser"}
$$r{"login"} $$r{"superuser"}
Truth table33%1/3
A or B
A= $$r{"login"}B= $$r{"superuser"}
ABresult
1X1
011
000
592 2 ▶ . Digest::MD5::md5_base64("stored:$_") . '=:' . Digest::MD5::md5_base64("server:$_") . '=' : undef } } sort keys %{ $pg->{roles} || {} } ];
Condition50%1/2
$$pg{'roles'} || {}
l!l
20
MC/DC0%0/1
$$pg{'roles'} || {}
$$pg{'roles'}
Truth table50%1/2
A
A= $$pg{'roles'}
Aresult
11
00
593 }
594 12 ▶ if ( $name eq 'pg_roles' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_roles") 1 11 12
595 3 return [ map { my $r = $pg->{roles}{$_};
596 { oid => $_, rolname => $_, rolsuper => $r->{superuser} ? 't' : 'f', rolcanlogin => ( $r->{login} || $r->{superuser} ) ? 't' : 'f',
597 rolcreaterole => $r->{createrole} ? 't' : 'f', rolcreatedb => $r->{createdb} ? 't' : 'f',
598 3 ▶ rolreplication => $r->{replication} ? 't' : 'f', rolbypassrls => $r->{bypassrls} ? 't' : 'f', rolinherit => 't',
Branch: 6 branches
BranchTrueFalseTotal
$$r{'superuser'} ? : 1 2 3
$$r{'login'} || $$r{'superuser'} ? : 2 1 3
$$r{'createrole'} ? : 0 3 3
$$r{'createdb'} ? : 0 3 3
$$r{'replication'} ? : 0 3 3
$$r{'bypassrls'} ? : 0 3 3
Condition66%2/3
$$r{"login"} or $$r{"superuser"}
l!l&&r!l&&!r
201
MC/DC50%1/2
$$r{"login"} or $$r{"superuser"}
$$r{"login"} $$r{"superuser"}
Truth table66%2/3
A or B
A= $$r{"login"}B= $$r{"superuser"}
ABresult
1X1
011
000
599 1 ▶ rolconnlimit => -1, rolvaliduntil => undef, rolpassword => '********', rolconfig => undef } } sort keys %{ $pg->{roles} || {} } ];
Condition50%1/2
$$pg{'roles'} || {}
l!l
10
MC/DC0%0/1
$$pg{'roles'} || {}
$$pg{'roles'}
Truth table50%1/2
A
A= $$pg{'roles'}
Aresult
11
00
600 }
601 11 ▶ if ( $name eq 'pg_auth_members' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_auth_members") 1 10 11
602 1 ▶ my $m = $pg->{members} || {};
Condition50%1/2
$$pg{'members'} || {}
l!l
01
MC/DC0%0/1
$$pg{'members'} || {}
$$pg{'members'}
Truth table50%1/2
A
A= $$pg{'members'}
Aresult
11
00
603 0 ▶ return [ map { my $g = $_; map { +{ roleid => $g, member => $_, grantor => 'postgres', admin_option => 'f' } } @{ $m->{$g} || [] } } sort keys %$m ];
Condition0%0/2
$$m{$g} || []
l!l
00
MC/DC0%0/1
$$m{$g} || []
$$m{$g}
Truth table0%0/2
A
A= $$m{$g}
Aresult
11
00
604 }
605 10 ▶ if ( $name eq 'pg_default_acl' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_default_acl") 3 7 10
606 3 my %k = ( tables => 'r', sequences => 'S', functions => 'f', types => 'T', schemas => 'n' );
607 return [ map { +{ defaclrole => $_->{role}, defaclnamespace => $_->{schema} // 0, defaclobjtype => $k{ lc( $_->{on} // 'tables' ) } // 'r',
608 0 ▶ defaclacl => '{' . ( $_->{grantee} eq 'PUBLIC' ? '' : $_->{grantee} ) . '=' . _acl_letters( $_->{privs} ) . "/$_->{role}}" } }
Branch: 1 branch
BranchTrueFalseTotal
$$_{'grantee'} eq 'PUBLIC' ? : 0 0 0
Condition0%0/6
$$_{"schema"} // 0
l!l
00
$k{lc($$_{"on"} // "tables")} // "r"
l!l
00
$$_{"on"} // "tables"
l!l
00
MC/DC0%0/1
$$_{"schema"} // 0
$$_{"schema"}
MC/DC0%0/1
$k{lc($$_{"on"} // "tables")} // "r"
$k{lc($$_{"on"} // "tables")}
MC/DC0%0/1
$$_{"on"} // "tables"
$$_{"on"}
Truth table0%0/2
A
A= $$_{"schema"}
Aresult
11
00
Truth table0%0/2
A
A= $k{lc($$_{"on"} // "tables")}
Aresult
11
00
Truth table0%0/2
A
A= $$_{"on"}
Aresult
11
00
609 0 ▶ grep { ( $_->{db} // $db ) eq $db } @{ $pg->{default_acl} || [] } ];
Condition20%1/5
$$_{"db"} // $db
l!l&&r!l&&!r
000
$$pg{'default_acl'} || []
l!l
30
MC/DC0%0/2
$$_{"db"} // $db
$$_{"db"} $db
MC/DC0%0/1
$$pg{'default_acl'} || []
$$pg{'default_acl'}
Truth table0%0/3
A // B
A= $$_{"db"}B= $db
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$pg{'default_acl'}
Aresult
11
00
610 }
611 7 ▶ if ( $name eq 'pg_hba_file_rules' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_hba_file_rules") 0 7 7
612 0 my $i = 0;
613 0 my @r;
614 0 ▶ for my $l ( split /\n/, _file( $sess->{srv}, $pg->{hba} ) // '' ) {
Condition0%0/2
_file($$sess{"srv"}, $$pg{"hba"}) // ""
l!l
00
MC/DC0%0/1
_file($$sess{"srv"}, $$pg{"hba"}) // ""
_file($$sess{"srv"}, $$pg{"hba"})
Truth table0%0/2
A
A= _file($$sess{"srv"}, $$pg{"hba"})
Aresult
11
00
615 0 $i++;
616 0 ( my $x = $l ) =~ s/#.*//;
617 0 $x =~ s/\A\s+|\s+\z//g;
618 0 ▶ next unless length $x;
Branch: 1 branch
BranchTrueFalseTotal
unless length $x 0 0 0
619 0 my @f = split /\s+/, $x;
620 0 my $type = shift @f;
621 0 my ( $d, $u ) = ( shift @f, shift @f );
622 0 ▶ my $addr = $type eq 'local' ? undef : shift @f;
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'local' ? : 0 0 0
623 0 push @r, { line_number => $i, type => $type, database => "{$d}", user_name => "{$u}", address => $addr, auth_method => shift(@f) };
624 }
625 0 return \@r;
626 }
627 7 ▶ if ( $name eq 'pg_class' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_class") 1 6 7
628 return [ map {
629 2 my ( $d, $sch, $t ) = split /\./, $_, 3;
630 2 my $x = $pg->{tables}{$_};
631 $d eq $db ? +{ oid => "$sch.$t", relname => $t, relnamespace => $sch, relowner => $x->{owner} // 'postgres', relkind => 'r',
632 2 ▶ reltuples => $x->{n_live_tup} // 0, relpages => int( _bytes( $x->{size} ) / 8192 ), relhasindex => @{ $x->{indexes} || [] } ? 't' : 'f',
Branch: 1 branch
BranchTrueFalseTotal
@{$$x{'reloptions'} or [];} ? : 1 1 2
Condition50%2/4
$$x{'indexes'} || []
l!l
02
$$x{"owner"} // "postgres"
l!l
20
MC/DC0%0/1
$$x{'indexes'} || []
$$x{'indexes'}
MC/DC0%0/1
$$x{"owner"} // "postgres"
$$x{"owner"}
Truth table50%1/2
A
A= $$x{'indexes'}
Aresult
11
00
Truth table50%1/2
A
A= $$x{"owner"}
Aresult
11
00
633 relacl => _acl_text( $pg, "table:$_", $x->{owner} // 'postgres' ),
634 2 ▶ reloptions => @{ $x->{reloptions} || [] } ? '{' . join( ',', @{ $x->{reloptions} } ) . '}' : undef,
Condition50%1/2
$$x{'reloptions'} || []
l!l
20
MC/DC0%0/1
$$x{'reloptions'} || []
$$x{'reloptions'}
Truth table50%1/2
A
A= $$x{'reloptions'}
Aresult
11
00
635 2 ▶ _size => _bytes( $x->{size} ) } : ();
Branch: 2 branches
BranchTrueFalseTotal
$d eq $db ? : 2 0 2
@{$$x{'indexes'} or [];} ? : 0 2 2
Condition50%2/4
$$x{"owner"} // "postgres"
l!l
20
$$x{"n_live_tup"} // 0
l!l
20
MC/DC0%0/1
$$x{"owner"} // "postgres"
$$x{"owner"}
MC/DC0%0/1
$$x{"n_live_tup"} // 0
$$x{"n_live_tup"}
Truth table50%1/2
A
A= $$x{"owner"}
Aresult
11
00
Truth table50%1/2
A
A= $$x{"n_live_tup"}
Aresult
11
00
636 1 ▶ } sort keys %{ $pg->{tables} || {} } ];
Condition50%1/2
$$pg{'tables'} || {}
l!l
10
MC/DC0%0/1
$$pg{'tables'} || {}
$$pg{'tables'}
Truth table50%1/2
A
A= $$pg{'tables'}
Aresult
11
00
637 }
638 6 ▶ if ( $name eq 'pg_database' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_database") 2 4 6
639 return [ map { { oid => $_, datname => $_, datdba => ( $pg->{databases}{$_} || {} )->{owner} // 'postgres',
640 datallowconn => ( ( $pg->{databases}{$_} || {} )->{allowconn} // 1 ) ? 't' : 'f', datistemplate => 'f', datconnlimit => -1,
641 encoding => 6, datcollate => 'C.UTF-8', datctype => 'C.UTF-8', datlocprovider => 'c',
642 4 ▶ datacl => _acl_text( $pg, "database:$_", ( $pg->{databases}{$_} || {} )->{owner} // 'postgres' ) } }
Branch: 1 branch
BranchTrueFalseTotal
($$pg{'databases'}{$_} || {})->{'allowconn'} // 1 ? : 4 0 4
Condition91%11/12
($$pg{"databases"}{$_} || {})->{"owner"} // "postgres"
l!l
22
$$pg{'databases'}{$_} || {}
l!l
22
($$pg{"databases"}{$_} || {})->{"allowconn"} // 1
l!l
04
$$pg{'databases'}{$_} || {}
l!l
22
($$pg{"databases"}{$_} || {})->{"owner"} // "postgres"
l!l
22
$$pg{'databases'}{$_} || {}
l!l
22
MC/DC100%1/1
($$pg{"databases"}{$_} || {})->{"owner"} // "postgres"
$$pg{'databases'}{$_}
MC/DC100%1/1
($$pg{"databases"}{$_} || {})->{"allowconn"} // 1
$$pg{'databases'}{$_}
MC/DC100%1/1
($$pg{"databases"}{$_} || {})->{"owner"} // "postgres"
$$pg{'databases'}{$_}
Truth table100%2/2
A
A= $$pg{'databases'}{$_}
Aresult
11
00
Truth table100%2/2
A
A= $$pg{'databases'}{$_}
Aresult
11
00
Truth table100%2/2
A
A= $$pg{'databases'}{$_}
Aresult
11
00
643 2 ▶ 'postgres', grep { $_ ne 'postgres' } sort keys %{ $pg->{databases} || {} } ];
Condition50%1/2
$$pg{'databases'} || {}
l!l
20
MC/DC0%0/1
$$pg{'databases'} || {}
$$pg{'databases'}
Truth table50%1/2
A
A= $$pg{'databases'}
Aresult
11
00
644 }
645 4 ▶ if ( $name eq 'pg_namespace' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_namespace") 2 2 4
646 2 return [ map { my ( $d, $n ) = split /\./, $_, 2; $d eq $db ? +{ oid => $n, nspname => $n, nspowner => $pg->{schemas}{$_}{owner} // 'postgres',
647 2 ▶ nspacl => _acl_text( $pg, "schema:$_", $pg->{schemas}{$_}{owner} // 'postgres' ) } : () } sort keys %{ $pg->{schemas} || {} } ];
Branch: 1 branch
BranchTrueFalseTotal
$d eq $db ? : 2 0 2
Condition50%3/6
$$pg{"schemas"}{$_}{"owner"} // "postgres"
l!l
20
$$pg{"schemas"}{$_}{"owner"} // "postgres"
l!l
20
$$pg{'schemas'} || {}
l!l
20
MC/DC0%0/1
$$pg{"schemas"}{$_}{"owner"} // "postgres"
$$pg{"schemas"}{$_}{"owner"}
MC/DC0%0/1
$$pg{"schemas"}{$_}{"owner"} // "postgres"
$$pg{"schemas"}{$_}{"owner"}
MC/DC0%0/1
$$pg{'schemas'} || {}
$$pg{'schemas'}
Truth table50%1/2
A
A= $$pg{"schemas"}{$_}{"owner"}
Aresult
11
00
Truth table50%1/2
A
A= $$pg{"schemas"}{$_}{"owner"}
Aresult
11
00
Truth table50%1/2
A
A= $$pg{'schemas'}
Aresult
11
00
648 }
649 2 return undef;
650 }
651  
652 # --- Ausdruecke ----------------------------------------------------------------
653  
654 55 ▶sub _tokens {
Subroutine _tokens: called CC=8 SCAR=21.1
655 55 my ($s) = @_;
656 55 my @t;
657 55 pos($s) = 0;
658 55 ▶ while ( pos($s) < length $s ) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $s < length $s) 366 55 421
659 366 ▶ if ( $s =~ /\G\s+/gc ) { next }
Branch: 6 branches
BranchTrueFalseTotal
if ($s =~ /\G\s+/cg) { } 91 275 366
elsif ($s =~ /\G'((?:[^']|'')*)'/cg) { } 29 246 275
elsif ($s =~ /\G"([^"]*)"/cg) { } 0 246 246
elsif ($s =~ /\G(\d+(?:\.\d+)?)/cg) { } 5 241 246
elsif ($s =~ /\G(::|\|\||<>|!=|<=|>=|[(),*=<>.+-])/cg) { } 125 116 241
elsif ($s =~ /\G([A-Za-z_][A-Za-z0-9_\$]*)/cg) { } 116 0 116
660 29 elsif ( $s =~ /\G'((?:[^']|'')*)'/gc ) { push @t, [ str => $1 =~ s/''/'/gr ] }
661 0 elsif ( $s =~ /\G"([^"]*)"/gc ) { push @t, [ id => $1 ] }
662 5 elsif ( $s =~ /\G(\d+(?:\.\d+)?)/gc ) { push @t, [ num => $1 ] }
663 125 elsif ( $s =~ /\G(::|\|\||<>|!=|<=|>=|[(),*=<>.+-])/gc ) { push @t, [ op => $1 ] }
664 116 elsif ( $s =~ /\G([A-Za-z_][A-Za-z0-9_\$]*)/gc ) { push @t, [ id => lc $1 ] }
665 0 else { die "syntax\n" }
666 }
667 55 return \@t;
668 }
669  
670 # rekursiver Abstieg: or > and > not > cmp > primary
671 114 ▶sub _parse_expr {
Subroutine _parse_expr: called CC=4 SCAR=14.8
672 114 my ($t) = @_;
673 114 my $l = _p_and($t);
674 0 ▶ while ( @$t && $t->[0][0] eq 'id' && $t->[0][1] eq 'or' ) { shift @$t; $l = [ or => $l, _p_and($t) ] }
Branch: 1 branch
BranchTrueFalseTotal
if (@$t and $$t[0][0] eq "id" and $$t[0][1] eq "or") 0 114 114
Condition83%5/6
@$t and $$t[0][0] eq "id" and $$t[0][1] eq "or"
!ll&&!rl&&r
11310
@$t and $$t[0][0] eq "id"
!ll&&!rl&&r
54591
MC/DC0%0/3
@$t and $$t[0][0] eq "id" and $$t[0][1] eq "or"
@$t $$t[0][0] eq "id" $$t[0][1] eq "or"
Truth table75%3/4
A and B and C
A= @$tB= $$t[0][0] eq "id"C= $$t[0][1] eq "or"
ABCresult
0XX0
10X0
1100
1111
675 114 return $l;
676 }
677  
678 114 ▶sub _p_and {
Subroutine _p_and: called CC=4 SCAR=14.8
679 114 my ($t) = @_;
680 114 my $l = _p_not($t);
681 0 ▶ while ( @$t && $t->[0][0] eq 'id' && $t->[0][1] eq 'and' ) { shift @$t; $l = [ and => $l, _p_not($t) ] }
Branch: 1 branch
BranchTrueFalseTotal
if (@$t and $$t[0][0] eq "id" and $$t[0][1] eq "and") 0 114 114
Condition83%5/6
@$t and $$t[0][0] eq "id" and $$t[0][1] eq "and"
!ll&&!rl&&r
11310
@$t and $$t[0][0] eq "id"
!ll&&!rl&&r
54591
MC/DC0%0/3
@$t and $$t[0][0] eq "id" and $$t[0][1] eq "and"
@$t $$t[0][0] eq "id" $$t[0][1] eq "and"
Truth table75%3/4
A and B and C
A= @$tB= $$t[0][0] eq "id"C= $$t[0][1] eq "and"
ABCresult
0XX0
10X0
1100
1111
682 114 return $l;
683 }
684  
685 114 ▶sub _p_not {
Subroutine _p_not: called CC=4 SCAR=15.9
686 114 my ($t) = @_;
687 0 ▶ if ( @$t && $t->[0][0] eq 'id' && $t->[0][1] eq 'not' ) { shift @$t; return [ not => _p_not($t) ] }
Branch: 1 branch
BranchTrueFalseTotal
if (@$t and $$t[0][0] eq "id" and $$t[0][1] eq "not") 0 114 114
Condition66%4/6
@$t and $$t[0][0] eq "id" and $$t[0][1] eq "not"
!ll&&!rl&&r
22920
@$t and $$t[0][0] eq "id"
!ll&&!rl&&r
02292
MC/DC0%0/3
@$t and $$t[0][0] eq "id" and $$t[0][1] eq "not"
@$t $$t[0][0] eq "id" $$t[0][1] eq "not"
Truth table50%2/4
A and B and C
A= @$tB= $$t[0][0] eq "id"C= $$t[0][1] eq "not"
ABCresult
0XX0
10X0
1100
1111
688 114 return _p_cmp($t);
689 }
690  
691 129 ▶sub _p_arith {
Subroutine _p_arith: called CC=4 SCAR=13.9
692 129 my ($t) = @_;
693 129 my $l = _p_prim($t);
694 129 ▶ while ( @$t && $t->[0][0] eq 'op' && $t->[0][1] =~ /\A(?:\|\||\+|-)\z/ ) { my $op = ( shift @$t )->[1]; $l = [ arith => $op, $l, _p_prim($t) ] }
Branch: 1 branch
BranchTrueFalseTotal
if (@$t and $$t[0][0] eq "op" and $$t[0][1] =~ /\A(?:\|\||\+|-)\z/) 5 129 134
Condition100%6/6
@$t and $$t[0][0] eq "op" and $$t[0][1] =~ /\A(?:\|\||\+|-)\z/
!ll&&!rl&&r
55745
@$t and $$t[0][0] eq "op"
!ll&&!rl&&r
52379
MC/DC100%3/3
@$t and $$t[0][0] eq "op" and $$t[0][1] =~ /\A(?:\|\||\+|-)\z/
@$t $$t[0][0] eq "op" $$t[0][1] =~ /\A(?:\|\||\+|-)\z/
Truth table100%4/4
A and B and C
A= @$tB= $$t[0][0] eq "op"C= $$t[0][1] =~ /\A(?:\|\||\+|-)\z/
ABCresult
0XX0
10X0
1100
1111
695 129 return $l;
696 }
697  
698 114 ▶sub _p_cmp {
Subroutine _p_cmp: called CC=26 SCAR=36.1
699 114 my ($t) = @_;
700 114 my $l = _p_arith($t);
701 114 ▶ return $l unless @$t;
Branch: 1 branch
BranchTrueFalseTotal
unless @$t 37 77 114
702 77 my $x = $t->[0];
703 77 ▶ if ( $x->[0] eq 'op' && $x->[1] =~ /\A(?:=|<>|!=|<|>|<=|>=)\z/ ) { shift @$t; return [ cmp => $x->[1], $l, _p_arith($t) ] }
Branch: 1 branch
BranchTrueFalseTotal
if ($$x[0] eq "op" and $$x[1] =~ /\A(?:=|<>|!=|<|>|<=|>=)\z/) 15 62 77
Condition100%3/3
$$x[0] eq "op" and $$x[1] =~ /\A(?:=|<>|!=|<|>|<=|>=)\z/
!ll&&!rl&&r
35915
MC/DC100%2/2
$$x[0] eq "op" and $$x[1] =~ /\A(?:=|<>|!=|<|>|<=|>=)\z/
$$x[0] eq "op" $$x[1] =~ /\A(?:=|<>|!=|<|>|<=|>=)\z/
Truth table100%3/3
A and B
A= $$x[0] eq "op"B= $$x[1] =~ /\A(?:=|<>|!=|<|>|<=|>=)\z/
ABresult
0X0
100
111
704 0 ▶ if ( $x->[0] eq 'id' && $x->[1] =~ /\A(?:like|ilike)\z/ ) { shift @$t; return [ $x->[1] => $l, _p_prim($t) ] }
Branch: 1 branch
BranchTrueFalseTotal
if ($$x[0] eq "id" and $$x[1] =~ /\A(?:like|ilike)\z/) 0 62 62
Condition66%2/3
$$x[0] eq "id" and $$x[1] =~ /\A(?:like|ilike)\z/
!ll&&!rl&&r
5930
MC/DC0%0/2
$$x[0] eq "id" and $$x[1] =~ /\A(?:like|ilike)\z/
$$x[0] eq "id" $$x[1] =~ /\A(?:like|ilike)\z/
Truth table66%2/3
A and B
A= $$x[0] eq "id"B= $$x[1] =~ /\A(?:like|ilike)\z/
ABresult
0X0
100
111
705 62 ▶ if ( $x->[0] eq 'id' && $x->[1] eq 'is' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$x[0] eq "id" and $$x[1] eq "is") 1 61 62
Condition100%3/3
$$x[0] eq "id" and $$x[1] eq "is"
!ll&&!rl&&r
5921
MC/DC100%2/2
$$x[0] eq "id" and $$x[1] eq "is"
$$x[0] eq "id" $$x[1] eq "is"
Truth table100%3/3
A and B
A= $$x[0] eq "id"B= $$x[1] eq "is"
ABresult
0X0
100
111
706 1 shift @$t;
707 1 ▶ my $neg = @$t && $t->[0][1] eq 'not' ? shift(@$t) && 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@$t && $$t[0][1] eq 'not' ? : 1 0 1
Condition40%2/5
@$t and $$t[0][1] eq "not"
!ll&&!rl&&r
001
shift @$t and 1
!ll
01
MC/DC0%0/2
@$t and $$t[0][1] eq "not"
@$t $$t[0][1] eq "not"
MC/DC0%0/1
shift @$t and 1
shift @$t
Truth table33%1/3
A and B
A= @$tB= $$t[0][1] eq "not"
ABresult
0X0
100
111
Truth table50%1/2
A
A= shift @$t
Aresult
00
11
708 1 my $v = shift @$t;
709 1 ▶ die "syntax\n" unless $v && $v->[1] =~ /\A(?:null|true|false)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $v and $$v[1] =~ /\A(?:null|true|false)\z/ 0 1 1
Condition33%1/3
$v and $$v[1] =~ /\A(?:null|true|false)\z/
!ll&&!rl&&r
001
MC/DC0%0/2
$v and $$v[1] =~ /\A(?:null|true|false)\z/
$v $$v[1] =~ /\A(?:null|true|false)\z/
Truth table33%1/3
A and B
A= $vB= $$v[1] =~ /\A(?:null|true|false)\z/
ABresult
0X0
100
111
710 1 return [ is => $neg, $l, $v->[1] ];
711 }
712 61 ▶ if ( $x->[0] eq 'id' && ( $x->[1] eq 'in' || $x->[1] eq 'not' && @$t > 1 && $t->[1][1] eq 'in' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$x[0] eq "id" and $$x[1] eq "in" || $$x[1] eq "not" && @$t > 1 && $$t[1][1] eq "in") 1 60 61
Condition58%7/12
$$x[0] eq "id" and $$x[1] eq "in" || $$x[1] eq "not" && @$t > 1 && $$t[1][1] eq "in"
!ll&&!rl&&r
5911
$$x[1] eq "in" or $$x[1] eq "not" and @$t > 1 and $$t[1][1] eq "in"
l!l&&r!l&&!r
101
$$x[1] eq "not" and @$t > 1 and $$t[1][1] eq "in"
!ll&&!rl&&r
100
$$x[1] eq "not" and @$t > 1
!ll&&!rl&&r
100
MC/DC40%2/5
$$x[0] eq "id" and $$x[1] eq "in" || $$x[1] eq "not" && @$t > 1 && $$t[1][1] eq "in"
$$x[0] eq "id" $$x[1] eq "in" $$x[1] eq "not" @$t > 1 $$t[1][1] eq "in"
Truth table50%3/6
A and B or C and D and E
A= $$x[0] eq "id"B= $$x[1] eq "in"C= $$x[1] eq "not"D= @$t > 1E= $$t[1][1] eq "in"
ABCDEresult
0XXXX0
100XX0
1010X0
101100
11XXX1
101111
713 1 ▶ my $neg = $x->[1] eq 'not' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$$x[1] eq 'not' ? : 0 1 1
714 1 ▶ shift @$t; shift @$t if $neg;
Branch: 1 branch
BranchTrueFalseTotal
if $neg 0 1 1
715 1 ▶ die "syntax\n" unless @$t && $t->[0][1] eq '(';
Branch: 1 branch
BranchTrueFalseTotal
unless @$t and $$t[0][1] eq "(" 0 1 1
Condition33%1/3
@$t and $$t[0][1] eq "("
!ll&&!rl&&r
001
MC/DC0%0/2
@$t and $$t[0][1] eq "("
@$t $$t[0][1] eq "("
Truth table33%1/3
A and B
A= @$tB= $$t[0][1] eq "("
ABresult
0X0
100
111
716 1 shift @$t;
717 1 my @v;
718 1 ▶ while ( @$t && $t->[0][1] ne ')' ) { push @v, _p_prim($t); shift @$t if @$t && $t->[0][1] eq ',' }
Branch: 2 branches
BranchTrueFalseTotal
if (@$t and $$t[0][1] ne ")") 2 1 3
if @$t and $$t[0][1] eq "," 1 1 2
Condition66%4/6
@$t and $$t[0][1] ne ")"
!ll&&!rl&&r
012
@$t and $$t[0][1] eq ","
!ll&&!rl&&r
011
MC/DC50%1/2
@$t and $$t[0][1] ne ")"
@$t $$t[0][1] ne ")"
MC/DC50%1/2
@$t and $$t[0][1] eq ","
@$t $$t[0][1] eq ","
Truth table66%2/3
A and B
A= @$tB= $$t[0][1] ne ")"
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= @$tB= $$t[0][1] eq ","
ABresult
0X0
100
111
719 1 shift @$t;
720 1 return [ in => $neg, $l, \@v ];
721 }
722 60 return $l;
723 }
724  
725 136 ▶sub _p_prim {
Subroutine _p_prim: called CC=31 SCAR=39.4
726 136 my ($t) = @_;
727 136 ▶ my $x = shift @$t // die "syntax\n";
Condition50%1/2
shift @$t // die("syntax\n")
l!l
1360
MC/DC0%0/1
shift @$t // die("syntax\n")
shift @$t
Truth table50%1/2
A
A= shift @$t
Aresult
11
00
728 136 my $e;
729 136 ▶ if ( $x->[0] eq 'str' || $x->[0] eq 'num' ) { $e = [ lit => $x->[1] ] }
Branch: 5 branches
BranchTrueFalseTotal
if ($$x[0] eq 'str' or $$x[0] eq 'num') { } 34 102 136
elsif ($$x[1] eq '(') { } 0 102 102
elsif ($$x[1] eq '*') { } 5 97 102
elsif ($$x[0] eq 'id' and $$x[1] =~ /\A(?:true|false|null)\z/) { } 0 97 97
elsif ($$x[0] eq 'id') { } 97 0 97
Condition100%3/3
$$x[0] eq "str" or $$x[0] eq "num"
l!l&&r!l&&!r
295102
MC/DC100%2/2
$$x[0] eq "str" or $$x[0] eq "num"
$$x[0] eq "str" $$x[0] eq "num"
Truth table100%3/3
A or B
A= $$x[0] eq "str"B= $$x[0] eq "num"
ABresult
1X1
011
000
730 0 ▶ elsif ( $x->[1] eq '(' ) { $e = _parse_expr($t); die "syntax\n" unless @$t && shift(@$t)->[1] eq ')' }
Branch: 1 branch
BranchTrueFalseTotal
unless @$t and shift(@$t)->[1] eq ")" 0 0 0
Condition0%0/3
@$t and shift(@$t)->[1] eq ")"
!ll&&!rl&&r
000
MC/DC0%0/2
@$t and shift(@$t)->[1] eq ")"
@$t shift(@$t)->[1] eq ")"
Truth table0%0/3
A and B
A= @$tB= shift(@$t)->[1] eq ")"
ABresult
0X0
100
111
731 5 elsif ( $x->[1] eq '*' ) { $e = ['star'] }
732 0 ▶ elsif ( $x->[0] eq 'id' && $x->[1] =~ /\A(?:true|false|null)\z/ ) { $e = [ lit => $x->[1] eq 'null' ? undef : $x->[1] eq 'true' ? 't' : 'f' ] }
Branch: 2 branches
BranchTrueFalseTotal
$$x[1] eq 'null' ? : 0 0 0
$$x[1] eq 'true' ? : 0 0 0
Condition33%1/3
$$x[0] eq "id" and $$x[1] =~ /\A(?:true|false|null)\z/
!ll&&!rl&&r
0970
MC/DC0%0/2
$$x[0] eq "id" and $$x[1] =~ /\A(?:true|false|null)\z/
$$x[0] eq "id" $$x[1] =~ /\A(?:true|false|null)\z/
Truth table33%1/3
A and B
A= $$x[0] eq "id"B= $$x[1] =~ /\A(?:true|false|null)\z/
ABresult
0X0
100
111
733 elsif ( $x->[0] eq 'id' ) {
734 97 my $name = $x->[1];
735 97 my $qual;
736 97 ▶ if ( @$t && $t->[0][1] eq '.' ) { shift @$t; ( $qual, $name ) = ( $name, ( shift @$t )->[1] ) } # tabelle.spalte
Branch: 1 branch
BranchTrueFalseTotal
if (@$t and $$t[0][1] eq ".") 9 88 97
Condition100%3/3
@$t and $$t[0][1] eq "."
!ll&&!rl&&r
14749
MC/DC100%2/2
@$t and $$t[0][1] eq "."
@$t $$t[0][1] eq "."
Truth table100%3/3
A and B
A= @$tB= $$t[0][1] eq "."
ABresult
0X0
100
111
737 97 ▶ if ( $name eq 'extract' && @$t > 2 && $t->[0][1] eq '(' && $t->[2][1] eq 'from' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($name eq 'extract' and @$t > 2 and $$t[0][1] eq '(' and $$t[2][1] eq 'from') { } 1 96 97
elsif ($name =~ /\A(?:current_timestamp|localtimestamp)\z/) { } 0 96 96
elsif (@$t and $$t[0][1] eq '(') { } 21 75 96
Condition66%6/9
$name eq "extract" and @$t > 2 and $$t[0][1] eq "(" and $$t[2][1] eq "from"
!ll&&!rl&&r
9601
$name eq "extract" and @$t > 2 and $$t[0][1] eq "("
!ll&&!rl&&r
9601
$name eq "extract" and @$t > 2
!ll&&!rl&&r
9601
MC/DC25%1/4
$name eq "extract" and @$t > 2 and $$t[0][1] eq "(" and $$t[2][1] eq "from"
$name eq "extract" @$t > 2 $$t[0][1] eq "(" $$t[2][1] eq "from"
Truth table40%2/5
A and B and C and D
A= $name eq "extract"B= @$t > 2C= $$t[0][1] eq "("D= $$t[2][1] eq "from"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
738 1 shift @$t;
739 1 my $field = ( shift @$t )->[1];
740 1 shift @$t;
741 1 my $arg = _parse_expr($t);
742 1 ▶ die "syntax\n" unless @$t && shift(@$t)->[1] eq ')';
Branch: 1 branch
BranchTrueFalseTotal
unless @$t and shift(@$t)->[1] eq ")" 0 1 1
Condition33%1/3
@$t and shift(@$t)->[1] eq ")"
!ll&&!rl&&r
001
MC/DC0%0/2
@$t and shift(@$t)->[1] eq ")"
@$t shift(@$t)->[1] eq ")"
Truth table33%1/3
A and B
A= @$tB= shift(@$t)->[1] eq ")"
ABresult
0X0
100
111
743 1 $e = [ fn => 'extract', [ [ lit => $field ], $arg ] ];
744 }
745 0 elsif ( $name =~ /\A(?:current_timestamp|localtimestamp)\z/ ) { $e = [ fn => 'now', [] ] }
746 ▶ elsif ( @$t && $t->[0][1] eq '(' ) {
Condition100%3/3
@$t and $$t[0][1] eq "("
!ll&&!rl&&r
185721
MC/DC100%2/2
@$t and $$t[0][1] eq "("
@$t $$t[0][1] eq "("
Truth table100%3/3
A and B
A= @$tB= $$t[0][1] eq "("
ABresult
0X0
100
111
747 21 shift @$t;
748 21 my @args;
749 21 ▶ while ( @$t && $t->[0][1] ne ')' ) { push @args, _parse_expr($t); shift @$t if @$t && $t->[0][1] eq ',' }
Branch: 2 branches
BranchTrueFalseTotal
if (@$t and $$t[0][1] ne ")") 23 21 44
if @$t and $$t[0][1] eq "," 7 16 23
Condition66%4/6
@$t and $$t[0][1] ne ")"
!ll&&!rl&&r
02123
@$t and $$t[0][1] eq ","
!ll&&!rl&&r
0167
MC/DC50%1/2
@$t and $$t[0][1] ne ")"
@$t $$t[0][1] ne ")"
MC/DC50%1/2
@$t and $$t[0][1] eq ","
@$t $$t[0][1] eq ","
Truth table66%2/3
A and B
A= @$tB= $$t[0][1] ne ")"
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= @$tB= $$t[0][1] eq ","
ABresult
0X0
100
111
750 21 ▶ die "syntax\n" unless @$t;
Branch: 1 branch
BranchTrueFalseTotal
unless @$t 0 21 21
751 21 shift @$t;
752 21 $e = [ fn => $name, \@args ];
753 }
754 75 else { $e = [ col => $name, $qual ] }
755 }
756 0 else { die "syntax\n" }
757 136 ▶ while ( @$t && $t->[0][1] eq '::' ) { shift @$t; shift @$t } # Typumwandlung: ohne Wirkung
Branch: 1 branch
BranchTrueFalseTotal
if (@$t and $$t[0][1] eq "::") 2 136 138
Condition100%3/3
@$t and $$t[0][1] eq "::"
!ll&&!rl&&r
52842
MC/DC100%2/2
@$t and $$t[0][1] eq "::"
@$t $$t[0][1] eq "::"
Truth table100%3/3
A and B
A= @$tB= $$t[0][1] eq "::"
ABresult
0X0
100
111
758 136 return $e;
759 }
760  
761 478 ▶sub _truth { my ($v) = @_; return defined $v && $v ne 'f' && $v ne '0' && $v ne '' }
Subroutine _truth: called CC=4 SCAR=14.6
Condition66%6/9
defined $v && $v ne 'f' && $v ne '0' && $v ne ''
!ll&&!rl&&r
1740304
defined $v and $v ne "f" and $v ne 0
!ll&&!rl&&r
1740304
defined $v and $v ne "f"
!ll&&!rl&&r
0174304
MC/DC25%1/4
defined $v && $v ne 'f' && $v ne '0' && $v ne ''
defined $v $v ne "f" $v ne 0 $v ne ''
Truth table40%2/5
A and B and C && D
A= defined $vB= $v ne "f"C= $v ne 0D= $v ne ''
ABCDresult
0XXX0
10XX0
110X0
11100
11111
762  
763 507 ▶sub _cmpv {
Subroutine _cmpv: called CC=7 SCAR=21.8
764 507 my ( $a, $b ) = @_;
765 507 ▶ return ( $a <=> $b ) if defined $a && defined $b && "$a" =~ /\A-?\d+(?:\.\d+)?\z/ && "$b" =~ /\A-?\d+(?:\.\d+)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $a and defined $b and "$a" =~ /\A-?\d+(?:\.\d+)?\z/ and "$b" =~ /\A-?\d+(?:\.\d+)?\z/ 1 506 507
Condition55%5/9
defined $a and defined $b and "$a" =~ /\A-?\d+(?:\.\d+)?\z/ and "$b" =~ /\A-?\d+(?:\.\d+)?\z/
!ll&&!rl&&r
50601
defined $a and defined $b and "$a" =~ /\A-?\d+(?:\.\d+)?\z/
!ll&&!rl&&r
05061
defined $a and defined $b
!ll&&!rl&&r
00507
MC/DC25%1/4
defined $a and defined $b and "$a" =~ /\A-?\d+(?:\.\d+)?\z/ and "$b" =~ /\A-?\d+(?:\.\d+)?\z/
defined $a defined $b "$a" =~ /\A-?\d+(?:\.\d+)?\z/ "$b" =~ /\A-?\d+(?:\.\d+)?\z/
Truth table40%2/5
A and B and C and D
A= defined $aB= defined $bC= "$a" =~ /\A-?\d+(?:\.\d+)?\z/D= "$b" =~ /\A-?\d+(?:\.\d+)?\z/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
766 506 ▶ return ( ( $a // '' ) cmp( $b // '' ) );
Condition50%2/4
$a // ""
l!l
5060
$b // ""
l!l
5060
MC/DC0%0/1
$a // ""
$a
MC/DC0%0/1
$b // ""
$b
Truth table50%1/2
A
A= $a
Aresult
11
00
Truth table50%1/2
A
A= $b
Aresult
11
00
767 }
768  
769 3289 ▶sub _ev {
Subroutine _ev: called CC=50 SCAR=55.3
770 3289 my ( $e, $row, $env ) = @_;
771 3289 my $k = $e->[0];
772 3289 ▶ return $e->[1] if $k eq 'lit';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "lit" 805 2484 3289
773 2484 ▶ if ( $k eq 'col' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "col") 1220 1264 2484
774 1220 ▶ return $row->{"$e->[2].$e->[1]"} if defined $e->[2] && exists $row->{"$e->[2].$e->[1]"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$e[2] and exists $$row{"$$e[2].$$e[1]"} 10 1210 1220
Condition66%2/3
defined $$e[2] and exists $$row{"$$e[2].$$e[1]"}
!ll&&!rl&&r
1210010
MC/DC50%1/2
defined $$e[2] and exists $$row{"$$e[2].$$e[1]"}
defined $$e[2] exists $$row{"$$e[2].$$e[1]"}
Truth table66%2/3
A and B
A= defined $$e[2]B= exists $$row{"$$e[2].$$e[1]"}
ABresult
0X0
100
111
775 # echte Spalte einer Katalog-Sicht, die hier nicht nachgebildet ist: Luecke, kein erfundener Fehler
776 1210 ▶ die "gap\n" if !exists $row->{ $e->[1] } && $env->{view} && $REAL_COLS{ $env->{view} } && $REAL_COLS{ $env->{view} }{ lc $e->[1] };
Branch: 1 branch
BranchTrueFalseTotal
if not exists $$row{$$e[1]} and $$env{"view"} and $Langertha::Holmgang::Sim::Linux::Postgres::REAL_COLS{$$env{"view"}} and $Langertha::Holmgang::Sim::Linux::Postgres::REAL_COLS{$$env{"view"}}{lc $$e[1]} 1 1209 1210
Condition77%7/9
not exists $$row{$$e[1]} and $$env{"view"} and $Langertha::Holmgang::Sim::Linux::Postgres::REAL_COLS{$$env{"view"}} and $Langertha::Holmgang::Sim::Linux::Postgres::REAL_COLS{$$env{"view"}}{lc $$e[1]}
!ll&&!rl&&r
120811
not exists $$row{$$e[1]} and $$env{"view"} and $Langertha::Holmgang::Sim::Linux::Postgres::REAL_COLS{$$env{"view"}}
!ll&&!rl&&r
120802
not exists $$row{$$e[1]} and $$env{"view"}
!ll&&!rl&&r
120802
MC/DC50%2/4
not exists $$row{$$e[1]} and $$env{"view"} and $Langertha::Holmgang::Sim::Linux::Postgres::REAL_COLS{$$env{"view"}} and $Langertha::Holmgang::Sim::Linux::Postgres::REAL_COLS{$$env{"view"}}{lc $$e[1]}
not exists $$row{$$e[1]} $$env{"view"} $Langertha::Holmgang::Sim::Linux::Postgres::REAL_COLS{$$env{"view"}} $Langertha::Holmgang::Sim::Linux::Postgres::REAL_COLS{$$env{"view"}}{lc $$e[1]}
Truth table60%3/5
not(A) and B and C and D
A= not exists $$row{$$e[1]}B= $$env{"view"}C= $Langertha::Holmgang::Sim::Linux::Postgres::REAL_COLS{$$env{"view"}}D= $Langertha::Holmgang::Sim::Linux::Postgres::REAL_COLS{$$env{"view"}}{lc $$e[1]}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
777 1209 ▶ die "column \"$e->[1]\" does not exist\n" unless exists $row->{ $e->[1] };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$row{$$e[1]} 1 1208 1209
778 1208 return $row->{ $e->[1] };
779 }
780 1264 ▶ return ( _truth( _ev( $e->[1], $row, $env ) ) || _truth( _ev( $e->[2], $row, $env ) ) ) ? 't' : 'f' if $k eq 'or';
Branch: 2 branches
BranchTrueFalseTotal
if $k eq "or" 0 1264 1264
_truth(_ev($$e[1], $row, $env)) || _truth(_ev($$e[2], $row, $env)) ? : 0 0 0
Condition0%0/3
_truth(_ev($$e[1], $row, $env)) or _truth(_ev($$e[2], $row, $env))
l!l&&r!l&&!r
000
MC/DC0%0/2
_truth(_ev($$e[1], $row, $env)) or _truth(_ev($$e[2], $row, $env))
_truth(_ev($$e[1], $row, $env)) _truth(_ev($$e[2], $row, $env))
Truth table0%0/3
A or B
A= _truth(_ev($$e[1], $row, $env))B= _truth(_ev($$e[2], $row, $env))
ABresult
1X1
011
000
781 1264 ▶ return ( _truth( _ev( $e->[1], $row, $env ) ) && _truth( _ev( $e->[2], $row, $env ) ) ) ? 't' : 'f' if $k eq 'and';
Branch: 2 branches
BranchTrueFalseTotal
if $k eq "and" 0 1264 1264
_truth(_ev($$e[1], $row, $env)) && _truth(_ev($$e[2], $row, $env)) ? : 0 0 0
Condition0%0/3
_truth(_ev($$e[1], $row, $env)) and _truth(_ev($$e[2], $row, $env))
!ll&&!rl&&r
000
MC/DC0%0/2
_truth(_ev($$e[1], $row, $env)) and _truth(_ev($$e[2], $row, $env))
_truth(_ev($$e[1], $row, $env)) _truth(_ev($$e[2], $row, $env))
Truth table0%0/3
A and B
A= _truth(_ev($$e[1], $row, $env))B= _truth(_ev($$e[2], $row, $env))
ABresult
0X0
100
111
782 1264 ▶ return _truth( _ev( $e->[1], $row, $env ) ) ? 'f' : 't' if $k eq 'not';
Branch: 2 branches
BranchTrueFalseTotal
if $k eq "not" 0 1264 1264
_truth(_ev($$e[1], $row, $env)) ? : 0 0 0
783 1264 ▶ if ( $k eq 'cmp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "cmp") 438 826 1264
784 438 my ( $a, $b ) = ( _ev( $e->[2], $row, $env ), _ev( $e->[3], $row, $env ) );
785 438 ▶ return undef unless defined $a && defined $b;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a and defined $b 0 438 438
Condition33%1/3
defined $a and defined $b
!ll&&!rl&&r
00438
MC/DC0%0/2
defined $a and defined $b
defined $a defined $b
Truth table33%1/3
A and B
A= defined $aB= defined $b
ABresult
0X0
100
111
786 438 my $c = _cmpv( $a, $b );
787 438 my %r = ( '=' => $c == 0, '<>' => $c != 0, '!=' => $c != 0, '<' => $c < 0, '>' => $c > 0, '<=' => $c <= 0, '>=' => $c >= 0 );
788 438 ▶ return $r{ $e->[1] } ? 't' : 'f';
Branch: 1 branch
BranchTrueFalseTotal
$r{$$e[1]} ? : 302 136 438
789 }
790 826 ▶ if ( $k eq 'like' || $k eq 'ilike' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "like" or $k eq "ilike") 0 826 826
Condition33%1/3
$k eq "like" or $k eq "ilike"
l!l&&r!l&&!r
00826
MC/DC0%0/2
$k eq "like" or $k eq "ilike"
$k eq "like" $k eq "ilike"
Truth table33%1/3
A or B
A= $k eq "like"B= $k eq "ilike"
ABresult
1X1
011
000
791 0 my ( $a, $p ) = ( _ev( $e->[1], $row, $env ), _ev( $e->[2], $row, $env ) );
792 0 ▶ return undef unless defined $a;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a 0 0 0
793 0 ▶ my $re = join '', map { $_ eq '%' ? '.*' : $_ eq '_' ? '.' : quotemeta } split //, $p;
Branch: 2 branches
BranchTrueFalseTotal
$_ eq '%' ? : 0 0 0
$_ eq '_' ? : 0 0 0
794 0 ▶ return ( $k eq 'ilike' ? $a =~ /\A$re\z/is : $a =~ /\A$re\z/s ) ? 't' : 'f';
Branch: 2 branches
BranchTrueFalseTotal
($k eq 'ilike' ? $a =~ /\A$re\z/is : $a =~ /\A$re\z/s) ? : 0 0 0
$k eq 'ilike' ? : 0 0 0
795 }
796 826 ▶ if ( $k eq 'is' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "is") 8 818 826
797 8 my $v = _ev( $e->[2], $row, $env );
798 8 ▶ my $r = $e->[3] eq 'null' ? !defined $v : $e->[3] eq 'true' ? _truth($v) : defined $v && !_truth($v);
Branch: 2 branches
BranchTrueFalseTotal
$$e[3] eq 'null' ? : 8 0 8
$$e[3] eq 'true' ? : 0 0 0
Condition0%0/3
defined $v and not _truth($v)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v and not _truth($v)
defined $v not _truth($v)
Truth table0%0/3
A and not(B)
A= defined $vB= not _truth($v)
ABresult
0X0
100
111
799 8 ▶ return ( $e->[1] ? !$r : $r ) ? 't' : 'f';
Branch: 2 branches
BranchTrueFalseTotal
($$e[1] ? !$r : $r) ? : 0 8 8
$$e[1] ? : 8 0 8
800 }
801 818 ▶ if ( $k eq 'in' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "in") 32 786 818
802 32 my $v = _ev( $e->[2], $row, $env );
803 32 my $hit = grep { _cmpv( $v, _ev( $_, $row, $env ) ) == 0 } @{ $e->[3] };
804 32 ▶ return ( $e->[1] ? !$hit : $hit ) ? 't' : 'f';
Branch: 2 branches
BranchTrueFalseTotal
($$e[1] ? !$hit : $hit) ? : 2 30 32
$$e[1] ? : 0 32 32
805 }
806 786 ▶ if ( $k eq 'fn' ) { return _fn( $e->[1], $e->[2], $row, $env ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "fn") 306 480 786
807 480 ▶ if ( $k eq 'arith' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "arith") 480 0 480
808 480 my ( $a, $b ) = ( _ev( $e->[2], $row, $env ), _ev( $e->[3], $row, $env ) );
809 480 ▶ return undef unless defined $a && defined $b;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a and defined $b 0 480 480
Condition33%1/3
defined $a and defined $b
!ll&&!rl&&r
00480
MC/DC0%0/2
defined $a and defined $b
defined $a defined $b
Truth table33%1/3
A and B
A= defined $aB= defined $b
ABresult
0X0
100
111
810 480 ▶ return "$a$b" if $e->[1] eq '||';
Branch: 1 branch
BranchTrueFalseTotal
if $$e[1] eq "||" 384 96 480
811 96 my ( $ea, $eb ) = ( _epoch($a), _epoch($b) );
812 96 ▶ if ( defined $ea && defined $eb && $e->[1] eq '-' ) { # Zeitstempel - Zeitstempel = Intervall
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ea and defined $eb and $$e[1] eq "-") 96 0 96
Condition33%2/6
defined $ea and defined $eb and $$e[1] eq "-"
!ll&&!rl&&r
0096
defined $ea and defined $eb
!ll&&!rl&&r
0096
MC/DC0%0/3
defined $ea and defined $eb and $$e[1] eq "-"
defined $ea defined $eb $$e[1] eq "-"
Truth table25%1/4
A and B and C
A= defined $eaB= defined $ebC= $$e[1] eq "-"
ABCresult
0XX0
10X0
1100
1111
813 96 my $d = $ea - $eb;
814 96 ▶ return sprintf( '%s%02d:%02d:%02d', $d < 0 ? '-' : '', abs($d) / 3600, abs($d) % 3600 / 60, abs($d) % 60 );
Branch: 1 branch
BranchTrueFalseTotal
$d < 0 ? : 0 96 96
815 }
816 0 ▶ die "gap\n" unless "$a" =~ /\A-?\d+(?:\.\d+)?\z/ && "$b" =~ /\A-?\d+(?:\.\d+)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless "$a" =~ /\A-?\d+(?:\.\d+)?\z/ and "$b" =~ /\A-?\d+(?:\.\d+)?\z/ 0 0 0
Condition0%0/3
"$a" =~ /\A-?\d+(?:\.\d+)?\z/ and "$b" =~ /\A-?\d+(?:\.\d+)?\z/
!ll&&!rl&&r
000
MC/DC0%0/2
"$a" =~ /\A-?\d+(?:\.\d+)?\z/ and "$b" =~ /\A-?\d+(?:\.\d+)?\z/
"$a" =~ /\A-?\d+(?:\.\d+)?\z/ "$b" =~ /\A-?\d+(?:\.\d+)?\z/
Truth table0%0/3
A and B
A= "$a" =~ /\A-?\d+(?:\.\d+)?\z/B= "$b" =~ /\A-?\d+(?:\.\d+)?\z/
ABresult
0X0
100
111
817 0 ▶ return $e->[1] eq '+' ? $a + $b : $a - $b;
Branch: 1 branch
BranchTrueFalseTotal
$$e[1] eq '+' ? : 0 0 0
818 }
819 0 die "syntax\n";
820 }
821  
822 # pg_sleep(x): die Anweisung dauerte x s; ab log_min_duration_statement (>= 0) steht sie
823 # mit ihrer Dauer im Log des Clusters (Laufzeitspur _append am Geraet, wie Linux sie liest)
824 4 ▶sub _slept {
Subroutine _slept: called CC=18 SCAR=33.0
825 4 my ( $pg, $sess, $secs, $stmt ) = @_;
826 4 ▶ my $min = _ms( ( $pg->{settings} || {} )->{log_min_duration_statement} );
Condition50%1/2
$$pg{'settings'} || {}
l!l
40
MC/DC0%0/1
$$pg{'settings'} || {}
$$pg{'settings'}
Truth table50%1/2
A
A= $$pg{'settings'}
Aresult
11
00
827 4 ▶ return unless defined $min && $min >= 0 && defined $secs && $secs =~ /\A\d+(?:\.\d+)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min and $min >= 0 and defined $secs and $secs =~ /\A\d+(?:\.\d+)?\z/ 2 2 4
Condition66%6/9
defined $min and $min >= 0 and defined $secs and $secs =~ /\A\d+(?:\.\d+)?\z/
!ll&&!rl&&r
202
defined $min and $min >= 0 and defined $secs
!ll&&!rl&&r
202
defined $min and $min >= 0
!ll&&!rl&&r
022
MC/DC25%1/4
defined $min and $min >= 0 and defined $secs and $secs =~ /\A\d+(?:\.\d+)?\z/
defined $min $min >= 0 defined $secs $secs =~ /\A\d+(?:\.\d+)?\z/
Truth table40%2/5
A and B and C and D
A= defined $minB= $min >= 0C= defined $secsD= $secs =~ /\A\d+(?:\.\d+)?\z/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
828 2 my $ms = $secs * 1000 + 0.412;
829 2 ▶ return if $ms < $min;
Branch: 1 branch
BranchTrueFalseTotal
if $ms < $min 1 1 2
830 1 ▶ my $dev = $sess->{srv} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $dev = $$sess{"srv"} or return 1 0 1
831 1 ▶ my $path = $pg->{log} // '/var/log/postgresql/postgresql-' . ( ( $pg->{cluster} // '15/main' ) =~ s{/}{-}r ) . '.log';
Condition50%2/4
$$pg{"log"} // '/var/log/postgresql/postgresql-' . ($$pg{"cluster"} // "15/main") =~ s[/][-]r . '.log'
l!l
01
$$pg{"cluster"} // "15/main"
l!l
10
MC/DC0%0/1
$$pg{"log"} // '/var/log/postgresql/postgresql-' . ($$pg{"cluster"} // "15/main") =~ s[/][-]r . '.log'
$$pg{"log"}
MC/DC0%0/1
$$pg{"cluster"} // "15/main"
$$pg{"cluster"}
Truth table50%1/2
A
A= $$pg{"log"}
Aresult
11
00
Truth table50%1/2
A
A= $$pg{"cluster"}
Aresult
11
00
832 1 ▶ my $e = ( $dev->{files} || {} )->{$path};
Condition50%1/2
$$dev{'files'} || {}
l!l
10
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
833 1 ▶ my $raw = ref $e eq 'HASH' ? $e->{content} // '' : $e;
Branch: 1 branch
BranchTrueFalseTotal
ref $e eq 'HASH' ? : 1 0 1
Condition50%1/2
$$e{"content"} // ""
l!l
10
MC/DC0%0/1
$$e{"content"} // ""
$$e{"content"}
Truth table50%1/2
A
A= $$e{"content"}
Aresult
11
00
834 1 ▶ return unless defined $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw 0 1 1
835 1 my $t = Langertha::Holmgang::Sim::Linux::Calendar::format_local($NOW); # "Sat 2026-10-24 10:00:00 CEST"
836 1 my ( $d, $zone ) = $t =~ /\A\w+ (\S+ \S+) (\S+)\z/;
837 1 ▶ ( my $st = $stmt // 'SELECT pg_sleep(' . $secs . ')' ) =~ s/\s*;?\s*\z//;
Condition50%1/2
$stmt // 'SELECT pg_sleep(' . $secs . ')'
l!l
10
MC/DC0%0/1
$stmt // 'SELECT pg_sleep(' . $secs . ')'
$stmt
Truth table50%1/2
A
A= $stmt
Aresult
11
00
838 1 ▶ my $old = ( $dev->{_append} || {} )->{$path};
Condition50%1/2
$$dev{'_append'} || {}
l!l
01
MC/DC0%0/1
$$dev{'_append'} || {}
$$dev{'_append'}
Truth table50%1/2
A
A= $$dev{'_append'}
Aresult
11
00
839 0 ▶ my @keep = $old && $old->{base} eq $raw ? @{ $old->{lines} } : ();
Branch: 1 branch
BranchTrueFalseTotal
$old && $$old{'base'} eq $raw ? : 0 1 1
Condition33%1/3
$old and $$old{"base"} eq $raw
!ll&&!rl&&r
100
MC/DC0%0/2
$old and $$old{"base"} eq $raw
$old $$old{"base"} eq $raw
Truth table33%1/3
A and B
A= $oldB= $$old{"base"} eq $raw
ABresult
0X0
100
111
840 1 $dev->{_append}{$path} = { base => $raw, lines => [ @keep, sprintf( '%s.%03d %s [9999] %s@%s LOG: duration: %.3f ms statement: %s', $d, 0, $zone, $sess->{user}, $sess->{db}, $ms, $st ) ] };
841 1 return;
842 }
843  
844 306 ▶sub _fn {
Subroutine _fn: called CC=61 SCAR=53.1
845 306 my ( $name, $args, $row, $env ) = @_;
846 306 my @v = map { _ev( $_, $row, $env ) } grep { $_->[0] ne 'star' } @$args;
847 306 my ( $pg, $sess ) = @{$env}{qw( pg sess )};
848 306 ▶ return _pretty( $v[0] // 0 ) if $name eq 'pg_size_pretty';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "pg_size_pretty" 2 304 306
Condition50%1/2
$v[0] // 0
l!l
20
MC/DC0%0/1
$v[0] // 0
$v[0]
Truth table50%1/2
A
A= $v[0]
Aresult
11
00
849 304 ▶ return $row->{_retained} // 0 if $name eq 'pg_wal_lsn_diff';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "pg_wal_lsn_diff" 2 302 304
Condition50%1/2
$$row{"_retained"} // 0
l!l
20
MC/DC0%0/1
$$row{"_retained"} // 0
$$row{"_retained"}
Truth table50%1/2
A
A= $$row{"_retained"}
Aresult
11
00
850 302 ▶ return '0/9A000000' if $name eq 'pg_current_wal_lsn';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "pg_current_wal_lsn" 2 300 302
851 300 ▶ return 'PostgreSQL 15.8 (Debian 15.8-0+deb12u1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit' if $name eq 'version';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "version" 0 300 300
852 300 ▶ return $sess->{user} if $name eq 'current_user' || $name eq 'session_user';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "current_user" or $name eq "session_user" 0 300 300
Condition33%1/3
$name eq "current_user" or $name eq "session_user"
l!l&&r!l&&!r
00300
MC/DC0%0/2
$name eq "current_user" or $name eq "session_user"
$name eq "current_user" $name eq "session_user"
Truth table33%1/3
A or B
A= $name eq "current_user"B= $name eq "session_user"
ABresult
1X1
011
000
853 300 ▶ return _ts($NOW) if $name eq 'now' || $name eq 'clock_timestamp' || $name eq 'statement_timestamp';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "now" or $name eq "clock_timestamp" or $name eq "statement_timestamp" 96 204 300
Condition66%4/6
$name eq "now" or $name eq "clock_timestamp" or $name eq "statement_timestamp"
l!l&&r!l&&!r
960204
$name eq "now" or $name eq "clock_timestamp"
l!l&&r!l&&!r
960204
MC/DC33%1/3
$name eq "now" or $name eq "clock_timestamp" or $name eq "statement_timestamp"
$name eq "now" $name eq "clock_timestamp" $name eq "statement_timestamp"
Truth table50%2/4
A or B or C
A= $name eq "now"B= $name eq "clock_timestamp"C= $name eq "statement_timestamp"
ABCresult
1XX1
01X1
0011
0000
854 204 ▶ if ( $name eq 'extract' || $name eq 'date_part' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "extract" or $name eq "date_part") 96 108 204
Condition66%2/3
$name eq "extract" or $name eq "date_part"
l!l&&r!l&&!r
960108
MC/DC50%1/2
$name eq "extract" or $name eq "date_part"
$name eq "extract" $name eq "date_part"
Truth table66%2/3
A or B
A= $name eq "extract"B= $name eq "date_part"
ABresult
1X1
011
000
855 96 my ( $f, $v ) = @v;
856 96 ▶ die "gap\n" unless lc( $f // '' ) eq 'epoch' && defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless lc($f // "") eq "epoch" and defined $v 0 96 96
Condition40%2/5
lc($f // "") eq "epoch" and defined $v
!ll&&!rl&&r
0096
$f // ""
l!l
960
MC/DC0%0/2
lc($f // "") eq "epoch" and defined $v
$f defined $v
Truth table33%1/3
A and B
A= $fB= defined $v
ABresult
0X0
100
111
857 96 ▶ return $1 * 3600 + $2 * 60 + $3 if $v =~ /\A(\d+):(\d\d):(\d\d)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /\A(\d+):(\d\d):(\d\d)\z/ 96 0 96
858 0 ▶ return $v =~ /\A-(\d+):(\d\d):(\d\d)\z/ ? -( $1 * 3600 + $2 * 60 + $3 ) : _epoch($v) // die "gap\n";
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /\A-(\d+):(\d\d):(\d\d)\z/ ? : 0 0 0
Condition0%0/2
_epoch($v) // die("gap\n")
l!l
00
MC/DC0%0/1
_epoch($v) // die("gap\n")
_epoch($v)
Truth table0%0/2
A
A= _epoch($v)
Aresult
11
00
859 }
860 108 ▶ return $sess->{db} if $name eq 'current_database';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "current_database" 1 107 108
861 107 ▶ if ( $name eq 'pg_sleep' ) { _slept( $pg, $sess, $v[0], $env->{stmt} ); return '' }
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_sleep") 3 104 107
862 104 ▶ if ( $name eq 'current_setting' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "current_setting") 0 104 104
863 0 ▶ my $s = $pg->{settings}{ $v[0] // '' };
Condition0%0/2
$v[0] // ""
l!l
00
MC/DC0%0/1
$v[0] // ""
$v[0]
Truth table0%0/2
A
A= $v[0]
Aresult
11
00
864 0 ▶ die qq{unrecognized configuration parameter "$v[0]"\n} unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 0 0
865 0 return $s;
866 }
867 104 ▶ if ( $name =~ /\Apg_(?:total_)?relation_size\z|\Apg_table_size\z|\Apg_indexes_size\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\Apg_(?:total_)?relation_size\z|\Apg_table_size\z|\Apg_indexes_size\z/) 0 104 104
868 # Argument: Spalte (relid/oid einer Zeile) oder Name 'schema.tabelle'
869 0 ▶ my $k = defined $v[0] ? _resolve( $pg, $sess, $v[0] ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $v[0] ? : 0 0 0
870 0 ▶ return defined $k ? _bytes( $pg->{tables}{$k}{size} ) : $row->{_size} // 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $k ? : 0 0 0
Condition0%0/2
$$row{"_size"} // 0
l!l
00
MC/DC0%0/1
$$row{"_size"} // 0
$$row{"_size"}
Truth table0%0/2
A
A= $$row{"_size"}
Aresult
11
00
871 }
872 104 ▶ if ( $name =~ /\Ahas_(database|schema|table)_privilege\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\Ahas_(database|schema|table)_privilege\z/) 2 102 104
873 2 my $kind = $1;
874 2 ▶ my ( $who, $obj, $priv ) = @v == 3 ? @v : ( $sess->{user}, @v );
Branch: 1 branch
BranchTrueFalseTotal
@v == 3 ? : 2 0 2
875 2 ▶ die "gap\n" unless defined $obj && defined $priv;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj and defined $priv 0 2 2
Condition33%1/3
defined $obj and defined $priv
!ll&&!rl&&r
002
MC/DC0%0/2
defined $obj and defined $priv
defined $obj defined $priv
Truth table33%1/3
A and B
A= defined $objB= defined $priv
ABresult
0X0
100
111
876 2 ▶ my $key = $kind eq 'database' ? "database:$obj" : $kind eq 'schema' ? "schema:$sess->{db}.$obj" : ( 'table:' . ( _resolve( $pg, $sess, $obj ) // die qq{relation "$obj" does not exist\n} ) );
Branch: 2 branches
BranchTrueFalseTotal
$kind eq 'database' ? : 1 1 2
$kind eq 'schema' ? : 1 0 1
Condition0%0/2
_resolve($pg, $sess, $obj) // die(qq[relation "$obj" does not exist\n])
l!l
00
MC/DC0%0/1
_resolve($pg, $sess, $obj) // die(qq[relation "$obj" does not exist\n])
_resolve($pg, $sess, $obj)
Truth table0%0/2
A
A= _resolve($pg, $sess, $obj)
Aresult
11
00
877 2 ▶ die qq{role "$who" does not exist\n} unless $pg->{roles}{$who};
Branch: 1 branch
BranchTrueFalseTotal
unless $$pg{"roles"}{$who} 0 2 2
878 2 my @p = map { uc s/\A\s+|\s+\z//gr } split /,/, $priv;
879 2 ▶ return ( grep { _has_priv( $pg, $who, $key, $_ ) } @p ) ? 't' : 'f';
Branch: 1 branch
BranchTrueFalseTotal
grep({_has_priv($pg, $who, $key, $_);} @p) ? : 2 0 2
880 }
881 102 ▶ if ( $name eq 'pg_has_role' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_has_role") 1 101 102
882 1 ▶ my ( $who, $role ) = @v == 3 ? @v[ 0, 1 ] : ( $sess->{user}, $v[0] );
Branch: 1 branch
BranchTrueFalseTotal
@v == 3 ? : 1 0 1
883 1 ▶ die qq{role "$role" does not exist\n} unless defined $role && $pg->{roles}{$role};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $role and $$pg{"roles"}{$role} 0 1 1
Condition33%1/3
defined $role and $$pg{"roles"}{$role}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $role and $$pg{"roles"}{$role}
defined $role $$pg{"roles"}{$role}
Truth table33%1/3
A and B
A= defined $roleB= $$pg{"roles"}{$role}
ABresult
0X0
100
111
884 1 ▶ return 't' if _is_super( $pg, $who );
Branch: 1 branch
BranchTrueFalseTotal
if _is_super($pg, $who) 1 0 1
885 0 ▶ return ( grep { $_ eq $role } _memberships( $pg, $who ) ) ? 't' : 'f';
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq $role;} _memberships($pg, $who)) ? : 0 0 0
886 }
887 0 ▶ if ( $name eq 'pg_database_size' ) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_database_size") 0 101 101
888 101 ▶ die "must be superuser\n" if $name =~ /\Apg_(?:reload_conf|drop_replication_slot|terminate_backend|cancel_backend)\z/ && !_is_super( $pg, $sess->{user} );
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\Apg_(?:reload_conf|drop_replication_slot|terminate_backend|cancel_backend)\z/ and not _is_super($pg, $$sess{"user"}) 0 101 101
Condition33%1/3
$name =~ /\Apg_(?:reload_conf|drop_replication_slot|terminate_backend|cancel_backend)\z/ and not _is_super($pg, $$sess{"user"})
!ll&&!rl&&r
01010
MC/DC0%0/2
$name =~ /\Apg_(?:reload_conf|drop_replication_slot|terminate_backend|cancel_backend)\z/ and not _is_super($pg, $$sess{"user"})
$name =~ /\Apg_(?:reload_conf|drop_replication_slot|terminate_backend|cancel_backend)\z/ not _is_super($pg, $$sess{"user"})
Truth table33%1/3
A and not(B)
A= $name =~ /\Apg_(?:reload_conf|drop_replication_slot|terminate_backend|cancel_backend)\z/B= not _is_super($pg, $$sess{"user"})
ABresult
0X0
100
111
889 101 ▶ if ( $name eq 'pg_reload_conf' ) { _apply_config( $sess->{srv}, 0 ); return 't' }
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_reload_conf") 2 99 101
890 99 ▶ if ( $name eq 'pg_drop_replication_slot' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_drop_replication_slot") 2 97 99
891 2 ▶ my $s = $pg->{slots}{ $v[0] // '' } or die qq{replication slot "$v[0]" does not exist\n};
Branch: 1 branch
BranchTrueFalseTotal
my $s = $$pg{"slots"}{$v[0] // ""} or die qq[replication slot "$v[0]" does not exist\n] 2 0 2
Condition50%1/2
$v[0] // ""
l!l
20
MC/DC0%0/1
$v[0] // ""
$v[0]
Truth table50%1/2
A
A= $v[0]
Aresult
11
00
892 2 ▶ die qq{replication slot "$v[0]" is active for PID 3121\n} if $s->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$s{"active"} 1 1 2
893 1 delete $pg->{slots}{ $v[0] };
894 1 $env->{mutated} = 1;
895 1 return '';
896 }
897 97 ▶ if ( $name eq 'pg_terminate_backend' || $name eq 'pg_cancel_backend' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_terminate_backend" or $name eq "pg_cancel_backend") 97 0 97
Condition33%1/3
$name eq "pg_terminate_backend" or $name eq "pg_cancel_backend"
l!l&&r!l&&!r
9700
MC/DC0%0/2
$name eq "pg_terminate_backend" or $name eq "pg_cancel_backend"
$name eq "pg_terminate_backend" $name eq "pg_cancel_backend"
Truth table33%1/3
A or B
A= $name eq "pg_terminate_backend"B= $name eq "pg_cancel_backend"
ABresult
1X1
011
000
898 97 ▶ my $pid = $v[0] // 0;
Condition50%1/2
$v[0] // 0
l!l
970
MC/DC0%0/1
$v[0] // 0
$v[0]
Truth table50%1/2
A
A= $v[0]
Aresult
11
00
899 97 my @rows = _activity_rows($pg);
900 97 my @keep = grep { $_->{pid} != $pid } @rows;
901 97 ▶ return 'f' if @keep == @rows;
Branch: 1 branch
BranchTrueFalseTotal
if @keep == @rows 0 97 97
902 97 ▶ if ( $name eq 'pg_terminate_backend' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "pg_terminate_backend") 97 0 97
903 # der getroffene Eintrag zerfaellt in Einzelzeilen, die uebrigen bleiben
904 97 my @new;
905 97 for my $a ( @{ $pg->{activity} } ) {
906 4562 ▶ my $c = $a->{count} // 1;
Condition100%2/2
$$a{"count"} // 1
l!l
24560
MC/DC100%1/1
$$a{"count"} // 1
$$a{"count"}
Truth table100%2/2
A
A= $$a{"count"}
Aresult
11
00
907 4562 ▶ if ( $pid >= $a->{pid} && $pid < $a->{pid} + $c ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid >= $$a{'pid'} and $pid < $$a{'pid'} + $c) { } 97 4465 4562
Condition66%2/3
$pid >= $$a{"pid"} and $pid < $$a{"pid"} + $c
!ll&&!rl&&r
4465097
MC/DC50%1/2
$pid >= $$a{"pid"} and $pid < $$a{"pid"} + $c
$pid >= $$a{"pid"} $pid < $$a{"pid"} + $c
Truth table66%2/3
A and B
A= $pid >= $$a{"pid"}B= $pid < $$a{"pid"} + $c
ABresult
0X0
100
111
908 97 push @new, map { my %x = ( %$a, pid => $a->{pid} + $_ ); delete $x{count}; \%x } grep { $a->{pid} + $_ != $pid } 0 .. $c - 1;
909 }
910 4465 else { push @new, $a }
911 }
912 97 $pg->{activity} = \@new;
913 }
914 97 return 't';
915 }
916 0 die "function $name() does not exist\n";
917 }
918  
919 # --- Anweisungen -------------------------------------------------------------
920  
921 8 ▶sub _err { my ($m) = @_; return ( "ERROR: $m", 0 ) }
Subroutine _err: called CC=1 SCAR=0.0
922  
923 68 ▶sub _statement {
Subroutine _statement: called CC=103 SCAR=59.6
924 68 my ( $pg, $sess, $st ) = @_;
925 68 my $super = _is_super( $pg, $sess->{user} );
926 68 ▶ return _meta( $pg, $sess, $st ) if $st =~ /\A\\/;
Branch: 1 branch
BranchTrueFalseTotal
if $st =~ /\A\\/ 3 65 68
927 65 ( my $u = $st ) =~ s/\s+/ /g;
928  
929 65 ▶ return ( '', 1 ) if $u =~ /\A(?:BEGIN|COMMIT|ROLLBACK|END|START TRANSACTION)\b/i;
Branch: 1 branch
BranchTrueFalseTotal
if $u =~ /\A(?:BEGIN|COMMIT|ROLLBACK|END|START TRANSACTION)\b/i 0 65 65
930 65 ▶ if ( $u =~ /\ASHOW (\w+)\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\ASHOW (\w+)\z/i) 1 64 65
931 1 my $k = lc $1;
932 1 ▶ return _err(qq{unrecognized configuration parameter "$k"}) unless defined $pg->{settings}{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$pg{"settings"}{$k} 0 1 1
933 1 return ( _table( $sess, [$k], [ [ $pg->{settings}{$k} ] ], text => 1 ), 1 );
934 }
935 64 ▶ if ( $u =~ /\AALTER SYSTEM (SET|RESET) (\w+)(?: ?(?:=|TO) ?(?:'([^']*)'|(\S+)))?\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\AALTER SYSTEM (SET|RESET) (\w+)(?: ?(?:=|TO) ?(?:'([^']*)'|(\S+)))?\z/i) 3 61 64
936 3 ▶ return _err('must be superuser to execute ALTER SYSTEM command') unless $super;
Branch: 1 branch
BranchTrueFalseTotal
unless $super 0 3 3
937 3 ▶ my ( $op, $k, $v ) = ( uc $1, lc $2, $3 // $4 );
Condition66%2/3
$3 // $4
l!l&&r!l&&!r
012
MC/DC50%1/2
$3 // $4
$3 $4
Truth table66%2/3
A // B
A= $3B= $4
ABresult
1X1
011
000
938 3 my $path = $pg->{auto_conf};
939 3 my $dev = $sess->{srv};
940 3 ▶ my @l = grep { !/\A\s*\Q$k\E\s*=/ } split /\n/, _file( $dev, $path ) // '';
Condition50%1/2
_file($dev, $path) // ""
l!l
30
MC/DC0%0/1
_file($dev, $path) // ""
_file($dev, $path)
Truth table50%1/2
A
A= _file($dev, $path)
Aresult
11
00
941 3 ▶ @l = ( '# Do not edit this file manually!', '# It will be overwritten by the ALTER SYSTEM command.' ) unless @l;
Branch: 1 branch
BranchTrueFalseTotal
unless @l 0 3 3
942 3 ▶ push @l, "$k = '$v'" if $op eq 'SET';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "SET" 3 0 3
943 3 _set_file( $dev, $path, join( "\n", @l ) . "\n" );
944 3 return ( 'ALTER SYSTEM', 1 );
945 }
946 61 ▶ if ( $u =~ /\ACHECKPOINT\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\ACHECKPOINT\z/i) 1 60 61
947 1 ▶ return _err('must be superuser to do CHECKPOINT') unless $super;
Branch: 1 branch
BranchTrueFalseTotal
unless $super 0 1 1
948 1 _checkpoint( $pg, $sess->{srv} );
949 1 return ( 'CHECKPOINT', 1 );
950 }
951 60 ▶ if ( $u =~ /\A(VACUUM|ANALYZE)\b ?(.*)\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\A(VACUUM|ANALYZE)\b ?(.*)\z/i) 2 58 60
952 2 my ( $what, $rest ) = ( uc $1, $2 );
953 2 my %opt;
954 2 ▶ $opt{ uc $_ } = 1 for $rest =~ /\A\(([^)]*)\)/ ? split( /\s*,\s*/, $1 ) : ();
Branch: 1 branch
BranchTrueFalseTotal
$rest =~ /\A\(([^)]*)\)/ ? : 1 1 2
955 2 $rest =~ s/\A\([^)]*\)\s*//;
956 2 ▶ while ( $rest =~ s/\A(FULL|FREEZE|VERBOSE|ANALYZE)\b\s*//i ) { $opt{ uc $1 } = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ s/\A(FULL|FREEZE|VERBOSE|ANALYZE)\b\s*//i) 1 2 3
957 2 $opt{ uc $_ } = 1 for map { s/\s+(?:true|on)\z//ir } keys %opt;
958 2 ▶ my @t = length $rest ? map { _resolve( $pg, $sess, $_ ) // return _err(qq{relation "$_" does not exist}) } split /\s*,\s*/, $rest
Condition50%1/2
_resolve($pg, $sess, $_) // (return _err(qq[relation "$_" does not exist]))
l!l
20
MC/DC0%0/1
_resolve($pg, $sess, $_) // (return _err(qq[relation "$_" does not exist]))
_resolve($pg, $sess, $_)
Truth table50%1/2
A
A= _resolve($pg, $sess, $_)
Aresult
11
00
959 0 ▶ : grep { ( split /\./ )[0] eq $sess->{db} } sort keys %{ $pg->{tables} || {} };
Branch: 1 branch
BranchTrueFalseTotal
length $rest ? : 2 0 2
Condition0%0/2
$$pg{'tables'} || {}
l!l
00
MC/DC0%0/1
$$pg{'tables'} || {}
$$pg{'tables'}
Truth table0%0/2
A
A= $$pg{'tables'}
Aresult
11
00
960 2 for my $k (@t) {
961 2 my $x = $pg->{tables}{$k};
962 2 ▶ next unless $super || ( $x->{owner} // '' ) eq $sess->{user};
Branch: 1 branch
BranchTrueFalseTotal
unless $super or ($$x{"owner"} // "") eq $$sess{"user"} 0 2 2
Condition20%1/5
$super or ($$x{"owner"} // "") eq $$sess{"user"}
l!l&&r!l&&!r
200
$$x{"owner"} // ""
l!l
00
MC/DC0%0/2
$super or ($$x{"owner"} // "") eq $$sess{"user"}
$super $$x{"owner"}
Truth table33%1/3
A or B
A= $superB= $$x{"owner"}
ABresult
1X1
011
000
963 2 ▶ if ( $what eq 'VACUUM' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "VACUUM") 2 0 2
964 2 ▶ $x->{n_dead_tup} = 0 if $x->{n_dead_tup};
Branch: 1 branch
BranchTrueFalseTotal
if $$x{"n_dead_tup"} 1 1 2
965 2 $x->{last_vacuum} = '2026-10-20 12:00:00+02';
966 2 ▶ if ( $opt{FULL} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"FULL"}) 1 1 2
967 1 ▶ $x->{rewrites} = ( $x->{rewrites} // 0 ) + 1;
Condition50%1/2
$$x{"rewrites"} // 0
l!l
01
MC/DC0%0/1
$$x{"rewrites"} // 0
$$x{"rewrites"}
Truth table50%1/2
A
A= $$x{"rewrites"}
Aresult
11
00
968 1 ▶ $x->{size} = $x->{size_live} if defined $x->{size_live};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$x{"size_live"} 1 0 1
969 }
970 }
971 2 ▶ $x->{last_analyze} = '2026-10-20 12:00:00+02' if $what eq 'ANALYZE' || $opt{ANALYZE};
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "ANALYZE" or $opt{"ANALYZE"} 1 1 2
Condition66%2/3
$what eq "ANALYZE" or $opt{"ANALYZE"}
l!l&&r!l&&!r
011
MC/DC50%1/2
$what eq "ANALYZE" or $opt{"ANALYZE"}
$what eq "ANALYZE" $opt{"ANALYZE"}
Truth table66%2/3
A or B
A= $what eq "ANALYZE"B= $opt{"ANALYZE"}
ABresult
1X1
011
000
972 }
973 2 return ( $what, 1 );
974 }
975 58 ▶ if ( $u =~ /\AALTER TABLE (?:IF EXISTS )?(?:ONLY )?(\S+) (SET|RESET) ?\((.*)\)\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\AALTER TABLE (?:IF EXISTS )?(?:ONLY )?(\S+) (SET|RESET) ?\((.*)\)\z/i) 2 56 58
976 2 my ( $name, $op, $list ) = ( $1, uc $2, $3 );
977 2 ▶ my $k = _resolve( $pg, $sess, $name ) // return _err(qq{relation "$name" does not exist});
Condition50%1/2
_resolve($pg, $sess, $name) // (return _err(qq[relation "$name" does not exist]))
l!l
20
MC/DC0%0/1
_resolve($pg, $sess, $name) // (return _err(qq[relation "$name" does not exist]))
_resolve($pg, $sess, $name)
Truth table50%1/2
A
A= _resolve($pg, $sess, $name)
Aresult
11
00
978 2 my $x = $pg->{tables}{$k};
979 2 ▶ return _err("must be owner of table $name") unless $super || ( $x->{owner} // '' ) eq $sess->{user};
Branch: 1 branch
BranchTrueFalseTotal
unless $super or ($$x{"owner"} // "") eq $$sess{"user"} 0 2 2
Condition20%1/5
$super or ($$x{"owner"} // "") eq $$sess{"user"}
l!l&&r!l&&!r
200
$$x{"owner"} // ""
l!l
00
MC/DC0%0/2
$super or ($$x{"owner"} // "") eq $$sess{"user"}
$super $$x{"owner"}
Truth table33%1/3
A or B
A= $superB= $$x{"owner"}
ABresult
1X1
011
000
980 2 ▶ my @o = @{ $x->{reloptions} || [] };
Condition50%1/2
$$x{'reloptions'} || []
l!l
20
MC/DC0%0/1
$$x{'reloptions'} || []
$$x{'reloptions'}
Truth table50%1/2
A
A= $$x{'reloptions'}
Aresult
11
00
981 2 for my $item ( split /\s*,\s*/, $list ) {
982 2 ▶ my ( $key, $val ) = $item =~ /\A\s*([\w.]+)\s*(?:=\s*'?([^']*?)'?)?\s*\z/ or return _err('syntax error');
Branch: 1 branch
BranchTrueFalseTotal
() = $item =~ /\A\s*([\w.]+)\s*(?:=\s*'?([^']*?)'?)?\s*\z/ or return _err("syntax error") 2 0 2
983 2 $key = lc $key;
984 2 @o = grep { !/\A\Q$key\E=/ } @o;
985 2 ▶ push @o, "$key=" . _norm_val( $val // 'true' ) =~ s/\Aon\z/true/r =~ s/\Aoff\z/false/r if $op eq 'SET';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "SET" 1 1 2
Condition50%1/2
$val // "true"
l!l
10
MC/DC0%0/1
$val // "true"
$val
Truth table50%1/2
A
A= $val
Aresult
11
00
986 }
987 2 $x->{reloptions} = \@o;
988 2 return ( 'ALTER TABLE', 1 );
989 }
990 56 ▶ if ( $u =~ /\A(CREATE|ALTER) (ROLE|USER) (\S+)(?: (?:WITH )?(.*))?\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\A(CREATE|ALTER) (ROLE|USER) (\S+)(?: (?:WITH )?(.*))?\z/i) 1 55 56
991 1 ▶ my ( $verb, $kind, $name, $opts ) = ( uc $1, uc $2, $3, $4 // '' );
Condition50%1/2
$4 // ""
l!l
10
MC/DC0%0/1
$4 // ""
$4
Truth table50%1/2
A
A= $4
Aresult
11
00
992 1 $name =~ s/\A"|"\z//g;
993 1 ▶ return _err('permission denied to create role') unless $super || ( _role( $pg, $sess->{user} ) || {} )->{createrole};
Branch: 1 branch
BranchTrueFalseTotal
unless $super or (_role($pg, $$sess{"user"}) || {})->{"createrole"} 0 1 1
Condition20%1/5
$super or (_role($pg, $$sess{"user"}) || {})->{"createrole"}
l!l&&r!l&&!r
100
_role($pg, $$sess{'user'}) || {}
l!l
00
MC/DC0%0/2
$super or (_role($pg, $$sess{"user"}) || {})->{"createrole"}
$super _role($pg, $$sess{'user'})
Truth table33%1/3
A or B
A= $superB= _role($pg, $$sess{'user'})
ABresult
1X1
011
000
994 1 my $r = $pg->{roles}{$name};
995 1 ▶ return _err(qq{role "$name" already exists}) if $verb eq 'CREATE' && $r;
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "CREATE" and $r 0 1 1
Condition33%1/3
$verb eq "CREATE" and $r
!ll&&!rl&&r
010
MC/DC0%0/2
$verb eq "CREATE" and $r
$verb eq "CREATE" $r
Truth table33%1/3
A and B
A= $verb eq "CREATE"B= $r
ABresult
0X0
100
111
996 1 ▶ return _err(qq{role "$name" does not exist}) if $verb eq 'ALTER' && !$r;
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "ALTER" and not $r 0 1 1
Condition33%1/3
$verb eq "ALTER" and not $r
!ll&&!rl&&r
100
MC/DC0%0/2
$verb eq "ALTER" and not $r
$verb eq "ALTER" not $r
Truth table33%1/3
A and not(B)
A= $verb eq "ALTER"B= not $r
ABresult
0X0
100
111
997 1 ▶ $r = $pg->{roles}{$name} //= {};
Condition50%1/2
$$pg{"roles"}{$name} //= {}
l!l
01
MC/DC0%0/1
$$pg{"roles"}{$name} //= {}
$$pg{"roles"}{$name}
Truth table50%1/2
A
A= $$pg{"roles"}{$name}
Aresult
11
00
998 1 ▶ $r->{login} = JSON::MaybeXS::true() if $verb eq 'CREATE' && $kind eq 'USER';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "CREATE" and $kind eq "USER" 0 1 1
Condition33%1/3
$verb eq "CREATE" and $kind eq "USER"
!ll&&!rl&&r
010
MC/DC0%0/2
$verb eq "CREATE" and $kind eq "USER"
$verb eq "CREATE" $kind eq "USER"
Truth table33%1/3
A and B
A= $verb eq "CREATE"B= $kind eq "USER"
ABresult
0X0
100
111
999 1 my $err = _role_opts( $pg, $r, $name, $opts );
1000 1 ▶ return _err($err) if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 1 1
1001 1 return ( "$verb ROLE", 1 );
1002 }
1003 55 ▶ if ( $u =~ /\ADROP (?:ROLE|USER) (IF EXISTS )?(\S+)\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\ADROP (?:ROLE|USER) (IF EXISTS )?(\S+)\z/i) 0 55 55
1004 0 ▶ return _err('permission denied to drop role') unless $super;
Branch: 1 branch
BranchTrueFalseTotal
unless $super 0 0 0
1005 0 ▶ delete $pg->{roles}{$2} or ( $1 ? return ( 'DROP ROLE', 1 ) : return _err(qq{role "$2" does not exist}) );
Branch: 2 branches
BranchTrueFalseTotal
delete $$pg{"roles"}{$2} or $1 ? (return "DROP ROLE", 1) : (return _err(qq[role "$2" does not exist])) 0 0 0
$1 ? : 0 0 0
1006 0 return ( 'DROP ROLE', 1 );
1007 }
1008 55 ▶ return _grant( $pg, $sess, $u ) if $u =~ /\A(?:GRANT|REVOKE) /i;
Branch: 1 branch
BranchTrueFalseTotal
if $u =~ /\A(?:GRANT|REVOKE) /i 5 50 55
1009 50 ▶ return _default_privs( $pg, $sess, $u ) if $u =~ /\AALTER DEFAULT PRIVILEGES /i;
Branch: 1 branch
BranchTrueFalseTotal
if $u =~ /\AALTER DEFAULT PRIVILEGES /i 2 48 50
1010 48 ▶ if ( $u =~ /\A(DROP TABLE|TRUNCATE(?: TABLE)?|DELETE FROM) (?:IF EXISTS )?(\S+)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\A(DROP TABLE|TRUNCATE(?: TABLE)?|DELETE FROM) (?:IF EXISTS )?(\S+)/i) 4 44 48
1011 4 my ( $what, $name ) = ( uc $1, $2 );
1012 4 ▶ my $k = _resolve( $pg, $sess, $name ) // return _err(qq{relation "$name" does not exist});
Condition50%1/2
_resolve($pg, $sess, $name) // (return _err(qq[relation "$name" does not exist]))
l!l
40
MC/DC0%0/1
_resolve($pg, $sess, $name) // (return _err(qq[relation "$name" does not exist]))
_resolve($pg, $sess, $name)
Truth table50%1/2
A
A= _resolve($pg, $sess, $name)
Aresult
11
00
1013 4 my $x = $pg->{tables}{$k};
1014 # DROP nur Eigentuemer (auch ueber Mitgliedschaft); DELETE/TRUNCATE auch mit dem Recht
1015 4 ▶ my $own = $super || grep { $_ eq ( $x->{owner} // '' ) } $sess->{user}, _memberships( $pg, $sess->{user} );
Condition60%3/5
$super || grep({$_ eq ($$x{'owner'} // '');} $$sess{'user'}, _memberships($pg, $$sess{'user'}))
l!l&&r!l&&!r
103
$$x{"owner"} // ""
l!l
60
MC/DC50%1/2
$super || grep({$_ eq ($$x{'owner'} // '');} $$sess{'user'}, _memberships($pg, $$sess{'user'}))
$super grep({$_ eq ($$x{'owner'} // '');} $$sess{'user'}, _memberships($pg, $$sess{'user'}))
MC/DC0%0/1
$$x{"owner"} // ""
$$x{"owner"}
Truth table66%2/3
A || B
A= $superB= grep({$_ eq ($$x{'owner'} // '');} $$sess{'user'}, _memberships($pg, $$sess{'user'}))
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$x{"owner"}
Aresult
11
00
1016 4 ▶ my $need = $what eq 'DROP TABLE' ? undef : $what =~ /\ATRUNCATE/ ? 'TRUNCATE' : 'DELETE';
Branch: 2 branches
BranchTrueFalseTotal
$what eq 'DROP TABLE' ? : 1 3 4
$what =~ /\ATRUNCATE/ ? : 0 3 3
1017 4 ▶ return _err("permission denied for table $name") unless $own || defined $need && _has_priv( $pg, $sess->{user}, "table:$k", $need );
Branch: 1 branch
BranchTrueFalseTotal
unless $own or defined $need and _has_priv($pg, $$sess{"user"}, "table:$k", $need) 2 2 4
Condition100%6/6
$own or defined $need and _has_priv($pg, $$sess{"user"}, "table:$k", $need)
l!l&&r!l&&!r
112
defined $need and _has_priv($pg, $$sess{"user"}, "table:$k", $need)
!ll&&!rl&&r
111
MC/DC100%3/3
$own or defined $need and _has_priv($pg, $$sess{"user"}, "table:$k", $need)
$own defined $need _has_priv($pg, $$sess{"user"}, "table:$k", $need)
Truth table100%4/4
A or B and C
A= $ownB= defined $needC= _has_priv($pg, $$sess{"user"}, "table:$k", $need)
ABCresult
1XX1
0111
00X0
0100
1018 0 ▶ if ( $what eq 'DROP TABLE' ) { delete $pg->{tables}{$k}; return ( 'DROP TABLE', 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "DROP TABLE") 0 2 2
1019 2 ▶ my $n = $x->{n_live_tup} // 0;
Condition50%1/2
$$x{"n_live_tup"} // 0
l!l
20
MC/DC0%0/1
$$x{"n_live_tup"} // 0
$$x{"n_live_tup"}
Truth table50%1/2
A
A= $$x{"n_live_tup"}
Aresult
11
00
1020 2 $x->{n_live_tup} = 0;
1021 2 ▶ return ( $what =~ /\ATRUNCATE/ ? 'TRUNCATE TABLE' : "DELETE $n", 1 );
Branch: 1 branch
BranchTrueFalseTotal
$what =~ /\ATRUNCATE/ ? : 0 2 2
1022 }
1023 44 ▶ if ( $u =~ /\ACREATE (UNIQUE )?INDEX (CONCURRENTLY )?(?:IF NOT EXISTS )?(?:(\w+) )?ON (?:ONLY )?(\S+?) ?(?:USING (\w+) ?)?\(([^()]+)\)\s*\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\ACREATE (UNIQUE )?INDEX (CONCURRENTLY )?(?:IF NOT EXISTS )?(?:(\w+) )?ON (?:ONLY )?(\S+?) ?(?:USING (\w+) ?)?\(([^()]+)\)\s*\z/i) 2 42 44
1024 2 ▶ my ( $uniq, $name, $table, $method, $cols ) = ( $1, $3, $4, lc( $5 // 'btree' ), $6 );
Condition50%1/2
$5 // "btree"
l!l
02
MC/DC0%0/1
$5 // "btree"
$5
Truth table50%1/2
A
A= $5
Aresult
11
00
1025 2 ▶ my $k = _resolve( $pg, $sess, $table ) // return _err(qq{relation "$table" does not exist});
Condition50%1/2
_resolve($pg, $sess, $table) // (return _err(qq[relation "$table" does not exist]))
l!l
20
MC/DC0%0/1
_resolve($pg, $sess, $table) // (return _err(qq[relation "$table" does not exist]))
_resolve($pg, $sess, $table)
Truth table50%1/2
A
A= _resolve($pg, $sess, $table)
Aresult
11
00
1026 2 my $x = $pg->{tables}{$k};
1027 2 ▶ return _err("must be owner of table $table") unless $super || ( $x->{owner} // '' ) eq $sess->{user};
Branch: 1 branch
BranchTrueFalseTotal
unless $super or ($$x{"owner"} // "") eq $$sess{"user"} 0 2 2
Condition20%1/5
$super or ($$x{"owner"} // "") eq $$sess{"user"}
l!l&&r!l&&!r
200
$$x{"owner"} // ""
l!l
00
MC/DC0%0/2
$super or ($$x{"owner"} // "") eq $$sess{"user"}
$super $$x{"owner"}
Truth table33%1/3
A or B
A= $superB= $$x{"owner"}
ABresult
1X1
011
000
1028 2 my @c = map { s/\A\s+|\s+\z//gr =~ s/"//gr } split /,/, lc $cols;
1029 2 my ( undef, undef, $t ) = split /\./, $k;
1030 2 ▶ $name //= join( '_', $t, @c, $uniq ? 'key' : 'idx' ) =~ s/\W+/_/gr;
Branch: 1 branch
BranchTrueFalseTotal
$uniq ? : 0 1 1
Condition66%2/3
$name //= join("_", $t, @c, $uniq ? "key" : "idx") =~ s/\W+/_/gr
l!l&&r!l&&!r
110
MC/DC0%0/2
$name //= join("_", $t, @c, $uniq ? "key" : "idx") =~ s/\W+/_/gr
$name join("_", $t, @c, $uniq ? "key" : "idx") =~ s/\W+/_/gr
Truth table66%2/3
A //= B
A= $nameB= join("_", $t, @c, $uniq ? "key" : "idx") =~ s/\W+/_/gr
ABresult
1X1
011
000
1031 2 ▶ return _err(qq{relation "$name" already exists}) if grep { $_->{name} eq $name } @{ $x->{indexes} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$$_{"name"} eq $name;} @{$$x{"indexes"} or [];} 1 1 2
Condition100%2/2
$$x{'indexes'} || []
l!l
11
MC/DC100%1/1
$$x{'indexes'} || []
$$x{'indexes'}
Truth table100%2/2
A
A= $$x{'indexes'}
Aresult
11
00
1032 1 ▶ push @{ $x->{indexes} }, { name => lc $name, columns => \@c, method => $method, ( $uniq ? ( unique => JSON::MaybeXS::true() ) : () ) };
Branch: 1 branch
BranchTrueFalseTotal
$uniq ? : 0 1 1
1033 1 return ( 'CREATE INDEX', 1 );
1034 }
1035 42 ▶ if ( $u =~ /\ADROP INDEX (?:CONCURRENTLY )?(IF EXISTS )?(\S+?)\s*\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\ADROP INDEX (?:CONCURRENTLY )?(IF EXISTS )?(\S+?)\s*\z/i) 1 41 42
1036 1 my ( $ifex, $name ) = ( $1, lc $2 );
1037 1 $name =~ s/\A.*\.//;
1038 1 ▶ for my $x ( values %{ $pg->{tables} || {} } ) {
Condition50%1/2
$$pg{'tables'} || {}
l!l
10
MC/DC0%0/1
$$pg{'tables'} || {}
$$pg{'tables'}
Truth table50%1/2
A
A= $$pg{'tables'}
Aresult
11
00
1039 2 ▶ my @keep = grep { $_->{name} ne $name } @{ $x->{indexes} || [] };
Condition100%2/2
$$x{'indexes'} || []
l!l
11
MC/DC100%1/1
$$x{'indexes'} || []
$$x{'indexes'}
Truth table100%2/2
A
A= $$x{'indexes'}
Aresult
11
00
1040 2 ▶ next if @keep == @{ $x->{indexes} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if @keep == @{$$x{"indexes"} or [];} 1 1 2
Condition100%2/2
$$x{'indexes'} || []
l!l
11
MC/DC100%1/1
$$x{'indexes'} || []
$$x{'indexes'}
Truth table100%2/2
A
A= $$x{'indexes'}
Aresult
11
00
1041 1 ▶ return _err("must be owner of index $name") unless $super;
Branch: 1 branch
BranchTrueFalseTotal
unless $super 0 1 1
1042 1 $x->{indexes} = \@keep;
1043 1 return ( 'DROP INDEX', 1 );
1044 }
1045 0 ▶ return $ifex ? ( 'DROP INDEX', 1 ) : _err(qq{index "$name" does not exist});
Branch: 1 branch
BranchTrueFalseTotal
$ifex ? : 0 0 0
1046 }
1047 41 ▶ if ( $u =~ /\ADROP (DATABASE|SCHEMA) (?:IF EXISTS )?(\S+)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\ADROP (DATABASE|SCHEMA) (?:IF EXISTS )?(\S+)/i) 0 41 41
1048 0 ▶ return _err('must be owner') unless $super;
Branch: 1 branch
BranchTrueFalseTotal
unless $super 0 0 0
1049 0 my ( $kind, $name ) = ( uc $1, $2 );
1050 0 ▶ if ( $kind eq 'DATABASE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq 'DATABASE') { } 0 0 0
1051 0 ▶ delete $pg->{databases}{$name} or return _err(qq{database "$name" does not exist});
Branch: 1 branch
BranchTrueFalseTotal
delete $$pg{"databases"}{$name} or return _err(qq[database "$name" does not exist]) 0 0 0
1052 0 ▶ delete $pg->{tables}{$_} for grep {/\A\Q$name\E\./} keys %{ $pg->{tables} || {} };
Condition0%0/2
$$pg{'tables'} || {}
l!l
00
MC/DC0%0/1
$$pg{'tables'} || {}
$$pg{'tables'}
Truth table0%0/2
A
A= $$pg{'tables'}
Aresult
11
00
1053 }
1054 else {
1055 0 ▶ delete $pg->{schemas}{"$sess->{db}.$name"} or return _err(qq{schema "$name" does not exist});
Branch: 1 branch
BranchTrueFalseTotal
delete $$pg{"schemas"}{qq[$$sess{"db"}.$name]} or return _err(qq[schema "$name" does not exist]) 0 0 0
1056 }
1057 0 return ( "DROP $kind", 1 );
1058 }
1059 41 ▶ if ( $u =~ /\ASELECT\b/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u =~ /\ASELECT\b/i) 40 1 41
1060 40 my $r = eval { _select( $pg, $sess, $st ) };
1061 40 ▶ if ( my $e = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 5 35 40
1062 5 ▶ return _gap($st) if $e eq "gap\n";
Branch: 1 branch
BranchTrueFalseTotal
if $e eq "gap\n" 2 3 5
1063 3 $e =~ s/\s+\z//;
1064 3 ▶ return $e eq 'syntax' ? _gap($st) : _err($e);
Branch: 1 branch
BranchTrueFalseTotal
$e eq 'syntax' ? : 0 3 3
1065 }
1066 35 return ( $r, 1 );
1067 }
1068 1 return _gap($st);
1069 }
1070  
1071 3 ▶sub _gap { my ($st) = @_; push @GAPS, "psql: $st"; return ( '', 0 ) }
Subroutine _gap: called CC=1 SCAR=0.0
1072  
1073 4 ▶sub _checkpoint {
Subroutine _checkpoint: called CC=11 SCAR=35.1
1074 4 my ( $pg, $dev ) = @_;
1075 # max_slot_wal_keep_size: ein Slot, der mehr zurueckhaelt, wird ungueltig
1076 4 ▶ my $lim = $pg->{settings}{max_slot_wal_keep_size} // -1;
Condition50%1/2
$$pg{"settings"}{"max_slot_wal_keep_size"} // -1
l!l
04
MC/DC0%0/1
$$pg{"settings"}{"max_slot_wal_keep_size"} // -1
$$pg{"settings"}{"max_slot_wal_keep_size"}
Truth table50%1/2
A
A= $$pg{"settings"}{"max_slot_wal_keep_size"}
Aresult
11
00
1077 4 ▶ if ( "$lim" ne '-1' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("$lim" ne -1) 0 4 4
1078 0 my $b = _bytes( $lim =~ s/B\z//ir =~ s/\A(\d+)\z/${1}M/r );
1079 0 ▶ for my $s ( values %{ $pg->{slots} || {} } ) {
Condition0%0/2
$$pg{'slots'} || {}
l!l
00
MC/DC0%0/1
$$pg{'slots'} || {}
$$pg{'slots'}
Truth table0%0/2
A
A= $$pg{'slots'}
Aresult
11
00
1080 0 ▶ next if $s->{invalidated} || _bytes( $s->{retained} ) <= $b;
Branch: 1 branch
BranchTrueFalseTotal
if $$s{"invalidated"} or _bytes($$s{"retained"}) <= $b 0 0 0
Condition0%0/3
$$s{"invalidated"} or _bytes($$s{"retained"}) <= $b
l!l&&r!l&&!r
000
MC/DC0%0/2
$$s{"invalidated"} or _bytes($$s{"retained"}) <= $b
$$s{"invalidated"} _bytes($$s{"retained"}) <= $b
Truth table0%0/3
A or B
A= $$s{"invalidated"}B= _bytes($$s{"retained"}) <= $b
ABresult
1X1
011
000
1081 0 $s->{invalidated} = JSON::MaybeXS::true();
1082 0 $s->{retained} = '0';
1083 0 ▶ $s->{active} = JSON::MaybeXS::false() if $s->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $$s{"active"} 0 0 0
1084 }
1085 }
1086 4 ▶ my $path = $pg->{wal} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $path = $$pg{"wal"} or return 4 0 4
1087 4 my $f = $dev->{files}{$path};
1088 4 ▶ return unless ref $f eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $f eq "HASH" 0 4 4
1089 4 my $need = _wal_needed($pg);
1090 4 ▶ $f->{size} = _pretty_size($need) if _bytes( $f->{size} ) > $need;
Branch: 1 branch
BranchTrueFalseTotal
if _bytes($$f{"size"}) > $need 1 3 4
1091 4 return;
1092 }
1093  
1094 1 ▶sub _pretty_size {
Subroutine _pretty_size: called CC=3 SCAR=11.1
1095 1 my ($b) = @_;
1096 1 ▶ for my $u ( [ G => 1024**3 ], [ M => 1024**2 ], [ K => 1024 ] ) { return ( $b / $u->[1] ) . $u->[0] if $b % $u->[1] == 0 }
Branch: 1 branch
BranchTrueFalseTotal
if $b % $$u[1] == 0 1 1 2
1097 0 return $b;
1098 }
1099  
1100 13 ▶sub _resolve {
Subroutine _resolve: called CC=6 SCAR=18.3
1101 13 my ( $pg, $sess, $name ) = @_;
1102 13 $name =~ s/"//g;
1103 13 $name = lc $name;
1104 13 my @p = split /\./, $name;
1105 21 ▶ my @hit = @p == 2 ? grep { $_ eq "$sess->{db}.$name" } keys %{ $pg->{tables} || {} }
Condition50%1/2
$$pg{'tables'} || {}
l!l
120
MC/DC0%0/1
$$pg{'tables'} || {}
$$pg{'tables'}
Truth table50%1/2
A
A= $$pg{'tables'}
Aresult
11
00
1106 13 ▶ : grep { /\A\Q$sess->{db}\E\.[^.]+\.\Q$name\E\z/ } keys %{ $pg->{tables} || {} };
Branch: 1 branch
BranchTrueFalseTotal
@p == 2 ? : 12 1 13
Condition50%1/2
$$pg{'tables'} || {}
l!l
10
MC/DC0%0/1
$$pg{'tables'} || {}
$$pg{'tables'}
Truth table50%1/2
A
A= $$pg{'tables'}
Aresult
11
00
1107 0 ▶ @hit = grep {/\.public\./} @hit if @hit > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @hit > 1 0 13 13
1108 13 ▶ return @hit == 1 ? $hit[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@hit == 1 ? : 12 1 13
1109 }
1110  
1111 1 ▶sub _role_opts {
Subroutine _role_opts: called CC=15 SCAR=47.2
1112 1 my ( $pg, $r, $name, $opts ) = @_;
1113 1 my @w = $opts =~ /('(?:[^']|'')*'|\S+)/g;
1114 1 ▶ while (@w) {
Branch: 1 branch
BranchTrueFalseTotal
if (@w) 1 1 2
1115 1 my $o = uc shift @w;
1116 # Attribute stehen nur, wenn sie gesetzt sind (wie rolsuper = true)
1117 1 ▶ if ( $o =~ /\A(NO)?(SUPERUSER|LOGIN|CREATEDB|CREATEROLE|REPLICATION|BYPASSRLS)\z/ ) {
Branch: 8 branches
BranchTrueFalseTotal
if ($o =~ /\A(NO)?(SUPERUSER|LOGIN|CREATEDB|CREATEROLE|REPLICATION|BYPASSRLS)\z/) { } 1 0 1
elsif ($o eq 'INHERIT') { } 0 0 0
elsif ($o eq 'NOINHERIT') { } 0 0 0
elsif ($o eq 'PASSWORD') { } 0 0 0
elsif ($o eq 'ENCRYPTED') { } 0 0 0
elsif ($o eq 'CONNECTION') { } 0 0 0
elsif ($o eq 'IN') { } 0 0 0
elsif ($o eq 'VALID') { } 0 0 0
1118 1 my $k = lc $2;
1119 0 ▶ if ($1) { delete $r->{$k} } else { $r->{$k} = JSON::MaybeXS::true() }
Branch: 1 branch
BranchTrueFalseTotal
if ($1) { } 0 1 1
1120 }
1121 0 elsif ( $o eq 'INHERIT' ) { delete $r->{noinherit} }
1122 0 elsif ( $o eq 'NOINHERIT' ) { $r->{noinherit} = JSON::MaybeXS::true() }
1123 elsif ( $o eq 'PASSWORD' ) {
1124 0 my $p = shift @w;
1125 0 ▶ if ( uc( $p // '' ) eq 'NULL' ) { delete $r->{password} } else { $r->{password} = JSON::MaybeXS::true() }
Branch: 1 branch
BranchTrueFalseTotal
if (uc($p // '') eq 'NULL') { } 0 0 0
Condition0%0/2
$p // ""
l!l
00
MC/DC0%0/1
$p // ""
$p
Truth table0%0/2
A
A= $p
Aresult
11
00
1126 }
1127 0 elsif ( $o eq 'ENCRYPTED' ) { next }
1128 0 ▶ elsif ( $o eq 'CONNECTION' ) { shift @w; $r->{connection_limit} = 0 + ( shift(@w) // -1 ) }
Condition0%0/2
shift @w // -1
l!l
00
MC/DC0%0/1
shift @w // -1
shift @w
Truth table0%0/2
A
A= shift @w
Aresult
11
00
1129 elsif ( $o eq 'IN' ) {
1130 0 shift @w;
1131 0 for my $g ( split /,/, join '', @w ) { push @{ $pg->{members}{$g} }, $name }
1132 0 @w = ();
1133 }
1134 0 elsif ( $o eq 'VALID' ) { shift @w; shift @w }
1135 0 else { return qq{syntax error at or near "$o"} }
1136 }
1137 1 return undef;
1138 }
1139  
1140 4 my %ALL_PRIVS = ( table => [qw( SELECT INSERT UPDATE DELETE TRUNCATE REFERENCES TRIGGER )], schema => [qw( USAGE CREATE )],
1141 database => [qw( CONNECT CREATE TEMPORARY )] );
1142  
1143 6 ▶sub _privs {
Subroutine _privs: called CC=6 SCAR=18.6
1144 6 my ( $list, $kind ) = @_;
1145 6 my @p = map { s/\A\s+|\s+\z//gr } split /,/, uc $list;
1146 0 ▶ return [ @{ $ALL_PRIVS{$kind} } ] if grep { $_ eq 'ALL' || $_ eq 'ALL PRIVILEGES' } @p;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "ALL" or $_ eq "ALL PRIVILEGES";} @p 0 6 6
Condition33%1/3
$_ eq 'ALL' || $_ eq 'ALL PRIVILEGES'
l!l&&r!l&&!r
006
MC/DC0%0/2
$_ eq 'ALL' || $_ eq 'ALL PRIVILEGES'
$_ eq 'ALL' $_ eq 'ALL PRIVILEGES'
Truth table33%1/3
A || B
A= $_ eq 'ALL'B= $_ eq 'ALL PRIVILEGES'
ABresult
1X1
011
000
1147 6 ▶ @p = map { $_ eq 'TEMP' ? 'TEMPORARY' : $_ } @p;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'TEMP' ? : 0 6 6
1148 6 ▶ for my $x (@p) { die qq{invalid privilege type $x for } . lc($kind) . "\n" unless grep { $_ eq $x } @{ $ALL_PRIVS{$kind} } }
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $x;} @{$ALL_PRIVS{$kind};} 1 5 6
1149 5 return \@p;
1150 }
1151  
1152 5 ▶sub _grant {
Subroutine _grant: called CC=42 SCAR=50.4
1153 5 my ( $pg, $sess, $u ) = @_;
1154 5 my $super = _is_super( $pg, $sess->{user} );
1155 5 my ( $verb, $privs, $on, $to ) = $u =~ /\A(GRANT|REVOKE) (.+?) ON (.+?) (?:TO|FROM) (.+?)(?: WITH GRANT OPTION)?(?: CASCADE| RESTRICT)?\z/i;
1156 5 ▶ if ( !$verb ) { # GRANT rolle TO rolle
Branch: 1 branch
BranchTrueFalseTotal
unless ($verb) 0 5 5
1157 0 ▶ my ( $v, $roles, $who ) = $u =~ /\A(GRANT|REVOKE) (\S+(?:\s*,\s*\S+)*) (?:TO|FROM) (.+)\z/i or return _gap($u);
Branch: 1 branch
BranchTrueFalseTotal
() = $u =~ /\A(GRANT|REVOKE) (\S+(?:\s*,\s*\S+)*) (?:TO|FROM) (.+)\z/i or return _gap($u) 0 0 0
1158 0 for my $g ( split /\s*,\s*/, $roles ) {
1159 0 ▶ return _err(qq{role "$g" does not exist}) unless $pg->{roles}{$g};
Branch: 1 branch
BranchTrueFalseTotal
unless $$pg{"roles"}{$g} 0 0 0
1160 0 for my $w ( split /\s*,\s*/, $who ) {
1161 0 ▶ return _err(qq{role "$w" does not exist}) unless $pg->{roles}{$w};
Branch: 1 branch
BranchTrueFalseTotal
unless $$pg{"roles"}{$w} 0 0 0
1162 0 ▶ my $m = $pg->{members}{$g} //= [];
Condition0%0/2
$$pg{"members"}{$g} //= []
l!l
00
MC/DC0%0/1
$$pg{"members"}{$g} //= []
$$pg{"members"}{$g}
Truth table0%0/2
A
A= $$pg{"members"}{$g}
Aresult
11
00
1163 0 @$m = grep { $_ ne $w } @$m;
1164 0 ▶ push @$m, $w if uc $v eq 'GRANT';
Branch: 1 branch
BranchTrueFalseTotal
if uc $v eq "GRANT" 0 0 0
1165 }
1166 }
1167 0 ▶ return ( uc($v) eq 'GRANT' ? 'GRANT ROLE' : 'REVOKE ROLE', 1 );
Branch: 1 branch
BranchTrueFalseTotal
uc $v eq 'GRANT' ? : 0 0 0
1168 }
1169 5 $verb = uc $verb;
1170 5 my @grantees = map { s/\A"|"\z//gr } split /\s*,\s*/, $to;
1171 5 ▶ for my $g (@grantees) { return _err(qq{role "$g" does not exist}) unless uc $g eq 'PUBLIC' || $pg->{roles}{$g} }
Branch: 1 branch
BranchTrueFalseTotal
unless uc $g eq "PUBLIC" or $$pg{"roles"}{$g} 1 4 5
Condition66%2/3
uc $g eq "PUBLIC" or $$pg{"roles"}{$g}
l!l&&r!l&&!r
041
MC/DC50%1/2
uc $g eq "PUBLIC" or $$pg{"roles"}{$g}
uc $g eq "PUBLIC" $$pg{"roles"}{$g}
Truth table66%2/3
A or B
A= uc $g eq "PUBLIC"B= $$pg{"roles"}{$g}
ABresult
1X1
011
000
1172 4 ▶ @grantees = map { uc $_ eq 'PUBLIC' ? 'PUBLIC' : $_ } @grantees;
Branch: 1 branch
BranchTrueFalseTotal
uc $_ eq 'PUBLIC' ? : 0 4 4
1173 4 my ( $kind, @objs );
1174 4 ▶ if ( $on =~ /\AALL TABLES IN SCHEMA (.+)\z/i ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($on =~ /\AALL TABLES IN SCHEMA (.+)\z/i) { } 1 3 4
elsif ($on =~ /\ASCHEMA (.+)\z/i) { } 1 2 3
elsif ($on =~ /\ADATABASE (.+)\z/i) { } 1 1 2
elsif ($on =~ /\A(?:TABLE )?(.+)\z/i and not $on =~ /\A(?:SEQUENCE|FUNCTION|ALL SEQUENCES|ALL FUNCTIONS|LARGE OBJECT|TABLESPACE|FOREIGN|TYPE|DOMAIN|LANGUAGE)/i) { } 1 0 1
1175 1 $kind = 'table';
1176 1 for my $s ( split /\s*,\s*/, lc $1 ) {
1177 1 ▶ return _err(qq{schema "$s" does not exist}) unless $pg->{schemas}{"$sess->{db}.$s"};
Branch: 1 branch
BranchTrueFalseTotal
unless $$pg{"schemas"}{qq[$$sess{"db"}.$s]} 0 1 1
1178 1 ▶ push @objs, map {"table:$_"} sort grep {/\A\Q$sess->{db}.$s.\E[^.]+\z/} keys %{ $pg->{tables} || {} };
Condition50%1/2
$$pg{'tables'} || {}
l!l
10
MC/DC0%0/1
$$pg{'tables'} || {}
$$pg{'tables'}
Truth table50%1/2
A
A= $$pg{'tables'}
Aresult
11
00
1179 }
1180 }
1181 elsif ( $on =~ /\ASCHEMA (.+)\z/i ) {
1182 1 $kind = 'schema';
1183 1 for my $s ( split /\s*,\s*/, lc $1 ) {
1184 1 ▶ return _err(qq{schema "$s" does not exist}) unless $pg->{schemas}{"$sess->{db}.$s"};
Branch: 1 branch
BranchTrueFalseTotal
unless $$pg{"schemas"}{qq[$$sess{"db"}.$s]} 0 1 1
1185 1 push @objs, "schema:$sess->{db}.$s";
1186 }
1187 }
1188 elsif ( $on =~ /\ADATABASE (.+)\z/i ) {
1189 1 $kind = 'database';
1190 1 for my $d ( split /\s*,\s*/, $1 ) {
1191 1 ▶ return _err(qq{database "$d" does not exist}) unless $pg->{databases}{$d};
Branch: 1 branch
BranchTrueFalseTotal
unless $$pg{"databases"}{$d} 0 1 1
1192 1 push @objs, "database:$d";
1193 }
1194 }
1195 ▶ elsif ( $on =~ /\A(?:TABLE )?(.+)\z/i && $on !~ /\A(?:SEQUENCE|FUNCTION|ALL SEQUENCES|ALL FUNCTIONS|LARGE OBJECT|TABLESPACE|FOREIGN|TYPE|DOMAIN|LANGUAGE)/i ) {
Condition33%1/3
$on =~ /\A(?:TABLE )?(.+)\z/i and not $on =~ /\A(?:SEQUENCE|FUNCTION|ALL SEQUENCES|ALL FUNCTIONS|LARGE OBJECT|TABLESPACE|FOREIGN|TYPE|DOMAIN|LANGUAGE)/i
!ll&&!rl&&r
001
MC/DC0%0/2
$on =~ /\A(?:TABLE )?(.+)\z/i and not $on =~ /\A(?:SEQUENCE|FUNCTION|ALL SEQUENCES|ALL FUNCTIONS|LARGE OBJECT|TABLESPACE|FOREIGN|TYPE|DOMAIN|LANGUAGE)/i
$on =~ /\A(?:TABLE )?(.+)\z/i not $on =~ /\A(?:SEQUENCE|FUNCTION|ALL SEQUENCES|ALL FUNCTIONS|LARGE OBJECT|TABLESPACE|FOREIGN|TYPE|DOMAIN|LANGUAGE)/i
Truth table33%1/3
A and not(B)
A= $on =~ /\A(?:TABLE )?(.+)\z/iB= not $on =~ /\A(?:SEQUENCE|FUNCTION|ALL SEQUENCES|ALL FUNCTIONS|LARGE OBJECT|TABLESPACE|FOREIGN|TYPE|DOMAIN|LANGUAGE)/i
ABresult
0X0
100
111
1196 1 $kind = 'table';
1197 1 for my $t ( split /\s*,\s*/, $1 ) {
1198 1 ▶ my $k = _resolve( $pg, $sess, $t ) // return _err(qq{relation "$t" does not exist});
Condition50%1/2
_resolve($pg, $sess, $t) // (return _err(qq[relation "$t" does not exist]))
l!l
10
MC/DC0%0/1
_resolve($pg, $sess, $t) // (return _err(qq[relation "$t" does not exist]))
_resolve($pg, $sess, $t)
Truth table50%1/2
A
A= _resolve($pg, $sess, $t)
Aresult
11
00
1199 1 push @objs, "table:$k";
1200 }
1201 }
1202 0 else { return _gap($u) }
1203 4 ▶ my $p = eval { _privs( $privs, $kind ) } or return _err( $@ =~ s/\s+\z//r );
Branch: 1 branch
BranchTrueFalseTotal
my $p = eval { do { _privs($privs, $kind) } } or return _err($@ =~ s/\s+\z//r) 3 1 4
1204 3 for my $o (@objs) {
1205 4 ▶ my $owner = $o =~ /\Atable:(.+)\z/ ? $pg->{tables}{$1}{owner} : $o =~ /\Aschema:(.+)\z/ ? $pg->{schemas}{$1}{owner} : $pg->{databases}{ $o =~ s/\Adatabase://r }{owner};
Branch: 2 branches
BranchTrueFalseTotal
$o =~ /\Atable:(.+)\z/ ? : 2 2 4
$o =~ /\Aschema:(.+)\z/ ? : 1 1 2
1206 0 ▶ return _err( 'permission denied for ' . ( split /:/, $o )[0] ) unless $super || grep { $_ eq ( $owner // '' ) } _memberships( $pg, $sess->{user} );
Branch: 1 branch
BranchTrueFalseTotal
unless $super or grep {$_ eq ($owner // "");} _memberships($pg, $$sess{"user"}) 0 4 4
Condition20%1/5
$super or grep {$_ eq ($owner // "");} _memberships($pg, $$sess{"user"})
l!l&&r!l&&!r
400
$owner // ""
l!l
00
MC/DC0%0/2
$super or grep {$_ eq ($owner // "");} _memberships($pg, $$sess{"user"})
$super grep {$_ eq ($owner // "");} _memberships($pg, $$sess{"user"})
MC/DC0%0/1
$owner // ""
$owner
Truth table33%1/3
A or B
A= $superB= grep {$_ eq ($owner // "");} _memberships($pg, $$sess{"user"})
ABresult
1X1
011
000
Truth table0%0/2
A
A= $owner
Aresult
11
00
1207 4 for my $g (@grantees) {
1208 4 ▶ my $cur = $pg->{grants}{$o}{$g} //= [];
Condition50%1/2
$$pg{"grants"}{$o}{$g} //= []
l!l
04
MC/DC0%0/1
$$pg{"grants"}{$o}{$g} //= []
$$pg{"grants"}{$o}{$g}
Truth table50%1/2
A
A= $$pg{"grants"}{$o}{$g}
Aresult
11
00
1209 0 my %h = map { $_ => 1 } @$cur;
1210 0 ▶ if ( $verb eq 'GRANT' ) { $h{$_} = 1 for @$p } else { delete $h{$_} for @$p }
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq 'GRANT') { } 4 0 4
1211 4 ▶ if (%h) { @$cur = sort keys %h }
Branch: 1 branch
BranchTrueFalseTotal
if (%h) { } 4 0 4
1212 else {
1213 0 delete $pg->{grants}{$o}{$g};
1214 0 ▶ delete $pg->{grants}{$o} unless %{ $pg->{grants}{$o} };
Branch: 1 branch
BranchTrueFalseTotal
unless %{$$pg{"grants"}{$o};} 0 0 0
1215 }
1216 }
1217 }
1218 3 return ( $verb, 1 );
1219 }
1220  
1221 2 ▶sub _default_privs {
Subroutine _default_privs: called CC=25 SCAR=44.3
1222 2 my ( $pg, $sess, $u ) = @_;
1223 2 ▶ my ( $for, $schema, $verb, $privs, $on, $who ) = $u =~ /\AALTER DEFAULT PRIVILEGES(?: FOR (?:ROLE|USER) (\S+))?(?: IN SCHEMA (\S+))? (GRANT|REVOKE) (.+?) ON (TABLES|SEQUENCES|FUNCTIONS|ROUTINES|TYPES|SCHEMAS) (?:TO|FROM) (.+?)(?: WITH GRANT OPTION)?\z/i
Branch: 1 branch
BranchTrueFalseTotal
() = $u =~ /\AALTER DEFAULT PRIVILEGES(?: FOR (?:ROLE|USER) (\S+))?(?: IN SCHEMA (\S+))? (GRANT|REVOKE) (.+?) ON (TABLES|SEQUENCES|FUNCTIONS|ROUTINES|TYPES|SCHEMAS) (?:TO|FROM) (.+?)(?: WITH GRANT OPTION)?\z/i or return _err("syntax error") 2 0 2
1224 or return _err('syntax error');
1225 2 ▶ return _gap($u) unless uc $on eq 'TABLES';
Branch: 1 branch
BranchTrueFalseTotal
unless uc $on eq "TABLES" 0 2 2
1226 2 ▶ $for //= $sess->{user};
Condition66%2/3
$for //= $$sess{"user"}
l!l&&r!l&&!r
110
MC/DC0%0/2
$for //= $$sess{"user"}
$for $$sess{"user"}
Truth table66%2/3
A //= B
A= $forB= $$sess{"user"}
ABresult
1X1
011
000
1227 2 ▶ return _err(qq{role "$for" does not exist}) unless $pg->{roles}{$for};
Branch: 1 branch
BranchTrueFalseTotal
unless $$pg{"roles"}{$for} 0 2 2
1228 0 ▶ return _err('permission denied to change default privileges') unless _is_super( $pg, $sess->{user} ) || grep { $_ eq $for } _memberships( $pg, $sess->{user} );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_super($pg, $$sess{"user"}) or grep {$_ eq $for;} _memberships($pg, $$sess{"user"}) 0 2 2
Condition33%1/3
_is_super($pg, $$sess{"user"}) or grep {$_ eq $for;} _memberships($pg, $$sess{"user"})
l!l&&r!l&&!r
200
MC/DC0%0/2
_is_super($pg, $$sess{"user"}) or grep {$_ eq $for;} _memberships($pg, $$sess{"user"})
_is_super($pg, $$sess{"user"}) grep {$_ eq $for;} _memberships($pg, $$sess{"user"})
Truth table33%1/3
A or B
A= _is_super($pg, $$sess{"user"})B= grep {$_ eq $for;} _memberships($pg, $$sess{"user"})
ABresult
1X1
011
000
1229 2 ▶ $schema = lc $schema if defined $schema;
Branch: 1 branch
BranchTrueFalseTotal
if defined $schema 2 0 2
1230 2 ▶ return _err(qq{schema "$schema" does not exist}) if defined $schema && !$pg->{schemas}{"$sess->{db}.$schema"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $schema and not $$pg{"schemas"}{qq[$$sess{"db"}.$schema]} 0 2 2
Condition33%1/3
defined $schema and not $$pg{"schemas"}{qq[$$sess{"db"}.$schema]}
!ll&&!rl&&r
020
MC/DC0%0/2
defined $schema and not $$pg{"schemas"}{qq[$$sess{"db"}.$schema]}
defined $schema not $$pg{"schemas"}{qq[$$sess{"db"}.$schema]}
Truth table33%1/3
A and not(B)
A= defined $schemaB= not $$pg{"schemas"}{qq[$$sess{"db"}.$schema]}
ABresult
0X0
100
111
1231 2 ▶ my $p = eval { _privs( $privs, 'table' ) } or return _err( $@ =~ s/\s+\z//r );
Branch: 1 branch
BranchTrueFalseTotal
my $p = eval { do { _privs($privs, "table") } } or return _err($@ =~ s/\s+\z//r) 2 0 2
1232 2 ▶ my $acl = $pg->{default_acl} //= [];
Condition50%1/2
$$pg{"default_acl"} //= []
l!l
20
MC/DC0%0/1
$$pg{"default_acl"} //= []
$$pg{"default_acl"}
Truth table50%1/2
A
A= $$pg{"default_acl"}
Aresult
11
00
1233 2 for my $g ( split /\s*,\s*/, $who ) {
1234 2 ▶ return _err(qq{role "$g" does not exist}) unless $pg->{roles}{$g} || uc $g eq 'PUBLIC';
Branch: 1 branch
BranchTrueFalseTotal
unless $$pg{"roles"}{$g} or uc $g eq "PUBLIC" 0 2 2
Condition33%1/3
$$pg{"roles"}{$g} or uc $g eq "PUBLIC"
l!l&&r!l&&!r
200
MC/DC0%0/2
$$pg{"roles"}{$g} or uc $g eq "PUBLIC"
$$pg{"roles"}{$g} uc $g eq "PUBLIC"
Truth table33%1/3
A or B
A= $$pg{"roles"}{$g}B= uc $g eq "PUBLIC"
ABresult
1X1
011
000
1235 0 ▶ my ($e) = grep { $_->{role} eq $for && ( $_->{schema} // '' ) eq ( $schema // '' ) && $_->{db} eq $sess->{db} && $_->{grantee} eq $g } @$acl;
Condition0%0/13
$$_{'role'} eq $for && ($$_{'schema'} // '') eq ($schema // '') && $$_{'db'} eq $$sess{'db'} && $$_{'grantee'} eq $g
!ll&&!rl&&r
000
$$_{"role"} eq $for and ($$_{"schema"} // "") eq ($schema // "") and $$_{"db"} eq $$sess{"db"}
!ll&&!rl&&r
000
$$_{"role"} eq $for and ($$_{"schema"} // "") eq ($schema // "")
!ll&&!rl&&r
000
$$_{"schema"} // ""
l!l
00
$schema // ""
l!l
00
MC/DC0%0/4
$$_{'role'} eq $for && ($$_{'schema'} // '') eq ($schema // '') && $$_{'db'} eq $$sess{'db'} && $$_{'grantee'} eq $g
$$_{"role"} eq $for $$_{"schema"} $$_{"db"} eq $$sess{"db"} $$_{'grantee'} eq $g
MC/DC0%0/1
$schema // ""
$schema
Truth table0%0/5
A and B and C && D
A= $$_{"role"} eq $forB= $$_{"schema"}C= $$_{"db"} eq $$sess{"db"}D= $$_{'grantee'} eq $g
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/2
A
A= $schema
Aresult
11
00
1236 2 ▶ if ( !$e ) { $e = { role => $for, db => $sess->{db}, ( defined $schema ? ( schema => $schema ) : () ), on => 'tables', grantee => $g, privs => [] }; push @$acl, $e }
Branch: 2 branches
BranchTrueFalseTotal
unless ($e) 2 0 2
defined $schema ? : 2 0 2
1237 0 my %h = map { $_ => 1 } @{ $e->{privs} };
1238 0 ▶ if ( uc $verb eq 'GRANT' ) { $h{$_} = 1 for @$p } else { delete $h{$_} for @$p }
Branch: 1 branch
BranchTrueFalseTotal
if (uc $verb eq 'GRANT') { } 2 0 2
1239 2 $e->{privs} = [ sort keys %h ];
1240 2 @$acl = grep { @{ $_->{privs} } } @$acl;
1241 }
1242 2 return ( 'ALTER DEFAULT PRIVILEGES', 1 );
1243 }
1244  
1245 40 ▶sub _select {
Subroutine _select: called CC=89 SCAR=50.6
1246 40 my ( $pg, $sess, $st ) = @_;
1247 40 ▶ my ( $body ) = $st =~ /\A\s*SELECT\s+(.*?)\s*;?\s*\z/is or die "syntax\n";
Branch: 1 branch
BranchTrueFalseTotal
my($body) = $st =~ /\A\s*SELECT\s+(.*?)\s*;?\s*\z/is or die "syntax\n" 40 0 40
1248 # FROM auf oberster Ebene (nicht in extract(… FROM …) oder in '…')
1249 40 my ( $list, $rest ) = ( $body, undef );
1250 {
1251 40 my ( $d, $q ) = ( 0, 0 );
1252 40 for my $i ( 0 .. length($body) - 1 ) {
1253 1040 my $c = substr( $body, $i, 1 );
1254 1040 ▶ if ( $c eq "'" ) { $q = !$q }
Branch: 5 branches
BranchTrueFalseTotal
if ($c eq q[']) { } 28 1012 1040
elsif ($q) { } 70 942 1012
elsif ($c eq '(') { } 22 920 942
elsif ($c eq ')') { } 22 898 920
elsif (not $d and substr($body, $i) =~ /\A\s+FROM\s+/i) { } 28 977 1005
1255 70 elsif ( $q ) { next }
1256 22 elsif ( $c eq '(' ) { $d++ }
1257 22 elsif ( $c eq ')' ) { $d-- }
1258 ▶ elsif ( !$d && substr( $body, $i ) =~ /\A\s+FROM\s+/i ) {
Condition100%3/3
not $d and substr($body, $i) =~ /\A\s+FROM\s+/i
!ll&&!rl&&r
10776328
MC/DC100%2/2
not $d and substr($body, $i) =~ /\A\s+FROM\s+/i
not $d substr($body, $i) =~ /\A\s+FROM\s+/i
Truth table100%3/3
not(A) and B
A= not $dB= substr($body, $i) =~ /\A\s+FROM\s+/i
ABresult
0X0
100
111
1259 28 ( $list, $rest ) = ( substr( $body, 0, $i ), substr( $body, $i ) =~ s/\A\s+FROM\s+//ir );
1260 28 last;
1261 }
1262 }
1263 }
1264 40 my ( $from, $where, $group, $order, $limit, $join );
1265 40 ▶ if ( defined $rest ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rest) 28 12 40
1266 28 ( $from, my $tail ) = $rest =~ /\A(\S+)\s*(.*)\z/s;
1267 28 ▶ if ( $from =~ /\A(?:pg_catalog\.)?pg_sleep\(\s*([\d.]+)\s*\)\z/i ) { # FROM pg_sleep(x): eine Zeile, die Anweisung dauert x s
Branch: 1 branch
BranchTrueFalseTotal
if ($from =~ /\A(?:pg_catalog\.)?pg_sleep\(\s*([\d.]+)\s*\)\z/i) 1 27 28
1268 1 _slept( $pg, $sess, $1, $st );
1269 1 $from = undef;
1270 1 ▶ $tail =~ s/\A\s*(?:AS\s+)?[a-z_]\w*\s*//i unless $tail =~ /\A\s*(?:WHERE|GROUP|ORDER|LIMIT)\b/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $tail =~ /\A\s*(?:WHERE|GROUP|ORDER|LIMIT)\b/i 1 0 1
1271 1 ▶ die "gap\n" if $tail =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $tail =~ /\S/ 0 1 1
1272 }
1273 28 ▶ die "syntax\n" if defined $from && $from =~ /\(/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $from and $from =~ /\(/ 0 28 28
Condition66%2/3
defined $from and $from =~ /\(/
!ll&&!rl&&r
1270
MC/DC0%0/2
defined $from and $from =~ /\(/
defined $from $from =~ /\(/
Truth table66%2/3
A and B
A= defined $fromB= $from =~ /\(/
ABresult
0X0
100
111
1274 28 ▶ $tail //= '';
Condition50%1/2
$tail //= ""
l!l
280
MC/DC0%0/1
$tail //= ""
$tail
Truth table50%1/2
A
A= $tail
Aresult
11
00
1275 # a [AS] x [INNER|LEFT [OUTER]] JOIN b [AS] y ON … (zwei Quellen; mehr ist eine Luecke)
1276 28 my $kw = qr/(?:WHERE|GROUP|ORDER|LIMIT|JOIN|INNER|LEFT|RIGHT|FULL|CROSS|ON)\b/i;
1277 28 ▶ if ( $tail =~ /\A(?:AS\s+)?(?!$kw)([a-z_]\w*)?\s*(?:(INNER|LEFT(?:\s+OUTER)?)\s+)?JOIN\s+(\S+)\s+(?:AS\s+)?(?!$kw)([a-z_]\w*)?\s*ON\s+(.+?)(?=\s+(?:WHERE|GROUP\s+BY|ORDER\s+BY|LIMIT)\b|\s*\z)(.*)\z/is ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tail =~ /\A(?:AS\s+)?(?!$kw)([a-z_]\w*)?\s*(?:(INNER|LEFT(?:\s+OUTER)?)\s+)?JOIN\s+(\S+)\s+(?:AS\s+)?(?!$kw)([a-z_]\w*)?\s*ON\s+(.+?)(?=\s+(?:WHERE|GROUP\s+BY|ORDER\s+BY|LIMIT)\b|\s*\z)(.*)\z/is) 2 26 28
1278 2 ▶ my ( $a1, $type, $from2, $a2, $on, $after ) = ( $1 // $from, $2 // '', $3, $4 // $3, $5, $6 );
Condition37%3/8
$1 // $from
l!l&&r!l&&!r
200
$2 // ""
l!l
02
$4 // $3
l!l&&r!l&&!r
200
MC/DC0%0/2
$1 // $from
$1 $from
MC/DC0%0/1
$2 // ""
$2
MC/DC0%0/2
$4 // $3
$4 $3
Truth table33%1/3
A // B
A= $1B= $from
ABresult
1X1
011
000
Truth table50%1/2
A
A= $2
Aresult
11
00
Truth table33%1/3
A // B
A= $4B= $3
ABresult
1X1
011
000
1279 2 ▶ die "gap\n" if $after =~ /\bJOIN\b/i;
Branch: 1 branch
BranchTrueFalseTotal
if $after =~ /\bJOIN\b/i 0 2 2
1280 2 ▶ $join = { a1 => lc( $a1 =~ s/\A.*\.//r ), from2 => $from2, a2 => lc( $a2 =~ s/\A.*\.//r ), on => $on, left => ( $type =~ /\ALEFT/i ? 1 : 0 ) };
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /\ALEFT/i ? : 0 2 2
1281 2 $tail = $after;
1282 }
1283 28 ▶ $limit = $1 if $tail =~ s/\s*\bLIMIT\s+(\d+)\s*\z//i;
Branch: 1 branch
BranchTrueFalseTotal
if $tail =~ s/\s*\bLIMIT\s+(\d+)\s*\z//i 5 23 28
1284 28 ▶ $order = $1 if $tail =~ s/\s*\bORDER\s+BY\s+(.+?)\s*\z//is;
Branch: 1 branch
BranchTrueFalseTotal
if $tail =~ s/\s*\bORDER\s+BY\s+(.+?)\s*\z//is 5 23 28
1285 28 ▶ $group = $1 if $tail =~ s/\s*\bGROUP\s+BY\s+(.+?)\s*\z//is;
Branch: 1 branch
BranchTrueFalseTotal
if $tail =~ s/\s*\bGROUP\s+BY\s+(.+?)\s*\z//is 1 27 28
1286 28 ▶ $where = $1 if $tail =~ s/\A\s*WHERE\s+(.+?)\s*\z//is;
Branch: 1 branch
BranchTrueFalseTotal
if $tail =~ s/\A\s*WHERE\s+(.+?)\s*\z//is 15 13 28
1287 28 $tail =~ s/\A\s*(?:AS\s+)?[a-z_]\w*\s*\z//i; # Alias der Tabelle
1288 28 ▶ die "syntax\n" if $tail =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $tail =~ /\S/ 0 28 28
1289 }
1290 40 my $env = { pg => $pg, sess => $sess, stmt => $st };
1291 40 my $rows = [ {} ];
1292 40 ▶ if ( defined $from ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $from) 27 13 40
1293 27 my $v = lc( $from =~ s/\Apg_catalog\.//ir );
1294 27 $rows = _view( $pg, $sess, $v );
1295 27 ▶ $env->{view} = $v if $rows;
Branch: 1 branch
BranchTrueFalseTotal
if $rows 25 2 27
1296 # echter Katalog ohne Nachbildung (nicht: Sichten von Erweiterungen, die hier nicht installiert sind)
1297 27 ▶ die "gap\n" if !$rows && $v =~ /\A(?:pg_[a-z_]+|information_schema\.[a-z_]+)\z/ && $v !~ /\Apg_(?:stat_statements|buffercache|stat_kcache|qualstats)/;
Branch: 1 branch
BranchTrueFalseTotal
if not $rows and $v =~ /\A(?:pg_[a-z_]+|information_schema\.[a-z_]+)\z/ and not $v =~ /\Apg_(?:stat_statements|buffercache|stat_kcache|qualstats)/ 1 26 27
Condition83%5/6
not $rows and $v =~ /\A(?:pg_[a-z_]+|information_schema\.[a-z_]+)\z/ and not $v =~ /\Apg_(?:stat_statements|buffercache|stat_kcache|qualstats)/
!ll&&!rl&&r
2511
not $rows and $v =~ /\A(?:pg_[a-z_]+|information_schema\.[a-z_]+)\z/
!ll&&!rl&&r
2502
MC/DC66%2/3
not $rows and $v =~ /\A(?:pg_[a-z_]+|information_schema\.[a-z_]+)\z/ and not $v =~ /\Apg_(?:stat_statements|buffercache|stat_kcache|qualstats)/
not $rows $v =~ /\A(?:pg_[a-z_]+|information_schema\.[a-z_]+)\z/ not $v =~ /\Apg_(?:stat_statements|buffercache|stat_kcache|qualstats)/
Truth table75%3/4
not(A) and B and not(C)
A= not $rowsB= $v =~ /\A(?:pg_[a-z_]+|information_schema\.[a-z_]+)\z/C= not $v =~ /\Apg_(?:stat_statements|buffercache|stat_kcache|qualstats)/
ABCresult
0XX0
10X0
1100
1111
1298 26 ▶ if ( !$rows ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows) 1 25 26
1299 1 ▶ my $k = _resolve( $pg, $sess, $from ) // die qq{relation "$from" does not exist\n};
Condition50%1/2
_resolve($pg, $sess, $from) // die(qq[relation "$from" does not exist\n])
l!l
01
MC/DC0%0/1
_resolve($pg, $sess, $from) // die(qq[relation "$from" does not exist\n])
_resolve($pg, $sess, $from)
Truth table50%1/2
A
A= _resolve($pg, $sess, $from)
Aresult
11
00
1300 0 my ( undef, $s ) = split /\./, $k;
1301 0 ▶ die "permission denied for schema $s\n" unless _has_priv( $pg, $sess->{user}, "schema:" . join( '.', ( split /\./, $k )[ 0, 1 ] ), 'USAGE' );
Branch: 1 branch
BranchTrueFalseTotal
unless _has_priv($pg, $$sess{"user"}, 'schema:' . join(".", (split(/\./, $k, 0))[0, 1]), "USAGE") 0 0 0
1302 0 ▶ die "permission denied for table " . ( split /\./, $k )[2] . "\n" unless _has_priv( $pg, $sess->{user}, "table:$k", 'SELECT' );
Branch: 1 branch
BranchTrueFalseTotal
unless _has_priv($pg, $$sess{"user"}, "table:$k", "SELECT") 0 0 0
1303 0 ▶ die "gap\n" unless $list =~ /\A\s*count\s*\(\s*\*\s*\)\s*\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $list =~ /\A\s*count\s*\(\s*\*\s*\)\s*\z/i 0 0 0
1304 0 ▶ return _table( $sess, ['count'], [ [ $pg->{tables}{$k}{n_live_tup} // 0 ] ] );
Condition0%0/2
$$pg{"tables"}{$k}{"n_live_tup"} // 0
l!l
00
MC/DC0%0/1
$$pg{"tables"}{$k}{"n_live_tup"} // 0
$$pg{"tables"}{$k}{"n_live_tup"}
Truth table0%0/2
A
A= $$pg{"tables"}{$k}{"n_live_tup"}
Aresult
11
00
1305 }
1306 25 ▶ die "permission denied for view $v\n" if $v eq 'pg_hba_file_rules' && !_is_super( $pg, $sess->{user} );
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "pg_hba_file_rules" and not _is_super($pg, $$sess{"user"}) 0 25 25
Condition33%1/3
$v eq "pg_hba_file_rules" and not _is_super($pg, $$sess{"user"})
!ll&&!rl&&r
2500
MC/DC0%0/2
$v eq "pg_hba_file_rules" and not _is_super($pg, $$sess{"user"})
$v eq "pg_hba_file_rules" not _is_super($pg, $$sess{"user"})
Truth table33%1/3
A and not(B)
A= $v eq "pg_hba_file_rules"B= not _is_super($pg, $$sess{"user"})
ABresult
0X0
100
111
1307 25 ▶ if ($join) {
Branch: 1 branch
BranchTrueFalseTotal
if ($join) 2 23 25
1308 2 my $v2 = lc( $join->{from2} =~ s/\Apg_catalog\.//ir );
1309 2 my $rows2 = _view( $pg, $sess, $v2 );
1310 2 ▶ die "gap\n" if !$rows2 && $v2 =~ /\A(?:pg_[a-z_]+|information_schema\.[a-z_]+)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if not $rows2 and $v2 =~ /\A(?:pg_[a-z_]+|information_schema\.[a-z_]+)\z/ 0 2 2
Condition33%1/3
not $rows2 and $v2 =~ /\A(?:pg_[a-z_]+|information_schema\.[a-z_]+)\z/
!ll&&!rl&&r
200
MC/DC0%0/2
not $rows2 and $v2 =~ /\A(?:pg_[a-z_]+|information_schema\.[a-z_]+)\z/
not $rows2 $v2 =~ /\A(?:pg_[a-z_]+|information_schema\.[a-z_]+)\z/
Truth table33%1/3
not(A) and B
A= not $rows2B= $v2 =~ /\A(?:pg_[a-z_]+|information_schema\.[a-z_]+)\z/
ABresult
0X0
100
111
1311 2 ▶ die qq{relation "$join->{from2}" does not exist\n} unless $rows2;
Branch: 1 branch
BranchTrueFalseTotal
unless $rows2 0 2 2
1312 2 my $on = _parse_expr( _tokens( $join->{on} ) );
1313 2 my @j;
1314 2 for my $ra (@$rows) {
1315 2 my $hit = 0;
1316 2 for my $rb (@$rows2) {
1317 2 my %m = ( %$ra, %$rb, ( map { ( "$join->{a1}.$_" => $ra->{$_} ) } keys %$ra ), ( map { ( "$join->{a2}.$_" => $rb->{$_} ) } keys %$rb ) );
1318 2 ▶ next unless _truth( _ev( $on, \%m, $env ) );
Branch: 1 branch
BranchTrueFalseTotal
unless _truth(_ev($on, \%m, $env)) 0 2 2
1319 2 push @j, \%m;
1320 2 $hit = 1;
1321 }
1322 0 ▶ push @j, { %$ra, ( map { ( "$join->{a1}.$_" => $ra->{$_} ) } keys %$ra ), ( map { ( "$join->{a2}.$_" => undef ) } keys %{ $rows2->[0] || {} } ) }
Condition0%0/2
$$rows2[0] || {}
l!l
00
MC/DC0%0/1
$$rows2[0] || {}
$$rows2[0]
Truth table0%0/2
A
A= $$rows2[0]
Aresult
11
00
1323 2 ▶ if !$hit && $join->{left};
Branch: 1 branch
BranchTrueFalseTotal
if not $hit and $$join{"left"} 0 2 2
Condition33%1/3
not $hit and $$join{"left"}
!ll&&!rl&&r
200
MC/DC0%0/2
not $hit and $$join{"left"}
not $hit $$join{"left"}
Truth table33%1/3
not(A) and B
A= not $hitB= $$join{"left"}
ABresult
0X0
100
111
1324 }
1325 2 $rows = \@j;
1326 2 $env->{view} = undef; # Spaltenpruefung: in einem JOIN mehrere Sichten
1327 }
1328 }
1329 # Auswahlliste
1330 38 my @items;
1331 38 my $t = _tokens($list);
1332 38 ▶ while (@$t) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$t) 73 0 73
1333 73 my $start = scalar @$t;
1334 73 my $e = _parse_expr($t);
1335 73 my $alias;
1336 73 ▶ if ( @$t && $t->[0][1] eq 'as' ) { shift @$t; $alias = ( shift @$t )->[1] }
Branch: 2 branches
BranchTrueFalseTotal
if (@$t and $$t[0][1] eq 'as') { } 1 72 73
elsif (@$t and $$t[0][0] eq 'id' and $$t[0][1] ne ',') { } 0 144 144
Condition100%3/3
@$t and $$t[0][1] eq "as"
!ll&&!rl&&r
37351
MC/DC100%2/2
@$t and $$t[0][1] eq "as"
@$t $$t[0][1] eq "as"
Truth table100%3/3
A and B
A= @$tB= $$t[0][1] eq "as"
ABresult
0X0
100
111
1337 0 ▶ elsif ( @$t && $t->[0][0] eq 'id' && $t->[0][1] ne ',' ) { $alias = ( shift @$t )->[1] }
Condition50%3/6
@$t and $$t[0][0] eq "id" and $$t[0][1] ne ","
!ll&&!rl&&r
7200
@$t and $$t[0][0] eq "id"
!ll&&!rl&&r
37350
MC/DC0%0/3
@$t and $$t[0][0] eq "id" and $$t[0][1] ne ","
@$t $$t[0][0] eq "id" $$t[0][1] ne ","
Truth table50%2/4
A and B and C
A= @$tB= $$t[0][0] eq "id"C= $$t[0][1] ne ","
ABCresult
0XX0
10X0
1100
1111
1338 73 push @items, [ $e, $alias ];
1339 73 ▶ last unless @$t;
Branch: 1 branch
BranchTrueFalseTotal
unless @$t 38 35 73
1340 35 ▶ die "syntax\n" unless $t->[0][1] eq ',';
Branch: 1 branch
BranchTrueFalseTotal
unless $$t[0][1] eq "," 0 35 35
1341 35 shift @$t;
1342 }
1343 38 my @rows = @$rows;
1344 38 ▶ if ( defined $where ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $where) 15 23 38
1345 15 my $w = _parse_expr( _tokens($where) );
1346 15 @rows = grep { _truth( _ev( $w, $_, $env ) ) } @rows;
1347 }
1348 38 ▶ my $is_count = sub { my ($e) = @_; return $e->[0] eq 'fn' && $e->[1] eq 'count' };
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%3/3
$$e[0] eq 'fn' && $$e[1] eq 'count'
!ll&&!rl&&r
54158
MC/DC100%2/2
$$e[0] eq 'fn' && $$e[1] eq 'count'
$$e[0] eq 'fn' $$e[1] eq 'count'
Truth table100%3/3
A && B
A= $$e[0] eq 'fn'B= $$e[1] eq 'count'
ABresult
0X0
100
111
1349 38 my ( @cols, @out );
1350 38 ▶ @cols = map { $_->[1] // ( $_->[0][0] eq 'col' ? $_->[0][1] : $_->[0][0] eq 'fn' ? $_->[0][1] : $_->[0][0] eq 'star' ? '*' : '?column?' ) } @items;
Branch: 3 branches
BranchTrueFalseTotal
$$_[0][0] eq 'col' ? : 50 22 72
$$_[0][0] eq 'fn' ? : 18 4 22
$$_[0][0] eq 'star' ? : 1 3 4
Condition66%2/3
$$_[1] // ($$_[0][0] eq "col" ? $$_[0][1] : ($$_[0][0] eq "fn" ? $$_[0][1] : ($$_[0][0] eq "star" ? "*" : "?column?")))
l!l&&r!l&&!r
1720
MC/DC0%0/2
$$_[1] // ($$_[0][0] eq "col" ? $$_[0][1] : ($$_[0][0] eq "fn" ? $$_[0][1] : ($$_[0][0] eq "star" ? "*" : "?column?")))
$$_[1] ($$_[0][0] eq "col" ? $$_[0][1] : ($$_[0][0] eq "fn" ? $$_[0][1] : ($$_[0][0] eq "star" ? "*" : "?column?")))
Truth table66%2/3
A // B
A= $$_[1]B= ($$_[0][0] eq "col" ? $$_[0][1] : ($$_[0][0] eq "fn" ? $$_[0][1] : ($$_[0][0] eq "star" ? "*" : "?column?")))
ABresult
1X1
011
000
1351 38 ▶ if ( @items == 1 && $items[0][0][0] eq 'star' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@items == 1 and $items[0][0][0] eq 'star') { } 1 37 38
elsif (defined $group or grep {&$is_count($$_[0]);} @items) { } 4 33 37
Condition100%3/3
@items == 1 and $items[0][0][0] eq "star"
!ll&&!rl&&r
19181
MC/DC100%2/2
@items == 1 and $items[0][0][0] eq "star"
@items == 1 $items[0][0][0] eq "star"
Truth table100%3/3
A and B
A= @items == 1B= $items[0][0][0] eq "star"
ABresult
0X0
100
111
1352 0 ▶ @cols = grep { !/\A_/ } sort keys %{ $rows[0] // {} };
Condition50%1/2
$rows[0] // {}
l!l
01
MC/DC0%0/1
$rows[0] // {}
$rows[0]
Truth table50%1/2
A
A= $rows[0]
Aresult
11
00
1353 0 ▶ @cols = grep { !/\A_/ } sort keys %{ ( _view( $pg, $sess, lc $from ) || [ {} ] )->[0] // {} } unless @cols;
Branch: 1 branch
BranchTrueFalseTotal
unless @cols 1 0 1
Condition50%2/4
(_view($pg, $sess, lc $from) || [{}])->[0] // {}
l!l
01
_view($pg, $sess, lc $from) || [{}]
l!l
10
MC/DC0%0/1
(_view($pg, $sess, lc $from) || [{}])->[0] // {}
_view($pg, $sess, lc $from)
Truth table50%1/2
A
A= _view($pg, $sess, lc $from)
Aresult
11
00
1354 0 @out = map { my $r = $_; [ map { $r->{$_} } @cols ] } @rows;
1355 }
1356 70 ▶ elsif ( defined $group || grep { $is_count->( $_->[0] ) } @items ) {
Condition100%3/3
defined $group or grep {&$is_count($$_[0]);} @items
l!l&&r!l&&!r
1333
MC/DC100%2/2
defined $group or grep {&$is_count($$_[0]);} @items
defined $group grep {&$is_count($$_[0]);} @items
Truth table100%3/3
A or B
A= defined $groupB= grep {&$is_count($$_[0]);} @items
ABresult
1X1
011
000
1357 4 ▶ my @g = defined $group ? map { lc s/\A\s+|\s+\z//gr } split /,/, $group : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $group ? : 1 3 4
1358 4 my ( %bucket, @keys );
1359 4 for my $r (@rows) {
1360 194 ▶ my $k = join "\0", map { $r->{$_} // '' } @g;
Condition50%1/2
$$r{$_} // ""
l!l
970
MC/DC0%0/1
$$r{$_} // ""
$$r{$_}
Truth table50%1/2
A
A= $$r{$_}
Aresult
11
00
1361 194 ▶ push @keys, $k unless $bucket{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless $bucket{$k} 3 191 194
1362 194 push @{ $bucket{$k} }, $r;
1363 }
1364 4 ▶ @keys = ('') if !@keys && !@g;
Branch: 1 branch
BranchTrueFalseTotal
unless @keys or @g 2 2 4
Condition66%2/3
@keys or @g
l!l&&r!l&&!r
202
MC/DC50%1/2
@keys or @g
@keys @g
Truth table66%2/3
A or B
A= @keysB= @g
ABresult
1X1
011
000
1365 4 for my $k (@keys) {
1366 5 ▶ my $b = $bucket{$k} || [];
Condition100%2/2
$bucket{$k} || []
l!l
32
MC/DC100%1/1
$bucket{$k} || []
$bucket{$k}
Truth table100%2/2
A
A= $bucket{$k}
Aresult
11
00
1367 5 ▶ push @out, [ map { $is_count->( $_->[0] ) ? scalar @$b : _ev( $_->[0], $b->[0] // {}, $env ) } @items ];
Branch: 1 branch
BranchTrueFalseTotal
&$is_count($$_[0]) ? : 5 2 7
Condition50%1/2
$$b[0] // {}
l!l
20
MC/DC0%0/1
$$b[0] // {}
$$b[0]
Truth table50%1/2
A
A= $$b[0]
Aresult
11
00
1368 }
1369 }
1370 else {
1371 33 @out = map { my $r = $_; [ map { _ev( $_->[0], $r, $env ) } @items ] } @rows;
1372 }
1373 35 ▶ if ( defined $order ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $order) 5 30 35
1374 5 ▶ my @ob = map { my ( $c, $d ) = /\A\s*(\S+)(?:\s+(ASC|DESC))?\s*\z/i; [ lc $c, uc( $d // 'ASC' ) ] } split /,/, $order;
Condition100%2/2
$d // "ASC"
l!l
14
MC/DC100%1/1
$d // "ASC"
$d
Truth table100%2/2
A
A= $d
Aresult
11
00
1375 5 my %ix = map { ( $cols[$_] => $_, ( $_ + 1 ) => $_ ) } 0 .. $#cols;
1376 @out = sort {
1377 5 my $c = 0;
1378 5 for my $o (@ob) {
1379 5 ▶ my $i = $ix{ $o->[0] } // next;
Condition50%1/2
$ix{$$o[0]} // (next)
l!l
50
MC/DC0%0/1
$ix{$$o[0]} // (next)
$ix{$$o[0]}
Truth table50%1/2
A
A= $ix{$$o[0]}
Aresult
11
00
1380 5 $c = _cmpv( $a->[$i], $b->[$i] );
1381 5 ▶ $c = -$c if $o->[1] eq 'DESC';
Branch: 1 branch
BranchTrueFalseTotal
if $$o[1] eq "DESC" 1 4 5
1382 5 ▶ last if $c;
Branch: 1 branch
BranchTrueFalseTotal
if $c 5 0 5
1383 }
1384 $c;
1385 } @out;
1386 }
1387 35 ▶ splice @out, $limit if defined $limit && @out > $limit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $limit and @out > $limit 4 31 35
Condition100%3/3
defined $limit and @out > $limit
!ll&&!rl&&r
3014
MC/DC100%2/2
defined $limit and @out > $limit
defined $limit @out > $limit
Truth table100%3/3
A and B
A= defined $limitB= @out > $limit
ABresult
0X0
100
111
1388 35 return _table( $sess, \@cols, \@out );
1389 }
1390  
1391 3 ▶sub _meta {
Subroutine _meta: called CC=58 SCAR=67.2
1392 3 my ( $pg, $sess, $st ) = @_;
1393 3 my ( $cmd, $arg ) = $st =~ /\A\\(\S+)\s*(.*)\z/;
1394 3 ▶ $cmd //= '';
Condition50%1/2
$cmd //= ""
l!l
30
MC/DC0%0/1
$cmd //= ""
$cmd
Truth table50%1/2
A
A= $cmd
Aresult
11
00
1395 3 ▶ if ( $cmd =~ /\Adu\+?\z|\Adg\+?\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /\Adu\+?\z|\Adg\+?\z/) 1 2 3
1396 1 my @r;
1397 1 ▶ for my $n ( sort keys %{ $pg->{roles} || {} } ) {
Condition50%1/2
$$pg{'roles'} || {}
l!l
10
MC/DC0%0/1
$$pg{'roles'} || {}
$$pg{'roles'}
Truth table50%1/2
A
A= $$pg{'roles'}
Aresult
11
00
1398 4 my $r = $pg->{roles}{$n};
1399 4 my @a;
1400 4 ▶ push @a, 'Superuser' if $r->{superuser};
Branch: 1 branch
BranchTrueFalseTotal
if $$r{"superuser"} 1 3 4
1401 4 ▶ push @a, 'Create role' if $r->{createrole};
Branch: 1 branch
BranchTrueFalseTotal
if $$r{"createrole"} 0 4 4
1402 4 ▶ push @a, 'Create DB' if $r->{createdb};
Branch: 1 branch
BranchTrueFalseTotal
if $$r{"createdb"} 0 4 4
1403 4 ▶ push @a, 'Cannot login' unless $r->{login} || $r->{superuser};
Branch: 1 branch
BranchTrueFalseTotal
unless $$r{"login"} or $$r{"superuser"} 1 3 4
Condition66%2/3
$$r{"login"} or $$r{"superuser"}
l!l&&r!l&&!r
301
MC/DC50%1/2
$$r{"login"} or $$r{"superuser"}
$$r{"login"} $$r{"superuser"}
Truth table66%2/3
A or B
A= $$r{"login"}B= $$r{"superuser"}
ABresult
1X1
011
000
1404 4 ▶ push @a, 'Replication' if $r->{replication};
Branch: 1 branch
BranchTrueFalseTotal
if $$r{"replication"} 0 4 4
1405 4 push @r, [ $n, join( ', ', @a ) ];
1406 }
1407 1 return ( " List of roles\n" . _table( $sess, [ 'Role name', 'Attributes' ], \@r ) =~ s/\n\(\d+ rows?\)\z//r, 1 );
1408 }
1409 0 ▶ if ( $cmd eq 'l' || $cmd eq 'l+' ) { return ( _list_dbs( $pg, $sess ), 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "l" or $cmd eq "l+") 0 2 2
Condition33%1/3
$cmd eq "l" or $cmd eq "l+"
l!l&&r!l&&!r
002
MC/DC0%0/2
$cmd eq "l" or $cmd eq "l+"
$cmd eq "l" $cmd eq "l+"
Truth table33%1/3
A or B
A= $cmd eq "l"B= $cmd eq "l+"
ABresult
1X1
011
000
1410 2 ▶ if ( $cmd eq 'dn' || $cmd eq 'dn+' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "dn" or $cmd eq "dn+") 0 2 2
Condition33%1/3
$cmd eq "dn" or $cmd eq "dn+"
l!l&&r!l&&!r
002
MC/DC0%0/2
$cmd eq "dn" or $cmd eq "dn+"
$cmd eq "dn" $cmd eq "dn+"
Truth table33%1/3
A or B
A= $cmd eq "dn"B= $cmd eq "dn+"
ABresult
1X1
011
000
1411 0 ▶ return ( _table( $sess, [qw( Name Owner )], [ map { [ ( split /\./ )[1], $pg->{schemas}{$_}{owner} ] } sort grep {/\A\Q$sess->{db}\E\./} keys %{ $pg->{schemas} || {} } ] ), 1 );
Condition0%0/2
$$pg{'schemas'} || {}
l!l
00
MC/DC0%0/1
$$pg{'schemas'} || {}
$$pg{'schemas'}
Truth table0%0/2
A
A= $$pg{'schemas'}
Aresult
11
00
1412 }
1413 2 ▶ if ( ( $cmd eq 'd' || $cmd eq 'd+' ) && length $arg ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "d" || $cmd eq "d+" and length $arg) 1 1 2
Condition66%4/6
$cmd eq "d" || $cmd eq "d+" and length $arg
!ll&&!rl&&r
101
$cmd eq "d" or $cmd eq "d+"
l!l&&r!l&&!r
101
MC/DC33%1/3
$cmd eq "d" || $cmd eq "d+" and length $arg
$cmd eq "d" $cmd eq "d+" length $arg
Truth table40%2/5
A or B and C
A= $cmd eq "d"B= $cmd eq "d+"C= length $arg
ABCresult
00X0
1X00
0100
1X11
0111
1414 1 ▶ my $k = _resolve( $pg, $sess, $arg ) // return ( qq{Did not find any relation named "$arg".}, 0 );
Condition50%1/2
_resolve($pg, $sess, $arg) // (return qq[Did not find any relation named "$arg".], 0)
l!l
10
MC/DC0%0/1
_resolve($pg, $sess, $arg) // (return qq[Did not find any relation named "$arg".], 0)
_resolve($pg, $sess, $arg)
Truth table50%1/2
A
A= _resolve($pg, $sess, $arg)
Aresult
11
00
1415 1 my ( undef, $sch, $n ) = split /\./, $k;
1416 1 my $x = $pg->{tables}{$k};
1417 0 ▶ my @cols = map { [ split /\s+/, $_, 2 ] } @{ $x->{columns} || [] };
Condition50%1/2
$$x{'columns'} || []
l!l
01
MC/DC0%0/1
$$x{'columns'} || []
$$x{'columns'}
Truth table50%1/2
A
A= $$x{'columns'}
Aresult
11
00
1418 1 my $t = _table( { fmt => { %{ $sess->{fmt} } } }, [qw( Column Type Collation Nullable Default )],
1419 0 ▶ [ map { [ $_->[0], $_->[1] // 'text', '', '', '' ] } @cols ] ) =~ s/\n\(\d+ rows?\)\z//r;
Condition0%0/2
$$_[1] // "text"
l!l
00
MC/DC0%0/1
$$_[1] // "text"
$$_[1]
Truth table0%0/2
A
A= $$_[1]
Aresult
11
00
1420 1 ▶ my @o = @{ $x->{reloptions} || [] };
Condition50%1/2
$$x{'reloptions'} || []
l!l
10
MC/DC0%0/1
$$x{'reloptions'} || []
$$x{'reloptions'}
Truth table50%1/2
A
A= $$x{'reloptions'}
Aresult
11
00
1421 return ( join( "\n", " Table \"$sch.$n\"", $t,
1422 1 ▶ ( @{ $x->{indexes} || [] } ? ( 'Indexes:', map { qq{ "$_->{name}"} . ( $_->{unique} ? ' UNIQUE,' : '' ) . " $_->{method} (" . join( ', ', @{ $_->{columns} } ) . ')' } @{ $x->{indexes} } ) : () ),
Branch: 4 branches
BranchTrueFalseTotal
@{$$x{'indexes'} or [];} ? : 1 0 1
$$_{'unique'} ? : 0 1 1
$cmd eq 'd+' ? : 0 1 1
@o ? : 0 1 1
Condition50%1/2
$$x{'indexes'} || []
l!l
10
MC/DC0%0/1
$$x{'indexes'} || []
$$x{'indexes'}
Truth table50%1/2
A
A= $$x{'indexes'}
Aresult
11
00
1423 ( $cmd eq 'd+' ? 'Access method: heap' : () ), ( @o ? 'Options: ' . join( ', ', @o ) : () ) ), 1 );
1424 }
1425 1 ▶ if ( $cmd eq 'dt' || $cmd eq 'dt+' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "dt" or $cmd eq "dt+") 0 1 1
Condition33%1/3
$cmd eq "dt" or $cmd eq "dt+"
l!l&&r!l&&!r
001
MC/DC0%0/2
$cmd eq "dt" or $cmd eq "dt+"
$cmd eq "dt" $cmd eq "dt+"
Truth table33%1/3
A or B
A= $cmd eq "dt"B= $cmd eq "dt+"
ABresult
1X1
011
000
1426 0 ▶ my @t = map { my ( undef, $s, $n ) = split /\./; [ $s, $n, 'table', $pg->{tables}{$_}{owner} ] } sort grep {/\A\Q$sess->{db}\E\./} keys %{ $pg->{tables} || {} };
Condition0%0/2
$$pg{'tables'} || {}
l!l
00
MC/DC0%0/1
$$pg{'tables'} || {}
$$pg{'tables'}
Truth table0%0/2
A
A= $$pg{'tables'}
Aresult
11
00
1427 0 ▶ @t = grep { my $x = "$_->[0].$_->[1]"; my $re = $arg =~ s/\./\\./gr =~ s/\*/.*/gr; $x =~ /\A$re\z/ || $_->[1] =~ /\A$re\z/ } @t if length $arg;
Branch: 1 branch
BranchTrueFalseTotal
if length $arg 0 0 0
Condition0%0/3
$x =~ /\A$re\z/ || $$_[1] =~ /\A$re\z/
l!l&&r!l&&!r
000
MC/DC0%0/2
$x =~ /\A$re\z/ || $$_[1] =~ /\A$re\z/
$x =~ /\A$re\z/ $$_[1] =~ /\A$re\z/
Truth table0%0/3
A || B
A= $x =~ /\A$re\z/B= $$_[1] =~ /\A$re\z/
ABresult
1X1
011
000
1428 0 return ( _table( $sess, [qw( Schema Name Type Owner )], \@t ), 1 );
1429 }
1430 1 ▶ if ( $cmd eq 'dp' || $cmd eq 'z' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "dp" or $cmd eq "z") 0 1 1
Condition33%1/3
$cmd eq "dp" or $cmd eq "z"
l!l&&r!l&&!r
001
MC/DC0%0/2
$cmd eq "dp" or $cmd eq "z"
$cmd eq "dp" $cmd eq "z"
Truth table33%1/3
A or B
A= $cmd eq "dp"B= $cmd eq "z"
ABresult
1X1
011
000
1431 0 my @t;
1432 0 ▶ for my $k ( sort grep {/\A\Q$sess->{db}\E\./} keys %{ $pg->{tables} || {} } ) {
Condition0%0/2
$$pg{'tables'} || {}
l!l
00
MC/DC0%0/1
$$pg{'tables'} || {}
$$pg{'tables'}
Truth table0%0/2
A
A= $$pg{'tables'}
Aresult
11
00
1433 0 my ( undef, $s, $n ) = split /\./, $k;
1434 0 ▶ next if length $arg && "$s.$n" !~ /\A\Q$arg\E\z/ && $n ne $arg && $arg !~ /\A\Q$s\E\.\*\z/;
Branch: 1 branch
BranchTrueFalseTotal
if length $arg and not +("$s.$n") =~ /\A\Q$arg\E\z/ and $n ne $arg and not $arg =~ /\A\Q$s\E\.\*\z/ 0 0 0
Condition0%0/9
length $arg and not +("$s.$n") =~ /\A\Q$arg\E\z/ and $n ne $arg and not $arg =~ /\A\Q$s\E\.\*\z/
!ll&&!rl&&r
000
length $arg and not +("$s.$n") =~ /\A\Q$arg\E\z/ and $n ne $arg
!ll&&!rl&&r
000
length $arg and not +("$s.$n") =~ /\A\Q$arg\E\z/
!ll&&!rl&&r
000
MC/DC0%0/4
length $arg and not +("$s.$n") =~ /\A\Q$arg\E\z/ and $n ne $arg and not $arg =~ /\A\Q$s\E\.\*\z/
length $arg not +("$s.$n") =~ /\A\Q$arg\E\z/ $n ne $arg not $arg =~ /\A\Q$s\E\.\*\z/
Truth table0%0/5
A and not(B) and C and not(D)
A= length $argB= not +("$s.$n") =~ /\A\Q$arg\E\z/C= $n ne $argD= not $arg =~ /\A\Q$s\E\.\*\z/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1435 0 ▶ my $g = $pg->{grants}{"table:$k"} || {};
Condition0%0/2
$$pg{'grants'}{"table:$k"} || {}
l!l
00
MC/DC0%0/1
$$pg{'grants'}{"table:$k"} || {}
$$pg{'grants'}{"table:$k"}
Truth table0%0/2
A
A= $$pg{'grants'}{"table:$k"}
Aresult
11
00
1436 0 my $own = $pg->{tables}{$k}{owner};
1437 0 ▶ my $acl = join "\n", map { my $w = $_; ( $w eq 'PUBLIC' ? '' : $w ) . '=' . _acl_letters( $g->{$w} ) . "/$own" } sort keys %$g;
Branch: 1 branch
BranchTrueFalseTotal
$w eq 'PUBLIC' ? : 0 0 0
1438 0 ▶ $acl = "$own=arwdDxt/$own" . ( length $acl ? "\n$acl" : '' ) if %$g;
Branch: 2 branches
BranchTrueFalseTotal
if %$g 0 0 0
length $acl ? : 0 0 0
1439 0 push @t, [ $s, $n, 'table', $acl, '', '' ];
1440 }
1441 0 return ( " Access privileges\n" . _table( $sess, [ 'Schema', 'Name', 'Type', 'Access privileges', 'Column privileges', 'Policies' ], \@t ), 1 );
1442 }
1443 1 ▶ if ( $cmd eq 'ddp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "ddp") 1 0 1
1444 1 ▶ my @t = map { [ $_->{role}, $_->{schema} // '', 'table', ( $_->{grantee} eq 'PUBLIC' ? '' : $_->{grantee} ) . '=' . _acl_letters( $_->{privs} ) . "/$_->{role}" ] }
Branch: 1 branch
BranchTrueFalseTotal
$$_{'grantee'} eq 'PUBLIC' ? : 0 1 1
Condition50%1/2
$$_{"schema"} // ""
l!l
10
MC/DC0%0/1
$$_{"schema"} // ""
$$_{"schema"}
Truth table50%1/2
A
A= $$_{"schema"}
Aresult
11
00
1445 1 ▶ grep { $_->{db} eq $sess->{db} } @{ $pg->{default_acl} || [] };
Condition50%1/2
$$pg{'default_acl'} || []
l!l
10
MC/DC0%0/1
$$pg{'default_acl'} || []
$$pg{'default_acl'}
Truth table50%1/2
A
A= $$pg{'default_acl'}
Aresult
11
00
1446 1 return ( " Default access privileges\n" . _table( $sess, [ 'Owner', 'Schema', 'Type', 'Access privileges' ], \@t ), 1 );
1447 }
1448 0 ▶ if ( $cmd eq 'conninfo' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "conninfo") 0 0 0
1449 0 ▶ return ( qq{You are connected to database "$sess->{db}" as user "$sess->{user}" via socket in "/var/run/postgresql" at port "} . ( $pg->{port} // 5432 ) . '".', 1 );
Condition0%0/2
$$pg{"port"} // 5432
l!l
00
MC/DC0%0/1
$$pg{"port"} // 5432
$$pg{"port"}
Truth table0%0/2
A
A= $$pg{"port"}
Aresult
11
00
1450 }
1451 0 ▶ if ( $cmd eq 'c' || $cmd eq 'connect' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "c" or $cmd eq "connect") 0 0 0
Condition0%0/3
$cmd eq "c" or $cmd eq "connect"
l!l&&r!l&&!r
000
MC/DC0%0/2
$cmd eq "c" or $cmd eq "connect"
$cmd eq "c" $cmd eq "connect"
Truth table0%0/3
A or B
A= $cmd eq "c"B= $cmd eq "connect"
ABresult
1X1
011
000
1452 0 my ($db) = split /\s+/, $arg;
1453 0 ▶ return ( qq{connection to server failed: FATAL: database "$db" does not exist}, 0 ) unless $pg->{databases}{$db} || $db eq 'postgres';
Branch: 1 branch
BranchTrueFalseTotal
unless $$pg{"databases"}{$db} or $db eq "postgres" 0 0 0
Condition0%0/3
$$pg{"databases"}{$db} or $db eq "postgres"
l!l&&r!l&&!r
000
MC/DC0%0/2
$$pg{"databases"}{$db} or $db eq "postgres"
$$pg{"databases"}{$db} $db eq "postgres"
Truth table0%0/3
A or B
A= $$pg{"databases"}{$db}B= $db eq "postgres"
ABresult
1X1
011
000
1454 0 $sess->{db} = $db;
1455 0 return ( qq{You are now connected to database "$db" as user "$sess->{user}".}, 1 );
1456 }
1457 0 ▶ return ( '', 1 ) if $cmd eq 'q' || $cmd eq 'x' || $cmd eq 'timing';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "q" or $cmd eq "x" or $cmd eq "timing" 0 0 0
Condition0%0/6
$cmd eq "q" or $cmd eq "x" or $cmd eq "timing"
l!l&&r!l&&!r
000
$cmd eq "q" or $cmd eq "x"
l!l&&r!l&&!r
000
MC/DC0%0/3
$cmd eq "q" or $cmd eq "x" or $cmd eq "timing"
$cmd eq "q" $cmd eq "x" $cmd eq "timing"
Truth table0%0/4
A or B or C
A= $cmd eq "q"B= $cmd eq "x"C= $cmd eq "timing"
ABCresult
1XX1
01X1
0011
0000
1458 0 return _gap($st);
1459 }
1460  
1461 # ACL wie im Katalog: {rolle=rechte/eigentuemer,…}; ohne Eintraege NULL
1462 8 ▶sub _acl_text {
Subroutine _acl_text: called CC=6 SCAR=18.2
1463 8 my ( $pg, $key, $owner ) = @_;
1464 8 ▶ my $g = ( $pg->{grants} || {} )->{$key} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $g = ($$pg{"grants"} || {})->{$key} or return undef 4 4 8
Condition100%2/2
$$pg{'grants'} || {}
l!l
62
MC/DC100%1/1
$$pg{'grants'} || {}
$$pg{'grants'}
Truth table100%2/2
A
A= $$pg{'grants'}
Aresult
11
00
1465 4 ▶ my @e = map { ( $_ eq 'PUBLIC' ? '' : $_ ) . '=' . _acl_letters( $g->{$_} ) . "/$owner" } grep { @{ $g->{$_} || [] } } sort keys %$g;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'PUBLIC' ? : 0 4 4
Condition50%1/2
$$g{$_} || []
l!l
40
MC/DC0%0/1
$$g{$_} || []
$$g{$_}
Truth table50%1/2
A
A= $$g{$_}
Aresult
11
00
1466 4 ▶ return @e ? '{' . join( ',', @e ) . '}' : undef;
Branch: 1 branch
BranchTrueFalseTotal
@e ? : 4 0 4
1467 }
1468  
1469 5 ▶sub _acl_letters {
Subroutine _acl_letters: called CC=3 SCAR=11.1
1470 5 my ($p) = @_;
1471 5 my %l = ( SELECT => 'r', INSERT => 'a', UPDATE => 'w', DELETE => 'd', TRUNCATE => 'D', REFERENCES => 'x', TRIGGER => 't', USAGE => 'U', CREATE => 'C', CONNECT => 'c', TEMPORARY => 'T' );
1472 5 my $order = 'arwdDxtUCcT';
1473 5 ▶ my %have = map { ( $l{$_} // '' ) => 1 } @{ $p || [] };
Condition50%2/4
$l{$_} // ""
l!l
80
$p || []
l!l
50
MC/DC0%0/1
$l{$_} // ""
$l{$_}
MC/DC0%0/1
$p || []
$p
Truth table50%1/2
A
A= $l{$_}
Aresult
11
00
Truth table50%1/2
A
A= $p
Aresult
11
00
1474 5 return join '', grep { $have{$_} } split //, $order;
1475 }
1476  
1477  
1478 0 ▶sub pg_lsclusters {
Subroutine pg_lsclusters: not called CC=8 SCAR=42.8
Pod documented
1479 0 my ( $dev, $av, $ctx ) = @_;
1480 0 ▶ my $pg = $dev->{postgres} or return ( '', 1 );
Branch: 1 branch
BranchTrueFalseTotal
my $pg = $$dev{"postgres"} or return "", 1 0 0 0
1481 0 ▶ my ( $ver, $name ) = split m{/}, $pg->{cluster} // '15/main';
Condition0%0/2
$$pg{"cluster"} // "15/main"
l!l
00
MC/DC0%0/1
$$pg{"cluster"} // "15/main"
$$pg{"cluster"}
Truth table0%0/2
A
A= $$pg{"cluster"}
Aresult
11
00
1482 0 ▶ my $svc = ( $dev->{services} || {} )->{ $pg->{service} // '' } || {};
Condition0%0/6
($$dev{'services'} || {})->{$$pg{'service'} // ''} || {}
l!l
00
$$dev{'services'} || {}
l!l
00
$$pg{"service"} // ""
l!l
00
MC/DC0%0/1
($$dev{'services'} || {})->{$$pg{'service'} // ''} || {}
$$dev{'services'}
MC/DC0%0/1
$$pg{"service"} // ""
$$pg{"service"}
Truth table0%0/2
A
A= $$dev{'services'}
Aresult
11
00
Truth table0%0/2
A
A= $$pg{"service"}
Aresult
11
00
1483 return ( join( "\n", 'Ver Cluster Port Status Owner Data directory Log file',
1484 sprintf( '%-3s %-7s %-4s %-6s postgres /var/lib/postgresql/%s/%s /var/log/postgresql/postgresql-%s-%s.log',
1485 0 ▶ $ver, $name, $pg->{port} // 5432, $svc->{active} ? 'online' : 'down', $ver, $name, $ver, $name ) ), 1 );
Branch: 1 branch
BranchTrueFalseTotal
$$svc{'active'} ? : 0 0 0
Condition0%0/2
$$pg{"port"} // 5432
l!l
00
MC/DC0%0/1
$$pg{"port"} // 5432
$$pg{"port"}
Truth table0%0/2
A
A= $$pg{"port"}
Aresult
11
00
1486 }
1487  
1488 4 1;
1489  
1490 __END__
« blib/lib/Langertha/Holmgang/Sim/Linux/Git.pm ↑ Summary blib/lib/Langertha/Holmgang/Expectation.pm »