blib/lib/DBIO/PostgreSQL/Introspect/Policies.pm

filter: Statementstmt 39.2% 11 / 28 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 31.9% 15 / 47 CC 6 SCAR 33.4
CC
6
Cov
28%
fetch
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 28.3
« blib/lib/DBIO/PostgreSQL/Introspect/CheckConstraints.pm ↑ Summary blib/lib/DBIO/PostgreSQL/Introspect/Sequences.pm »
1 package DBIO::PostgreSQL::Introspect::Policies;
2 # ABSTRACT: Introspect PostgreSQL Row Level Security policies
3  
4 171 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 171 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 171 our $VERSION = '0.900007';
8  
9 171 ▶use DBIO::PostgreSQL::Introspect ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12  
13 0 ▶sub fetch {
Subroutine fetch: not called CC=6 SCAR=37.4
Pod documented
14 0 my ($class, $dbh, $filter) = @_;
15  
16 0 my $sql = q{
17 SELECT
18 n.nspname AS schema_name,
19 c.relname AS table_name,
20 p.polname AS policy_name,
21 CASE p.polcmd
22 WHEN 'r' THEN 'SELECT'
23 WHEN 'a' THEN 'INSERT'
24 WHEN 'w' THEN 'UPDATE'
25 WHEN 'd' THEN 'DELETE'
26 WHEN '*' THEN 'ALL'
27 END AS command,
28 p.polpermissive AS permissive,
29 pg_catalog.pg_get_expr(p.polqual, p.polrelid) AS using_expr,
30 pg_catalog.pg_get_expr(p.polwithcheck, p.polrelid) AS check_expr,
31 array_agg(r.rolname) FILTER (WHERE r.rolname IS NOT NULL) AS roles
32 FROM pg_catalog.pg_policy p
33 JOIN pg_catalog.pg_class c ON c.oid = p.polrelid
34 JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
35 LEFT JOIN pg_catalog.pg_roles r ON r.oid = ANY(p.polroles)
36 WHERE 1=1
37 };
38 0 $sql .= DBIO::PostgreSQL::Introspect->system_schema_filter('n');
39 0 $sql .= DBIO::PostgreSQL::Introspect->extension_member_filter('pg_class', 'c.oid');
40  
41 0 my @bind;
42 0 ▶ if ($filter && @$filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter and @$filter) 0 0 0
Condition0%0/3
$filter and @$filter
!ll&&!rl&&r
000
MC/DC0%0/2
$filter and @$filter
$filter @$filter
Truth table0%0/3
A and B
A= $filterB= @$filter
ABresult
0X0
100
111
43 0 $sql .= ' AND n.nspname = ANY($1)';
44 0 push @bind, $filter;
45 }
46  
47 0 $sql .= q{
48 GROUP BY n.nspname, c.relname, p.polname, p.polcmd,
49 p.polpermissive, p.polqual, p.polwithcheck, p.polrelid
50 ORDER BY n.nspname, c.relname, p.polname
51 };
52  
53 0 my $sth = $dbh->prepare($sql);
54 0 $sth->execute(@bind);
55  
56 0 my $reads = DBIO::PostgreSQL::Introspect->column_reads(
57 $dbh, $filter, 'pg_policy', 'polrelid', 'polname',
58 );
59  
60 0 my %policies;
61 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
62 0 my $table_key = DBIO::PostgreSQL::Introspect->qualified_key($row);
63 $policies{$table_key}{ $row->{policy_name} } = {
64 schema_name => $row->{schema_name},
65 table_name => $row->{table_name},
66 policy_name => $row->{policy_name},
67 command => $row->{command},
68 permissive => $row->{permissive} ? 1 : 0,
69 using_expr => $row->{using_expr},
70 check_expr => $row->{check_expr},
71 roles => $row->{roles},
72 depends_on_columns => $reads->{$table_key}{ $row->{policy_name} } // {},
73 0 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$row->{'permissive'} ? : 0 0 0
Condition0%0/2
$reads->{$table_key}{$row->{"policy_name"}} // {}
l!l
00
MC/DC0%0/1
$reads->{$table_key}{$row->{"policy_name"}} // {}
$reads->{$table_key}{$row->{"policy_name"}}
Truth table0%0/2
A
A= $reads->{$table_key}{$row->{"policy_name"}}
Aresult
11
00
74 }
75  
76 0 return \%policies;
77 }
78  
79 171 1;
80  
81 __END__
« blib/lib/DBIO/PostgreSQL/Introspect/CheckConstraints.pm ↑ Summary blib/lib/DBIO/PostgreSQL/Introspect/Sequences.pm »