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

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