blib/lib/DBIO/PostgreSQL/Test/Conformance.pm

filter: Statementstmt 16.1% 43 / 267 Branchbran 0.0% 0 / 94 Conditioncond 0.0% 0 / 42 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 40.6% 13 / 32 Podpod 100% 13 / 13 totaltotal 14.7% 69 / 469 CC 77 SCAR 58.3
CC
77
Cov
11%
conformance_fact
1056.0
conformance_cleanup
156.0
conformance_namespace
42.0
CRAP 340.9
↑ Summary blib/lib/DBIO/PostgreSQL/Introspect/Indexes.pm »
1 package DBIO::PostgreSQL::Test::Conformance;
2 # ABSTRACT: Answers the shared conformance case table for the PostgreSQL driver
3  
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 our $VERSION = '0.900007';
8  
9 8 ▶use base 'DBIO::Test::Conformance';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 ▶use DBIO::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use DBIO::Schema ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use DBIO::PostgreSQL::Introspect ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use DBIO::PostgreSQL::Deploy ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use DBIO::PostgreSQL::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 8 my $SEQ = 0;
19 # schema class => the name of its case's schema
20 8 my %NAMESPACE;
21 # schema class => the other schemas its sources are qualified with
22 my %EXTRA;
23 # schema class => { schema name => 1 }: the schemas this run created (karr k138)
24 8 my %CREATED;
25  
26  
27 0 ▶sub conformance_live_available {
Subroutine conformance_live_available: not called CC=4 SCAR=30.0
Pod documented
28 0 ▶ return 0 unless length($ENV{DBIO_TEST_PG_DSN} // '');
Branch: 1 branch
BranchTrueFalseTotal
unless length($ENV{"DBIO_TEST_PG_DSN"} // "") 0 0 0
Condition0%0/2
$ENV{"DBIO_TEST_PG_DSN"} // ""
l!l
00
MC/DC0%0/1
$ENV{"DBIO_TEST_PG_DSN"} // ""
$ENV{"DBIO_TEST_PG_DSN"}
Truth table0%0/2
A
A= $ENV{"DBIO_TEST_PG_DSN"}
Aresult
11
00
29 0 ▶ return eval { require DBD::Pg; 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require DBD::Pg; 1 } } ? : 0 0 0
30 }
31  
32  
33 0 ▶sub conformance_connect {
Subroutine conformance_connect: not called CC=1 SCAR=6.9
Pod documented
34 0 my ($class, $schema_class) = @_;
35 0 my $name = sprintf 'dbio_cf_%d_%d', $$, ++$SEQ;
36 0 return $class->_connect_in($schema_class, $name);
37 }
38  
39 # Binds a schema class to the namespace $name and connects it. Used for the
40 # class of a case, and by conformance_upgrade for the class of its target.
41 0 ▶sub _connect_in {
Subroutine _connect_in: not called CC=1 SCAR=6.9
42 0 my ($class, $schema_class, $name) = @_;
43 0 $NAMESPACE{$schema_class} = $name;
44 0 $EXTRA{$schema_class} = [ $class->_extras_of($schema_class, $name) ];
45  
46 0 $class->_prepare_schema_class($schema_class);
47 0 $schema_class->pg_schemas($name, @{ $EXTRA{$schema_class} });
48 0 $schema_class->pg_search_path($name);
49  
50 0 my $dsn = $ENV{DBIO_TEST_PG_DSN} . ';options='
51 . DBIO::PostgreSQL::Util::quote_dsn_value("-csearch_path=$name");
52 return $schema_class->connect($dsn,
53 $ENV{DBIO_TEST_PG_USER}, $ENV{DBIO_TEST_PG_PASS}, {
54 0 AutoCommit => 1, RaiseError => 1, PrintError => 0, PrintWarn => 0,
55 });
56 }
57  
58 # A source named 'other.t' is the table t in the schema other: the
59 # declaration names that schema, as a user of the driver declares it, so the
60 # install -- the temporary database of a diff too -- creates it.
61 0 ▶sub _extras_of {
Subroutine _extras_of: not called CC=4 SCAR=30.0
62 0 my ($class, $schema_class, $name) = @_;
63 0 my %extra;
64 0 for my $moniker ($schema_class->sources) {
65 0 my $table = $schema_class->source($moniker)->name;
66 0 ▶ next if ref $table;
Branch: 1 branch
BranchTrueFalseTotal
if ref $table 0 0 0
67 0 my @parts = split /\./, $table;
68 0 pop @parts;
69 0 $extra{$_} = 1 for grep { length } @parts;
70 }
71 0 delete $extra{$name};
72 0 return sort keys %extra;
73 }
74  
75 # What a case's classes are given before they connect: the schema component,
76 # and for every result class the result component with FOREIGN KEY
77 # constraints from belongs_to (pg_fk_constraints_from_rels, on by default
78 # since karr k140, set so the case does not depend on it). The case
79 # declares a relationship and expects the server to hold the key.
80 29 ▶sub _prepare_schema_class {
Subroutine _prepare_schema_class: called CC=2 SCAR=6.9
81 29 my ($class, $schema_class) = @_;
82 29 $schema_class->load_components('PostgreSQL');
83 29 for my $moniker ($schema_class->sources) {
84 45 my $result_class = $schema_class->source($moniker)->result_class;
85 45 $result_class->load_components('PostgreSQL::Result');
86 45 $result_class->pg_fk_constraints_from_rels(1);
87 }
88 29 return $schema_class;
89 }
90  
91 0 ▶sub _namespace_of {
Subroutine _namespace_of: not called CC=2 SCAR=17.9
92 0 my ($class, $schema) = @_;
93 0 my $name = $NAMESPACE{ ref $schema };
94 0 ▶ DBIO::Exception->throw('conformance: this schema was not connected through '
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
95 . 'conformance_connect') unless defined $name;
96 0 return $name;
97 }
98  
99  
100 0 ▶sub conformance_namespace {
Subroutine conformance_namespace: not called CC=6 SCAR=37.4
Pod documented
101 0 my ($class, $schema, $case) = @_;
102 0 my $name = $class->_namespace_of($schema);
103 0 my $dbh = $schema->storage->dbh;
104  
105 # a schema of the declaration that is there already is not the case's to
106 # create nor to drop: refuse to run rather than damage it
107 0 ▶ my @extra = @{ $EXTRA{ ref $schema } || [] };
Condition0%0/2
$EXTRA{ref $schema} || []
l!l
00
MC/DC0%0/1
$EXTRA{ref $schema} || []
$EXTRA{ref $schema}
Truth table0%0/2
A
A= $EXTRA{ref $schema}
Aresult
11
00
108 0 for my $extra (@extra) {
109 0 my ($there) = $dbh->selectrow_array(
110 'SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = ?', undef, $extra);
111 0 ▶ DBIO::Exception->throw("conformance: the schema '$extra' the case declares "
Branch: 1 branch
BranchTrueFalseTotal
if $there 0 0 0
112 . 'is in the database already; it is not the run\'s to use or drop')
113 if $there;
114 }
115  
116 0 my ($main_there) = $dbh->selectrow_array(
117 'SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = ?', undef, $name);
118 0 ▶ unless ($main_there) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($main_there) 0 0 0
119 0 $dbh->do('CREATE SCHEMA ' . DBIO::PostgreSQL::Util::quote_ident($name));
120 0 $CREATED{ ref $schema }{$name} = 1;
121 }
122 # the check above found them absent; the install creates them
123 0 $CREATED{ ref $schema }{$_} = 1 for @extra;
124 0 return { name => $name, extra => \@extra };
125 }
126  
127  
128 0 ▶sub conformance_install {
Subroutine conformance_install: not called CC=1 SCAR=6.9
Pod documented
129 0 my ($class, $schema, $case) = @_;
130 0 $schema->deploy;
131 0 return;
132 }
133  
134  
135 0 ▶sub conformance_cleanup {
Subroutine conformance_cleanup: not called CC=12 SCAR=50.5
Pod documented
136 0 my ($class, $schema, $case, $namespace) = @_;
137 0 ▶ my $created = $CREATED{ ref $schema } || {};
Condition0%0/2
$CREATED{ref $schema} || {}
l!l
00
MC/DC0%0/1
$CREATED{ref $schema} || {}
$CREATED{ref $schema}
Truth table0%0/2
A
A= $CREATED{ref $schema}
Aresult
11
00
138 # the schemas the target of an upgrade qualifies with are marked in
139 # %CREATED by conformance_upgrade, and are in %EXTRA of its class
140 0 my %seen;
141 my @drop = defined $namespace
142 0 ▶ ? grep { $created->{$_} and !$seen{$_}++ } $namespace->{name},
Condition0%0/3
$created->{$_} && !$seen{$_}++
!ll&&!rl&&r
000
MC/DC0%0/2
$created->{$_} && !$seen{$_}++
$created->{$_} !$seen{$_}++
Truth table0%0/3
A && not(B)
A= $created->{$_}B= !$seen{$_}++
ABresult
0X0
100
111
143 0 ▶ @{ $namespace->{extra} || [] }, @{ $EXTRA{ ref $schema } || [] }
Branch: 1 branch
BranchTrueFalseTotal
defined $namespace ? : 0 0 0
Condition0%0/4
$namespace->{'extra'} || []
l!l
00
$EXTRA{ref $schema} || []
l!l
00
MC/DC0%0/1
$namespace->{'extra'} || []
$namespace->{'extra'}
MC/DC0%0/1
$EXTRA{ref $schema} || []
$EXTRA{ref $schema}
Truth table0%0/2
A
A= $namespace->{'extra'}
Aresult
11
00
Truth table0%0/2
A
A= $EXTRA{ref $schema}
Aresult
11
00
144 : ();
145  
146 0 ▶ if (@drop) {
Branch: 1 branch
BranchTrueFalseTotal
if (@drop) 0 0 0
147 my @sql = map {
148 0 'DROP SCHEMA IF EXISTS ' . DBIO::PostgreSQL::Util::quote_ident($_) . ' CASCADE'
149 } @drop;
150 0 my $storage = $schema->storage;
151 0 my $ok = eval {
152 0 my $dbh = $storage->dbh;
153 # a failed statement in a transaction leaves it unusable
154 0 ▶ $dbh->rollback unless $dbh->{AutoCommit};
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh->{"AutoCommit"} 0 0 0
155 0 local $dbh->{PrintWarn} = 0;
156 0 $dbh->do($_) for @sql;
157 0 1;
158 };
159 0 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
160 0 my $err = $@;
161 0 ▶ my $dbh = DBI->connect(@ENV{qw(DBIO_TEST_PG_DSN DBIO_TEST_PG_USER DBIO_TEST_PG_PASS)},
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = "DBI"->connect(@ENV{"DBIO_TEST_PG_DSN", "DBIO_TEST_PG_USER", "DBIO_TEST_PG_PASS"}, {"RaiseError", 1, "PrintError", 0, "PrintWarn", 0, "AutoCommit", 1}) or "DBIO::Exception"->throw(qq[cleanup of schema $namespace->{"name"} failed: $err]) 0 0 0
162 { RaiseError => 1, PrintError => 0, PrintWarn => 0, AutoCommit => 1 })
163 or DBIO::Exception->throw("cleanup of schema $namespace->{name} failed: $err");
164 0 $dbh->do($_) for @sql;
165 0 $dbh->disconnect;
166 }
167 }
168 0 delete $NAMESPACE{ ref $schema };
169 0 delete $EXTRA{ ref $schema };
170 0 delete $CREATED{ ref $schema };
171 0 $schema->storage->disconnect;
172 0 return;
173 }
174  
175  
176 0 ▶sub conformance_diff_is_empty {
Subroutine conformance_diff_is_empty: not called CC=2 SCAR=17.9
Pod documented
177 0 my ($class, $schema, $case) = @_;
178 0 my $diff = DBIO::PostgreSQL::Deploy->new(schema => $schema)->diff;
179 0 ▶ return $diff->has_changes ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$diff->has_changes ? : 0 0 0
180 }
181  
182  
183 0 ▶sub conformance_upgrade {
Subroutine conformance_upgrade: not called CC=2 SCAR=17.9
Pod documented
184 0 my ($class, $schema, $to_class, $case) = @_;
185 0 my $to = $class->_connect_target($schema, $to_class);
186 # The cases bring the database to the target declaration, drops and column
187 # type changes among them; the guard itself is held by the deploy cases.
188 0 my $ok = eval { DBIO::PostgreSQL::Deploy->new(schema => $to)->upgrade(allow_destructive => 1); 1 };
189 0 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
190 0 my $err = $@;
191 # the installed schema is cleaned up by the runner under its own class
192 0 delete $NAMESPACE{ref $to};
193 0 delete $EXTRA{ref $to};
194 0 delete $CREATED{ref $to};
195 0 eval { $to->storage->disconnect };
196 0 die $err;
197 }
198 0 return $to;
199 }
200  
201  
202 0 ▶sub conformance_deploy {
Subroutine conformance_deploy: not called CC=1 SCAR=6.9
Pod documented
203 0 my ($class, $schema, $to_class, $case) = @_;
204 0 my $to = $class->_connect_target($schema, $to_class);
205 0 return DBIO::PostgreSQL::Deploy->new(schema => $to);
206 }
207  
208 # The class of the target declaration, connected to the namespace of the
209 # installed schema; the namespace, the schemas the target qualifies with and
210 # the marks of what this run created pass over to it.
211 0 ▶sub _connect_target {
Subroutine _connect_target: not called CC=6 SCAR=37.4
212 0 my ($class, $schema, $to_class) = @_;
213 0 my $from_class = ref $schema;
214 0 my $name = $class->_namespace_of($schema);
215 0 my $dbh = $schema->storage->dbh;
216  
217 0 ▶ my @marked = keys %{ $CREATED{$from_class} || {} };
Condition0%0/2
$CREATED{$from_class} || {}
l!l
00
MC/DC0%0/1
$CREATED{$from_class} || {}
$CREATED{$from_class}
Truth table0%0/2
A
A= $CREATED{$from_class}
Aresult
11
00
218 0 ▶ my %known = map { $_ => 1 } $name, @{ $EXTRA{$from_class} || [] };
Condition0%0/2
$EXTRA{$from_class} || []
l!l
00
MC/DC0%0/1
$EXTRA{$from_class} || []
$EXTRA{$from_class}
Truth table0%0/2
A
A= $EXTRA{$from_class}
Aresult
11
00
219 0 my @extra = $class->_extras_of($to_class, $name);
220 0 my @new = grep { !$known{$_} } @extra;
221 0 for my $extra (@new) {
222 0 my ($there) = $dbh->selectrow_array(
223 'SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = ?', undef, $extra);
224 0 ▶ DBIO::Exception->throw("conformance: the schema '$extra' the target "
Branch: 1 branch
BranchTrueFalseTotal
if $there 0 0 0
225 . 'declares is in the database already; it is not the run\'s to use or drop')
226 if $there;
227 }
228  
229 0 my $to = $class->_connect_in($to_class, $name);
230 0 $CREATED{$to_class}{$_} = 1 for @marked, @new;
231 0 return $to;
232 }
233  
234  
235 1 ▶sub conformance_name_kinds { { schema => 1, extension => 1 } }
Subroutine conformance_name_kinds: called CC=1 SCAR=0.0
Pod documented
236  
237  
238 8 my $NAME_SEQ = 0;
239  
240 0 ▶sub conformance_apply_name {
Subroutine conformance_apply_name: not called CC=3 SCAR=24.8
Pod documented
241 0 my ($class, $kind, $name) = @_;
242 0 ▶ return $class->_apply_schema_name($name) if $kind eq 'schema';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "schema" 0 0 0
243 0 ▶ return $class->_apply_extension_name($name) if $kind eq 'extension';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "extension" 0 0 0
244 0 DBIO::Exception->throw("conformance: the PostgreSQL driver declares no name kind '$kind'");
245 }
246  
247 # A schema class with the PostgreSQL component, nothing declared beyond $o{extensions}.
248 0 ▶sub _name_schema_class {
Subroutine _name_schema_class: not called CC=2 SCAR=13.4
249 0 my ($class, @extensions) = @_;
250 0 my $schema_class = 'DBIO::PostgreSQL::Test::Conformance::Names' . ++$NAME_SEQ;
251 {
252 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
253 0 @{"${schema_class}::ISA"} = ('DBIO::Schema');
254 }
255 0 $schema_class->load_components('PostgreSQL');
256 0 ▶ $schema_class->pg_extensions(@extensions) if @extensions;
Branch: 1 branch
BranchTrueFalseTotal
if @extensions 0 0 0
257 0 return $schema_class;
258 }
259  
260 0 ▶sub _name_connect {
Subroutine _name_connect: not called CC=1 SCAR=6.9
261 0 my ($class, $schema_class, %attrs) = @_;
262 return $schema_class->connect(
263 0 @ENV{qw(DBIO_TEST_PG_DSN DBIO_TEST_PG_USER DBIO_TEST_PG_PASS)},
264 { AutoCommit => 1, RaiseError => 1, PrintError => 0, PrintWarn => 0, %attrs });
265 }
266  
267 0 ▶sub _apply_schema_name {
Subroutine _apply_schema_name: not called CC=5 SCAR=34.0
268 0 my ($class, $name) = @_;
269 0 my $schema = $class->_name_connect($class->_name_schema_class, schema => $name);
270 0 my $dbh = $schema->storage->dbh;
271 0 my $made = 0;
272 0 my $shown;
273 0 my $ok = eval {
274 0 ▶ die "conformance: the schema '$name' is in the database already; it is not the run's to use or drop\n"
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->selectrow_array("SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = ?", undef, $name) 0 0 0
275 if $dbh->selectrow_array('SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = ?', undef, $name);
276 0 $made = 1;
277 0 $schema->pg_deploy->install;
278 0 my $model = DBIO::PostgreSQL::Introspect->new(dbh => $dbh, schema_filter => [ $name ])->model;
279 0 ($shown) = keys %{ $model->{schemas} };
280 0 1;
281 };
282 0 my $error = $@;
283 0 eval {
284 0 ▶ $dbh->rollback unless $dbh->{AutoCommit};
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh->{"AutoCommit"} 0 0 0
285 0 ▶ $dbh->do('DROP SCHEMA IF EXISTS ' . DBIO::PostgreSQL::Util::quote_ident($name) . ' CASCADE') if $made;
Branch: 1 branch
BranchTrueFalseTotal
if $made 0 0 0
286 };
287 0 eval { $schema->storage->disconnect };
288 0 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
289 0 return $shown;
290 }
291  
292 0 ▶sub _apply_extension_name {
Subroutine _apply_extension_name: not called CC=5 SCAR=34.0
293 0 my ($class, $name) = @_;
294 0 my $schema = $class->_name_connect($class->_name_schema_class($name));
295 0 my $dbh = $schema->storage->dbh;
296 0 my $made = 0;
297 0 my $shown;
298 0 my $ok = eval {
299 0 ▶ die "conformance: the extension '$name' is in the database already; it is not the run's to use or drop\n"
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->selectrow_array("SELECT 1 FROM pg_catalog.pg_extension WHERE extname = ?", undef, $name) 0 0 0
300 if $dbh->selectrow_array('SELECT 1 FROM pg_catalog.pg_extension WHERE extname = ?', undef, $name);
301 0 $made = 1;
302 0 $schema->pg_deploy->install;
303 0 my $model = DBIO::PostgreSQL::Introspect->new(dbh => $dbh)->model;
304 0 ($shown) = grep { $_ eq $name } keys %{ $model->{extensions} };
305 0 1;
306 };
307 0 my $error = $@;
308 0 eval {
309 0 ▶ $dbh->rollback unless $dbh->{AutoCommit};
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh->{"AutoCommit"} 0 0 0
310 0 ▶ $dbh->do('DROP EXTENSION IF EXISTS ' . DBIO::PostgreSQL::Util::quote_ident($name)) if $made;
Branch: 1 branch
BranchTrueFalseTotal
if $made 0 0 0
311 };
312 0 eval { $schema->storage->disconnect };
313 0 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
314 0 return $shown;
315 }
316  
317  
318 8 ▶sub conformance_answered_through { { DDL => 2, Diff => 4, Bind => 1, Names => 1 } }
Subroutine conformance_answered_through: called CC=1 SCAR=0.0
Pod documented
319  
320  
321 5 ▶sub conformance_refusals {{
Subroutine conformance_refusals: called CC=1 SCAR=0.0
Pod documented
322 5 'diff-column-added-not-null-populated' => {
323 kind => 'server',
324 reason => qr/NOT NULL without a default, and table \S+ holds rows/,
325 },
326 'diff-not-null-over-nulls' => {
327 kind => 'server',
328 reason => qr/holds rows where it is NULL/,
329 },
330 'ddl-default-digit-string' => {
331 kind => 'deviation',
332 fact => qr/expected '007', read back '007 '/,
333 reason => 'char(n) is blank-padded to its length by PostgreSQL, so the '
334 . q{default '007' of a char(5) column reads back as '007 '; the driver does not trim},
335 },
336 }}
337  
338  
339 0 ▶sub conformance_fact {
Subroutine conformance_fact: not called CC=32 SCAR=69.6
Pod documented
340 0 my ($class, $schema, $name, $args) = @_;
341 0 my $ns = $class->_namespace_of($schema);
342 0 my $table = $args->{table};
343 0 my $dbh = $schema->storage->dbh;
344 0 my $intro = DBIO::PostgreSQL::Introspect->new(
345 dbh => $dbh, schema_filter => [ $ns ],
346 );
347  
348 0 ▶ if ($name eq 'table_in_namespace') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "table_in_namespace") 0 0 0
349 my $other = DBIO::PostgreSQL::Introspect->new(
350 0 dbh => $dbh, schema_filter => [ $args->{namespace} ],
351 );
352 0 ▶ return exists $other->model->{tables}{"$args->{namespace}.$args->{unqualified}"} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $other->model->{'tables'}{"$args->{'namespace'}.$args->{'unqualified'}"} ? : 0 0 0
353 }
354  
355 0 my $model = $intro->model;
356 0 my $key = "$ns.$table";
357 0 my $entry = $model->{tables}{$key};
358 0 ▶ my @cols = @{ $args->{columns} || [] };
Condition0%0/2
$args->{'columns'} || []
l!l
00
MC/DC0%0/1
$args->{'columns'} || []
$args->{'columns'}
Truth table0%0/2
A
A= $args->{'columns'}
Aresult
11
00
359 0 ▶ my $same = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
360 0 my ($got) = @_;
361 0 ▶ return 0 unless @$got == @cols;
Branch: 1 branch
BranchTrueFalseTotal
unless @$got == @cols 0 0 0
362 0 ▶ return (join("\0", map { $_ // '' } @$got) eq join("\0", @cols)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
join("\000", map({$_ // '';} @$got)) eq join("\000", @cols) ? : 0 0 0
Condition0%0/2
$_ // ""
l!l
00
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
363 0 };
364  
365 0 ▶ if ($name eq 'object_kind') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "object_kind") 0 0 0
366 0 ▶ return undef unless $entry;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry 0 0 0
367 0 ▶ return ($entry->{kind} // '') =~ /\A[vm]\z/ ? 'view' : 'table';
Branch: 1 branch
BranchTrueFalseTotal
($entry->{'kind'} // '') =~ /\A[vm]\z/ ? : 0 0 0
Condition0%0/2
$entry->{"kind"} // ""
l!l
00
MC/DC0%0/1
$entry->{"kind"} // ""
$entry->{"kind"}
Truth table0%0/2
A
A= $entry->{"kind"}
Aresult
11
00
368 }
369 0 ▶ if ($name eq 'table_name') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "table_name") 0 0 0
370 0 ▶ return $entry ? $entry->{table_name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$entry ? : 0 0 0
371 }
372  
373 0 ▶ my $columns = $model->{columns}{$key} || [];
Condition0%0/2
$model->{'columns'}{$key} || []
l!l
00
MC/DC0%0/1
$model->{'columns'}{$key} || []
$model->{'columns'}{$key}
Truth table0%0/2
A
A= $model->{'columns'}{$key}
Aresult
11
00
374 0 ▶ if ($name eq 'column_names') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "column_names") 0 0 0
375 0 return [ map { $_->{column_name} }
376 0 sort { $a->{ordinal} <=> $b->{ordinal} } @$columns ];
377 }
378 0 ▶ if ($name eq 'column_size') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "column_size") 0 0 0
379 0 my ($col) = grep { $_->{column_name} eq $args->{column} } @$columns;
380 0 ▶ return undef unless $col;
Branch: 1 branch
BranchTrueFalseTotal
unless $col 0 0 0
381 0 ▶ return $col->{data_type} =~ /\((\d+)\)/ ? $1 + 0 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$col->{'data_type'} =~ /\((\d+)\)/ ? : 0 0 0
382 }
383 0 ▶ if ($name eq 'column_auto_increment') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "column_auto_increment") 0 0 0
384 0 my ($col) = grep { $_->{column_name} eq $args->{column} } @$columns;
385 0 ▶ return 0 unless $col;
Branch: 1 branch
BranchTrueFalseTotal
unless $col 0 0 0
386 0 ▶ return ($col->{identity} || ($col->{default_value} // '') =~ /\Anextval\(/) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$col->{'identity'} || ($col->{'default_value'} // '') =~ /\Anextval\(/ ? : 0 0 0
Condition0%0/5
$col->{"identity"} or ($col->{"default_value"} // "") =~ /\Anextval\(/
l!l&&r!l&&!r
000
$col->{"default_value"} // ""
l!l
00
MC/DC0%0/2
$col->{"identity"} or ($col->{"default_value"} // "") =~ /\Anextval\(/
$col->{"identity"} $col->{"default_value"}
Truth table0%0/3
A or B
A= $col->{"identity"}B= $col->{"default_value"}
ABresult
1X1
011
000
387 }
388  
389 0 ▶ my $indexes = $model->{indexes}{$key} || {};
Condition0%0/2
$model->{'indexes'}{$key} || {}
l!l
00
MC/DC0%0/1
$model->{'indexes'}{$key} || {}
$model->{'indexes'}{$key}
Truth table0%0/2
A
A= $model->{'indexes'}{$key}
Aresult
11
00
390 0 ▶ if ($name eq 'primary_key_columns') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "primary_key_columns") 0 0 0
391 0 for my $i (values %$indexes) {
392 0 ▶ return [ @{ $i->{columns} } ] if $i->{is_primary};
Branch: 1 branch
BranchTrueFalseTotal
if $i->{"is_primary"} 0 0 0
393 }
394 0 return [];
395 }
396 0 ▶ if ($name eq 'unique_exists') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "unique_exists") 0 0 0
397 return (grep {
398 0 ▶ ($_->{constraint_type} // '') eq 'u' and $same->($_->{columns})
Branch: 1 branch
BranchTrueFalseTotal
grep({($_->{'constraint_type'} // '') eq 'u' and &$same($_->{'columns'});} values %$indexes) ? : 0 0 0
399 0 ▶ } values %$indexes) ? 1 : 0;
Condition0%0/5
($_->{'constraint_type'} // '') eq 'u' && &$same($_->{'columns'})
!ll&&!rl&&r
000
$_->{"constraint_type"} // ""
l!l
00
MC/DC0%0/2
($_->{'constraint_type'} // '') eq 'u' && &$same($_->{'columns'})
$_->{"constraint_type"} &$same($_->{'columns'})
Truth table0%0/3
A && B
A= $_->{"constraint_type"}B= &$same($_->{'columns'})
ABresult
0X0
100
111
400 }
401 0 ▶ if ($name eq 'foreign_key_count') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "foreign_key_count") 0 0 0
402 0 ▶ return scalar @{ $model->{foreign_keys}{$key} || [] };
Condition0%0/2
$model->{'foreign_keys'}{$key} || []
l!l
00
MC/DC0%0/1
$model->{'foreign_keys'}{$key} || []
$model->{'foreign_keys'}{$key}
Truth table0%0/2
A
A= $model->{'foreign_keys'}{$key}
Aresult
11
00
403 }
404 0 ▶ if ($name eq 'index_count') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "index_count") 0 0 0
405 return scalar grep {
406 0 !$_->{is_primary} and $same->($_->{columns})
407 0 ▶ } values %$indexes;
Condition0%0/3
!$_->{'is_primary'} && &$same($_->{'columns'})
!ll&&!rl&&r
000
MC/DC0%0/2
!$_->{'is_primary'} && &$same($_->{'columns'})
!$_->{'is_primary'} &$same($_->{'columns'})
Truth table0%0/3
not(A) && B
A= !$_->{'is_primary'}B= &$same($_->{'columns'})
ABresult
0X0
100
111
408 }
409  
410 0 DBIO::Exception->throw("unknown conformance fact '$name'");
411 }
412  
413 8 1;
414  
415 __END__
↑ Summary blib/lib/DBIO/PostgreSQL/Introspect/Indexes.pm »