| 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
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
| |||||||||||||||||||||||||||||||||||||
| 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 // []
MC/DC0%0/1
$rows // []
$rows
Truth table50%1/2
A
A= $rows
| |||||||||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | my $key = $row->{$key_field} // next; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$row->{$key_field} // (next)
MC/DC0%0/1
$row->{$key_field} // (next)
$row->{$key_field}
Truth table50%1/2
A
A= $row->{$key_field}
| |||||||||||||||||||||||||||||||||||||
| 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 // []
MC/DC100%1/1
$rows // []
$rows
Truth table100%2/2
A
A= $rows
| |||||||||||||||||||||||||||||||||||||
| 49 | 5 | ▶ | my $key = $row->{$key_field} // next; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$row->{$key_field} // (next)
MC/DC100%1/1
$row->{$key_field} // (next)
$row->{$key_field}
Truth table100%2/2
A
A= $row->{$key_field}
| |||||||||||||||||||||||||||||||||||||
| 50 | 4 | ▶ | unless (exists $index{$key}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 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'} || {}
MC/DC100%1/1
$self->model->{'tables'} || {}
$self->model->{'tables'}
Truth table100%2/2
A
A= $self->model->{'tables'}
| |||||||||||||||||||||||||||||||||||||
| 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} || []
MC/DC100%1/1
$self->model->{'columns'}{$key} || []
$self->model->{'columns'}{$key}
Truth table100%2/2
A
A= $self->model->{'columns'}{$key}
| |||||||||||||||||||||||||||||||||||||
| 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} || []
MC/DC100%1/1
$self->model->{'columns'}{$key} || []
$self->model->{'columns'}{$key}
Truth table100%2/2
A
A= $self->model->{'columns'}{$key}
| |||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$col->{"not_null"} or $col->{"is_pk"}
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"}
| |||||||||||||||||||||||||||||||||||||
| 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} || []
MC/DC100%1/1
$self->model->{'columns'}{$key} || []
$self->model->{'columns'}{$key}
Truth table100%2/2
A
A= $self->model->{'columns'}{$key}
| |||||||||||||||||||||||||||||||||||||
| 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
$DBIO::Introspect::Base::b->{'pk_position'} || 0
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'}
Truth table50%1/2
A
A= $DBIO::Introspect::Base::b->{'pk_position'}
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 113 | 1 | ▶ | return $model->{unique_constraints}{$key} || []; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$model->{'unique_constraints'}{$key} || []
MC/DC0%0/1
$model->{'unique_constraints'}{$key} || []
$model->{'unique_constraints'}{$key}
Truth table50%1/2
A
A= $model->{'unique_constraints'}{$key}
| |||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||
| 116 | 2 | ▶ | my $indexes = $model->{indexes}{$key} || {}; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$model->{'indexes'}{$key} || {}
MC/DC100%1/1
$model->{'indexes'}{$key} || {}
$model->{'indexes'}{$key}
Truth table100%2/2
A
A= $model->{'indexes'}{$key}
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 121 | 2 | ▶ | next if ($idx->{origin} || '') eq 'pk'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$idx->{'origin'} || ''
MC/DC100%1/1
$idx->{'origin'} || ''
$idx->{'origin'}
Truth table100%2/2
A
A= $idx->{'origin'}
| |||||||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | next if uc($name) eq 'PRIMARY'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 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} || []
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}
| |||||||||||||||||||||||||||||||||||||
| 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} || {}
MC/DC100%1/1
$self->model->{'tables'}{$key} || {}
$self->model->{'tables'}{$key}
Truth table100%2/2
A
A= $self->model->{'tables'}{$key}
| |||||||||||||||||||||||||||||||||||||
| 152 | 3 | ▶ | return ($tbl->{kind} || '') eq 'view' ? 1 : 0; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$tbl->{'kind'} || ''
MC/DC100%1/1
$tbl->{'kind'} || ''
$tbl->{'kind'}
Truth table100%2/2
A
A= $tbl->{'kind'}
| |||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||