blib/lib/DBIO/Introspect/Base.pm

filter: Statementstmt 100% 78 / 78 Branchbran 94.4% 17 / 18 Conditioncond 84.2% 32 / 38 MC/DCmcdc 65.0% 13 / 20 Subroutinesub 100% 20 / 20 Podpod 100% 15 / 15 totaltotal 92.5% 175 / 189 CC 32 SCAR 15.1
CC
32
Cov
95%
table_uniq_info
9.0
table_columns_info
7.0
_aggregate_by_ordered
5.0
CRAP 4.5
« blib/lib/DBIO/Test/StorageLayer.pm ↑ Summary blib/lib/DBIO/Schema/Type.pm »
1 package DBIO::Introspect::Base;
2 # ABSTRACT: Base class for DBIO driver introspectors
3  
4 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 16 our $VERSION = '0.900007';
8  
9 16 our $CONTRACT_VERSION = '1.2';
10  
11  
12  
13 2 ▶sub contract_version { $CONTRACT_VERSION }
Subroutine contract_version: called CC=1 SCAR=0.0
Pod documented
14  
15  
16 39 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
17 39 my ($class, %args) = @_;
18 39 bless \%args, $class;
19 }
20  
21  
22 34 ▶sub dbh { $_[0]->{dbh} }
Subroutine dbh: called CC=1 SCAR=0.0
Pod documented
23  
24  
25 41 ▶sub model { $_[0]->{model} //= $_[0]->_build_model }
Subroutine model: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
$_[0]{"model"} //= $_[0]->_build_model
l!l&&r!l&&!r
31100
MC/DC0%0/2
$_[0]{"model"} //= $_[0]->_build_model
$_[0]{"model"} $_[0]->_build_model
Truth table66%2/3
A //= B
A= $_[0]{"model"}B= $_[0]->_build_model
ABresult
1X1
011
000
26  
27 1 ▶sub _build_model {
Subroutine _build_model: called CC=1 SCAR=0.0
28 1 my ($self) = @_;
29 1 die ref($self) . '::_build_model not implemented';
30 }
31  
32  
33 1 ▶sub _aggregate_by {
Subroutine _aggregate_by: called CC=4 SCAR=14.0
34 1 my ($class, $rows, $key_field) = @_;
35 1 my %result;
36 1 ▶ for my $row (@{ $rows // [] }) {
Condition50%1/2
$rows // []
l!l
10
MC/DC0%0/1
$rows // []
$rows
Truth table50%1/2
A
A= $rows
Aresult
11
00
37 3 ▶ my $key = $row->{$key_field} // next;
Condition50%1/2
$row->{$key_field} // (next)
l!l
30
MC/DC0%0/1
$row->{$key_field} // (next)
$row->{$key_field}
Truth table50%1/2
A
A= $row->{$key_field}
Aresult
11
00
38 3 push @{ $result{$key} }, $row;
39 }
40 1 return \%result;
41 }
42  
43  
44 2 ▶sub _aggregate_by_ordered {
Subroutine _aggregate_by_ordered: called CC=5 SCAR=16.1
45 2 my ($class, $rows, $key_field) = @_;
46 2 my @order;
47 my %index;
48 2 ▶ for my $row (@{ $rows // [] }) {
Condition100%2/2
$rows // []
l!l
11
MC/DC100%1/1
$rows // []
$rows
Truth table100%2/2
A
A= $rows
Aresult
11
00
49 5 ▶ my $key = $row->{$key_field} // next;
Condition100%2/2
$row->{$key_field} // (next)
l!l
41
MC/DC100%1/1
$row->{$key_field} // (next)
$row->{$key_field}
Truth table100%2/2
A
A= $row->{$key_field}
Aresult
11
00
50 4 ▶ unless (exists $index{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $index{$key}) 2 2 4
51 2 $index{$key} = scalar @order; # 0-based slot for this key
52 2 push @order, [ $key, [] ];
53 }
54 4 push @{ $order[ $index{$key} ][1] }, $row;
55 }
56 2 return \@order;
57 }
58  
59  
60 2 ▶sub table_keys {
Subroutine table_keys: called CC=2 SCAR=6.9
Pod documented
61 2 my ($self) = @_;
62 2 ▶ return [ sort keys %{ $self->model->{tables} || {} } ];
Condition100%2/2
$self->model->{'tables'} || {}
l!l
11
MC/DC100%1/1
$self->model->{'tables'} || {}
$self->model->{'tables'}
Truth table100%2/2
A
A= $self->model->{'tables'}
Aresult
11
00
63 }
64  
65  
66 9 ▶sub table_columns {
Subroutine table_columns: called CC=2 SCAR=6.9
Pod documented
67 9 my ($self, $key) = @_;
68 9 ▶ my $cols = $self->model->{columns}{$key} || [];
Condition100%2/2
$self->model->{'columns'}{$key} || []
l!l
81
MC/DC100%1/1
$self->model->{'columns'}{$key} || []
$self->model->{'columns'}{$key}
Truth table100%2/2
A
A= $self->model->{'columns'}{$key}
Aresult
11
00
69 9 return [ map { $_->{column_name} } @$cols ];
70 }
71  
72  
73 12 ▶sub table_columns_info {
Subroutine table_columns_info: called CC=7 SCAR=19.5
Pod documented
74 12 my ($self, $key) = @_;
75 12 ▶ my $cols = $self->model->{columns}{$key} || [];
Condition100%2/2
$self->model->{'columns'}{$key} || []
l!l
111
MC/DC100%1/1
$self->model->{'columns'}{$key} || []
$self->model->{'columns'}{$key}
Truth table100%2/2
A
A= $self->model->{'columns'}{$key}
Aresult
11
00
76 12 my %info;
77 # The primary key is folded into is_nullable, the way the
78 # driver introspectors that override this method already did. It states what
79 # DBIO's model holds -- the row's identity cannot be NULL -- and not what the
80 # engine would refuse; ClickHouse and SQLite both permit a key column to hold
81 # NULL under the conditions the POD above names. An engine that permits it
82 # overrides this method (ClickHouse does); there is no flag here. ADR 0038.
83 12 for my $col (@$cols) {
84 $info{ $col->{column_name} } = {
85 data_type => $col->{data_type},
86 is_nullable => (($col->{not_null} || $col->{is_pk}) ? 0 : 1),
87 default_value => $col->{default_value},
88 (defined $col->{size} ? (size => $col->{size}) : ()),
89 (exists $col->{is_auto_increment}
90 34 ▶ ? (is_auto_increment => $col->{is_auto_increment}) : ()),
Branch: 3 branches
BranchTrueFalseTotal
$col->{'not_null'} || $col->{'is_pk'} ? : 17 17 34
defined $col->{'size'} ? : 5 29 34
exists $col->{'is_auto_increment'} ? : 2 32 34
Condition100%3/3
$col->{"not_null"} or $col->{"is_pk"}
l!l&&r!l&&!r
10717
MC/DC100%2/2
$col->{"not_null"} or $col->{"is_pk"}
$col->{"not_null"} $col->{"is_pk"}
Truth table100%3/3
A or B
A= $col->{"not_null"}B= $col->{"is_pk"}
ABresult
1X1
011
000
91 };
92 }
93 12 return \%info;
94 }
95  
96  
97 6 ▶sub table_pk_info {
Subroutine table_pk_info: called CC=4 SCAR=14.0
Pod documented
98 6 my ($self, $key) = @_;
99 6 ▶ my $cols = $self->model->{columns}{$key} || [];
Condition100%2/2
$self->model->{'columns'}{$key} || []
l!l
51
MC/DC100%1/1
$self->model->{'columns'}{$key} || []
$self->model->{'columns'}{$key}
Truth table100%2/2
A
A= $self->model->{'columns'}{$key}
Aresult
11
00
100 return [
101 5 map { $_->{column_name} }
102 1 ▶ sort { ($a->{pk_position} || 0) <=> ($b->{pk_position} || 0) }
Condition50%2/4
$DBIO::Introspect::Base::a->{'pk_position'} || 0
l!l
10
$DBIO::Introspect::Base::b->{'pk_position'} || 0
l!l
10
MC/DC0%0/1
$DBIO::Introspect::Base::a->{'pk_position'} || 0
$DBIO::Introspect::Base::a->{'pk_position'}
MC/DC0%0/1
$DBIO::Introspect::Base::b->{'pk_position'} || 0
$DBIO::Introspect::Base::b->{'pk_position'}
Truth table50%1/2
A
A= $DBIO::Introspect::Base::a->{'pk_position'}
Aresult
11
00
Truth table50%1/2
A
A= $DBIO::Introspect::Base::b->{'pk_position'}
Aresult
11
00
103 6 grep { $_->{is_pk} } @$cols
104 ];
105 }
106  
107  
108 3 ▶sub table_uniq_info {
Subroutine table_uniq_info: called CC=9 SCAR=22.0
Pod documented
109 3 my ($self, $key) = @_;
110 3 my $model = $self->model;
111  
112 3 ▶ if (exists $model->{unique_constraints}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $model->{"unique_constraints"}) 1 2 3
113 1 ▶ return $model->{unique_constraints}{$key} || [];
Condition50%1/2
$model->{'unique_constraints'}{$key} || []
l!l
10
MC/DC0%0/1
$model->{'unique_constraints'}{$key} || []
$model->{'unique_constraints'}{$key}
Truth table50%1/2
A
A= $model->{'unique_constraints'}{$key}
Aresult
11
00
114 }
115  
116 2 ▶ my $indexes = $model->{indexes}{$key} || {};
Condition100%2/2
$model->{'indexes'}{$key} || {}
l!l
11
MC/DC100%1/1
$model->{'indexes'}{$key} || {}
$model->{'indexes'}{$key}
Truth table100%2/2
A
A= $model->{'indexes'}{$key}
Aresult
11
00
117 2 my @uniq;
118 2 for my $name (sort keys %$indexes) {
119 3 my $idx = $indexes->{$name};
120 3 ▶ next unless $idx->{is_unique};
Branch: 1 branch
BranchTrueFalseTotal
unless $idx->{"is_unique"} 1 2 3
121 2 ▶ next if ($idx->{origin} || '') eq 'pk';
Branch: 1 branch
BranchTrueFalseTotal
if ($idx->{"origin"} || "") eq "pk" 1 1 2
Condition100%2/2
$idx->{'origin'} || ''
l!l
11
MC/DC100%1/1
$idx->{'origin'} || ''
$idx->{'origin'}
Truth table100%2/2
A
A= $idx->{'origin'}
Aresult
11
00
122 1 ▶ next if uc($name) eq 'PRIMARY';
Branch: 1 branch
BranchTrueFalseTotal
if uc $name eq "PRIMARY" 0 1 1
123 1 push @uniq, [ $name => $idx->{columns} ];
124 }
125 2 return \@uniq;
126 }
127  
128  
129 2 ▶sub table_fk_info {
Subroutine table_fk_info: called CC=2 SCAR=6.9
Pod documented
130 2 my ($self, $key) = @_;
131 2 ▶ my $fks = $self->model->{foreign_keys}{$key} || [];
Condition100%2/2
$self->model->{'foreign_keys'}{$key} || []
l!l
11
MC/DC100%1/1
$self->model->{'foreign_keys'}{$key} || []
$self->model->{'foreign_keys'}{$key}
Truth table100%2/2
A
A= $self->model->{'foreign_keys'}{$key}
Aresult
11
00
132 return [
133 map {
134 2 +{
135 local_columns => $_->{from_columns},
136 remote_table => $_->{to_table},
137 remote_schema => undef,
138 remote_columns => $_->{to_columns},
139 attrs => {
140 on_delete => $_->{on_delete},
141 on_update => $_->{on_update},
142 },
143 }
144 1 } @$fks
145 ];
146 }
147  
148  
149 3 ▶sub table_is_view {
Subroutine table_is_view: called CC=4 SCAR=13.9
Pod documented
150 3 my ($self, $key) = @_;
151 3 ▶ my $tbl = $self->model->{tables}{$key} || {};
Condition100%2/2
$self->model->{'tables'}{$key} || {}
l!l
21
MC/DC100%1/1
$self->model->{'tables'}{$key} || {}
$self->model->{'tables'}{$key}
Truth table100%2/2
A
A= $self->model->{'tables'}{$key}
Aresult
11
00
152 3 ▶ return ($tbl->{kind} || '') eq 'view' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($tbl->{'kind'} || '') eq 'view' ? : 1 2 3
Condition100%2/2
$tbl->{'kind'} || ''
l!l
21
MC/DC100%1/1
$tbl->{'kind'} || ''
$tbl->{'kind'}
Truth table100%2/2
A
A= $tbl->{'kind'}
Aresult
11
00
153 }
154  
155  
156 7 ▶sub view_definition { return undef }
Subroutine view_definition: called CC=1 SCAR=0.0
Pod documented
157  
158  
159 1 ▶sub table_comment { return undef }
Subroutine table_comment: called CC=1 SCAR=0.0
Pod documented
160  
161  
162 1 ▶sub column_comment { return undef }
Subroutine column_comment: called CC=1 SCAR=0.0
Pod documented
163  
164  
165 1 ▶sub result_class_extra_statements { return () }
Subroutine result_class_extra_statements: called CC=1 SCAR=0.0
Pod documented
166  
167 16 1;
168  
169 __END__
« blib/lib/DBIO/Test/StorageLayer.pm ↑ Summary blib/lib/DBIO/Schema/Type.pm »