| 1 | package DBIO::Admin; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Lightweight schema administration helper for DBIO | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 10 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 16 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=13 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 16 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 16 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 16 | for my $attr (qw/schema_class resultset config_stanza sql_dir | |||||||||||||||||||||||||||||||||||||||||
| 22 | config_file mode/) { | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 96 | ▶ | $self->{$attr} = $args{$attr} if exists $args{$attr}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 16 | for my $attr (qw/force quiet _confirm trace all dry_run/) { | |||||||||||||||||||||||||||||||||||||||||
| 27 | 96 | ▶ | $self->{$attr} = $args{$attr} ? 1 : 0 if exists $args{$attr}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 16 | for my $attr (qw/where set attrs/) { | |||||||||||||||||||||||||||||||||||||||||
| 31 | 48 | ▶ | $self->{$attr} = _coerce_hashref($args{$attr}) if exists $args{$attr}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 16 | ▶ | if (exists $args{connect_info}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | $self->{connect_info} = _coerce_connect_info($args{connect_info}); | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 16 | ▶ | if (exists $args{config}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $self->{config} = _coerce_hashref($args{config}); | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 16 | ▶ | if (exists $args{schema}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 11 | $self->{schema} = $args{schema}; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 16 | ▶ | if ($self->{schema_class}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 5 | _require_module($self->{schema_class}); | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 16 | ▶ | $self->{mode} ||= 'auto'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"mode"} ||= "auto"
MC/DC0%0/1
$self->{"mode"} ||= "auto"
$self->{"mode"}
Truth table50%1/2
A
A= $self->{"mode"}
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 16 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | ▶ | sub schema_class { $_[0]->{schema_class} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schema_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub config_stanza { $_[0]->{config_stanza} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config_stanza: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub sql_dir { $_[0]->{sql_dir} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sql_dir: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub config_file { $_[0]->{config_file} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | ▶ | sub resultset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resultset: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $_[0]->{resultset} = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 4 | return $_[0]->{resultset}; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 15 | ▶ | sub force { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
force: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 15 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $_[0]->{force} = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 15 | return $_[0]->{force}; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | ▶ | sub dry_run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dry_run: called CC=3 SCAR=16.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 6 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $_[0]->{dry_run} = $_[1] ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | return $_[0]->{dry_run}; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | ▶ | sub all { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all: called CC=3 SCAR=16.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | $_[0]->{all} = $_[1] ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | return $_[0]->{all}; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 10 | ▶ | sub _all_option { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_all_option: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 10 | ▶ | return $_[0]->{all} ? { all => 1 } : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 13 | ▶ | sub quiet { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quiet: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 13 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $_[0]->{quiet} = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 13 | return $_[0]->{quiet}; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 8 | ▶ | sub mode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mode: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 8 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | $_[0]->{mode} = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 7 | return $_[0]->{mode}; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 6 | ▶ | sub where { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
where: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 6 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $_[0]->{where} = _coerce_hashref($_[1]); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 6 | return $_[0]->{where}; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $_[0]->{set} = _coerce_hashref($_[1]); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | return $_[0]->{set}; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 7 | ▶ | sub attrs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attrs: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 7 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $_[0]->{attrs} = _coerce_hashref($_[1]); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 7 | return $_[0]->{attrs}; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub trace { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trace: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if (@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | $self->{trace} = $args[0] ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $self->schema->storage->debug($self->{trace}); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | return $self->{trace}; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 19 | ▶ | sub schema { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schema: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 19 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 19 | ▶ | $self->{schema} ||= $self->_build_schema; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"schema"} ||= $self->_build_schema
MC/DC50%1/2
$self->{"schema"} ||= $self->_build_schema
$self->{"schema"}
$self->_build_schema
Truth table66%2/3
A ||= B
A= $self->{"schema"}B= $self->_build_schema
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 15 | return $self->{schema}; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 4 | ▶ | sub _build_schema { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_schema: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 4 | my $connect_info = $self->connect_info; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 4 | $self->_assert_driver_modules_available($connect_info); | |||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 3 | my @connect = _normalized_connect_info($connect_info); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 3 | ▶ | $connect[3] ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$connect[3] ||= {}
MC/DC100%1/1
$connect[3] ||= {}
$connect[3]
Truth table100%2/2
A
A= $connect[3]
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | $connect[3]{ignore_version} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 3 | my $schema = $self->schema_class->connect(@connect); | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | $schema->storage->debug(1) if $self->{trace}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | return $schema; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 7 | ▶ | sub connect_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_info: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 7 | ▶ | $self->{connect_info} ||= $self->_build_connect_info; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"connect_info"} ||= $self->_build_connect_info
MC/DC0%0/2
$self->{"connect_info"} ||= $self->_build_connect_info
$self->{"connect_info"}
$self->_build_connect_info
Truth table33%1/3
A ||= B
A= $self->{"connect_info"}B= $self->_build_connect_info
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 7 | return $self->{connect_info}; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub _build_connect_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_connect_info: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | return $self->_find_stanza($self->config, $self->config_stanza); | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | sub config { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | $self->{config} ||= $self->_build_config; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"config"} ||= $self->_build_config
MC/DC0%0/2
$self->{"config"} ||= $self->_build_config
$self->{"config"}
$self->_build_config
Truth table0%0/3
A ||= B
A= $self->{"config"}B= $self->_build_config
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | return $self->{config}; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | sub _build_config { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_config: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | _require_module('Config::Any', 'Config::Any is required to parse --config files'); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $cfg = Config::Any->load_files({ | |||||||||||||||||||||||||||||||||||||||||
| 203 | files => [$self->config_file], | ||||||||||||||||||||||||||||||||||||||||||
| 204 | use_ext => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 205 | flatten_to_hash => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 206 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $cfg = $cfg->{$self->config_file}; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | return $cfg; | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 7 | ▶ | sub upgrade { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upgrade: called CC=12 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 7 | ▶ | my $mode = lc($self->mode || 'auto'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->mode || 'auto'
MC/DC0%0/1
$self->mode || 'auto'
$self->mode
Truth table50%1/2
A
A= $self->mode
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 7 | ▶ | Carp::croak("Unsupported mode '$mode' (expected auto|native)") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | unless $mode =~ /\A(?:auto|native)\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 6 | ▶ | my $deploy = $self->_native_deploy | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | or Carp::croak('No native upgrade path available for this schema/driver'); | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 6 | my $diff = $deploy->diff; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 6 | ▶ | return unless $diff->has_changes; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 6 | ▶ | if ($self->dry_run) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | print "Summary:\n", $diff->summary, "\n\nSQL:\n", $diff->as_sql, "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | return $diff; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 5 | ▶ | my $allow = $self->force ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | # A refusing diff goes straight to apply, which throws; asking first would | ||||||||||||||||||||||||||||||||||||||||||
| 232 | # offer a release that does not exist. | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | ▶ | my $refused = @{ $diff->classify->{refused} || [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$diff->classify->{'refused'} || []
MC/DC0%0/1
$diff->classify->{'refused'} || []
$diff->classify->{'refused'}
Truth table50%1/2
A
A= $diff->classify->{'refused'}
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | ▶ | if (!$allow && !$refused && (my @risky = $diff->destructive_operations)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $allow || $refused and my(@risky) = $diff->destructive_operations
$allow || $refused
MC/DC66%2/3
not $allow || $refused and my(@risky) = $diff->destructive_operations
$allow
$refused
my(@risky) = $diff->destructive_operations
Truth table75%3/4
not(A || B) and C
A= $allowB= $refusedC= my(@risky) = $diff->destructive_operations
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | print "This upgrade drops or may alter stored data:\n", | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 2 | (map { ' ' . $_->summary . "\n" } @risky); | |||||||||||||||||||||||||||||||||||||||||
| 237 | 2 | ▶ | return 0 unless $self->_confirm; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | $allow = 1; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | $deploy->apply($diff, allow_destructive => $allow); | |||||||||||||||||||||||||||||||||||||||||
| 242 | 3 | return $diff; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | # The Deploy object of the schema's driver, or undef without a native path. | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub _native_deploy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_native_deploy: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my $schema = $self->schema; | |||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | # PostgreSQL-native upgrade path from DBIO-PostgreSQL | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ($schema->can('pg_deploy')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | _require_module('DBIO::PostgreSQL::Deploy', | |||||||||||||||||||||||||||||||||||||||||
| 253 | 'Native PostgreSQL upgrade requires DBIO-PostgreSQL (install DBIO::PostgreSQL)'); | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | return $schema->pg_deploy; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 3 | ▶ | sub deploy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deploy: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 3 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 3 | return $self->schema->deploy($args, $self->sql_dir); | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 3 | ▶ | sub insert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: called CC=6 SCAR=19.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 3 | my ($self, $rs, $set) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 3 | ▶ | $rs ||= $self->resultset; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$rs ||= $self->resultset
MC/DC0%0/2
$rs ||= $self->resultset
$rs
$self->resultset
Truth table66%2/3
A ||= B
A= $rsB= $self->resultset
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 3 | ▶ | $set ||= $self->set; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$set ||= $self->set
MC/DC0%0/2
$set ||= $self->set
$set
$self->set
Truth table66%2/3
A ||= B
A= $setB= $self->set
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 3 | ▶ | Carp::croak('insert requires --resultset/--class and --set') unless $rs && $set; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rs and $set
MC/DC0%0/2
$rs and $set
$rs
$set
Truth table33%1/3
A and B
A= $rsB= $set
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 3 | my $resultset = $self->schema->resultset($rs); | |||||||||||||||||||||||||||||||||||||||||
| 275 | 3 | my $obj = $resultset->new_result($set)->insert; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 3 | ▶ | print ''.ref($resultset).' ID: '.join(',', $obj->id)."\n" if !$self->quiet; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 3 | return $obj; | |||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 4 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=12 SCAR=35.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 4 | my ($self, $rs, $set, $where) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 4 | ▶ | $rs ||= $self->resultset; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$rs ||= $self->resultset
MC/DC0%0/2
$rs ||= $self->resultset
$rs
$self->resultset
Truth table33%1/3
A ||= B
A= $rsB= $self->resultset
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 4 | ▶ | $set ||= $self->set; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$set ||= $self->set
MC/DC0%0/2
$set ||= $self->set
$set
$self->set
Truth table33%1/3
A ||= B
A= $setB= $self->set
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 4 | ▶ | $where ||= $self->where || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
$where ||= $self->where || {}
$self->where || {}
MC/DC0%0/2
$where ||= $self->where || {}
$where
$self->where
Truth table33%1/3
A ||= B
A= $whereB= $self->where
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 4 | ▶ | Carp::croak('update requires --resultset/--class and --set') unless $rs && $set; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rs and $set
MC/DC0%0/2
$rs and $set
$rs
$set
Truth table33%1/3
A and B
A= $rsB= $set
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 4 | my $resultset = $self->schema->resultset($rs)->search($where); | |||||||||||||||||||||||||||||||||||||||||
| 290 | 4 | ▶ | if (!$self->quiet) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my $count = eval { $resultset->count }; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if (defined $count && !$@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $count and not $@
MC/DC0%0/2
defined $count and not $@
defined $count
not $@
Truth table0%0/3
A and not(B)
A= defined $countB= not $@
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | print "This action will modify $count ".ref($resultset)." records.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | print "This action will modify matching ".ref($resultset)." records.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 4 | ▶ | return 0 unless $self->force || $self->_confirm; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->force or $self->_confirm
MC/DC0%0/2
$self->force or $self->_confirm
$self->force
$self->_confirm
Truth table33%1/3
A or B
A= $self->forceB= $self->_confirm
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 4 | return $resultset->update_all($set, $self->_all_option); | |||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 6 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=12 SCAR=32.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 6 | my ($self, $rs, $where, $attrs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 6 | ▶ | $rs ||= $self->resultset; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$rs ||= $self->resultset
MC/DC0%0/2
$rs ||= $self->resultset
$rs
$self->resultset
Truth table66%2/3
A ||= B
A= $rsB= $self->resultset
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 6 | ▶ | $where ||= $self->where || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$where ||= $self->where || {}
$self->where || {}
MC/DC0%0/2
$where ||= $self->where || {}
$where
$self->where
Truth table66%2/3
A ||= B
A= $whereB= $self->where
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 6 | ▶ | $attrs ||= $self->attrs || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
$attrs ||= $self->attrs || {}
$self->attrs || {}
MC/DC0%0/2
$attrs ||= $self->attrs || {}
$attrs
$self->attrs
Truth table33%1/3
A ||= B
A= $attrsB= $self->attrs
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 6 | ▶ | Carp::croak('delete requires --resultset/--class') unless $rs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 6 | my $resultset = $self->schema->resultset($rs)->search($where, $attrs); | |||||||||||||||||||||||||||||||||||||||||
| 314 | 6 | ▶ | if (!$self->quiet) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my $count = eval { $resultset->count }; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | if (defined $count && !$@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $count and not $@
MC/DC0%0/2
defined $count and not $@
defined $count
not $@
Truth table0%0/3
A and not(B)
A= defined $countB= not $@
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | print "This action will delete $count ".ref($resultset)." records.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | print "This action will delete matching ".ref($resultset)." records.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 6 | ▶ | return 0 unless $self->force || $self->_confirm; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->force or $self->_confirm
MC/DC0%0/2
$self->force or $self->_confirm
$self->force
$self->_confirm
Truth table33%1/3
A or B
A= $self->forceB= $self->_confirm
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 6 | return $resultset->delete_all($self->_all_option); | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 2 | ▶ | sub select { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select: called CC=8 SCAR=21.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 2 | my ($self, $rs, $where, $attrs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 2 | ▶ | $rs ||= $self->resultset; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$rs ||= $self->resultset
MC/DC0%0/2
$rs ||= $self->resultset
$rs
$self->resultset
Truth table33%1/3
A ||= B
A= $rsB= $self->resultset
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 2 | ▶ | $where ||= $self->where || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
$where ||= $self->where || {}
$self->where || {}
MC/DC0%0/2
$where ||= $self->where || {}
$where
$self->where
Truth table33%1/3
A ||= B
A= $whereB= $self->where
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 2 | ▶ | $attrs ||= $self->attrs || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
$attrs ||= $self->attrs || {}
$self->attrs || {}
MC/DC0%0/2
$attrs ||= $self->attrs || {}
$attrs
$self->attrs
Truth table33%1/3
A ||= B
A= $attrsB= $self->attrs
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | ▶ | Carp::croak('select requires --resultset/--class') unless $rs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 2 | my $resultset = $self->schema->resultset($rs)->search($where, $attrs); | |||||||||||||||||||||||||||||||||||||||||
| 338 | 2 | my @columns = $resultset->result_source->columns; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 2 | my @data = ( [ @columns ] ); | |||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 2 | ▶ | while (my $row = $resultset->next) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | push @data, [ map { $row->get_column($_) } @columns ]; | |||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 2 | return \@data; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 12 | ▶ | sub _confirm { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_confirm: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 12 | ▶ | return 1 if $self->{_confirm}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | print "Are you sure you want to do this? (type YES to confirm)\n"; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 1 | my $response = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | ▶ | return ($response||'') =~ /^YES/; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$response || ''
MC/DC0%0/1
$response || ''
$response
Truth table50%1/2
A
A= $response
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | sub _find_stanza { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_stanza: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my ($self, $cfg, $stanza) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | Carp::croak('config_stanza is required when using config/config_file') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $stanza and length $stanza
MC/DC0%0/2
defined $stanza and length $stanza
defined $stanza
length $stanza
Truth table0%0/3
A and B
A= defined $stanzaB= length $stanza
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | unless defined $stanza && length $stanza; | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my @path = split /::/, $stanza; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | while (my $path = shift @path) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | if (exists $cfg->{$path}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $cfg = $cfg->{$path}; | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | Carp::croak("Could not find $stanza in config ($path does not exist)"); | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | $cfg = $cfg->{connect_info} if ref($cfg) eq 'HASH' && exists $cfg->{connect_info}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $cfg eq "HASH" and exists $cfg->{"connect_info"}
MC/DC0%0/2
ref $cfg eq "HASH" and exists $cfg->{"connect_info"}
ref $cfg eq "HASH"
exists $cfg->{"connect_info"}
Truth table0%0/3
A and B
A= ref $cfg eq "HASH"B= exists $cfg->{"connect_info"}
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | return $cfg; | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 4 | ▶ | sub _assert_driver_modules_available { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_driver_modules_available: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 4 | my ($self, $connect_info) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 4 | ▶ | my $driver = _dbi_driver_name($connect_info) || return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
_dbi_driver_name($connect_info) || (return)
MC/DC100%1/1
_dbi_driver_name($connect_info) || (return)
_dbi_driver_name($connect_info)
Truth table100%2/2
A
A= _dbi_driver_name($connect_info)
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 3 | my %driver_to_modules = ( | |||||||||||||||||||||||||||||||||||||||||
| 379 | pg => [qw/DBIO::PostgreSQL DBIO::PostgreSQL::Storage/], | ||||||||||||||||||||||||||||||||||||||||||
| 380 | postgresql=> [qw/DBIO::PostgreSQL DBIO::PostgreSQL::Storage/], | ||||||||||||||||||||||||||||||||||||||||||
| 381 | sqlite => [qw/DBIO::SQLite DBIO::SQLite::Storage/], | ||||||||||||||||||||||||||||||||||||||||||
| 382 | mysql => [qw/DBIO::MySQL DBIO::MySQL::Storage/], | ||||||||||||||||||||||||||||||||||||||||||
| 383 | mariadb => [qw/DBIO::MySQL DBIO::MySQL::MariaDB DBIO::MySQL::Storage/], | ||||||||||||||||||||||||||||||||||||||||||
| 384 | oracle => [qw/DBIO::Oracle DBIO::Oracle::Storage/], | ||||||||||||||||||||||||||||||||||||||||||
| 385 | db2 => [qw/DBIO::DB2 DBIO::DB2::Storage/], | ||||||||||||||||||||||||||||||||||||||||||
| 386 | informix => [qw/DBIO::Informix DBIO::Informix::Storage/], | ||||||||||||||||||||||||||||||||||||||||||
| 387 | firebird => [qw/DBIO::Firebird DBIO::Firebird::Storage/], | ||||||||||||||||||||||||||||||||||||||||||
| 388 | sybase => [qw/DBIO::Sybase DBIO::Sybase::Storage/], | ||||||||||||||||||||||||||||||||||||||||||
| 389 | mssql => [qw/DBIO::MSSQL DBIO::MSSQL::Storage/], | ||||||||||||||||||||||||||||||||||||||||||
| 390 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 3 | ▶ | my $candidates = $driver_to_modules{ lc $driver } || return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$driver_to_modules{lc $driver} || (return)
MC/DC100%1/1
$driver_to_modules{lc $driver} || (return)
$driver_to_modules{lc $driver}
Truth table100%2/2
A
A= $driver_to_modules{lc $driver}
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 1 | for my $mod (@$candidates) { | |||||||||||||||||||||||||||||||||||||||||
| 395 | 2 | ▶ | return 1 if eval "require $mod; 1"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | Carp::croak( | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 1 | "No DBIO driver module available for DSN driver '$driver'. " | |||||||||||||||||||||||||||||||||||||||||
| 400 | . "Install one of: " . join(', ', @$candidates) | ||||||||||||||||||||||||||||||||||||||||||
| 401 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 4 | ▶ | sub _dbi_driver_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbi_driver_name: called CC=6 SCAR=20.5
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 4 | my ($connect_info) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 406 | 4 | my $dsn; | |||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 4 | ▶ | if (ref $connect_info eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 4 | $dsn = $connect_info->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | elsif (ref $connect_info eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | $dsn = $connect_info->{dsn}; | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 4 | ▶ | return unless defined $dsn && !ref($dsn); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $dsn and not ref $dsn
MC/DC50%1/2
defined $dsn and not ref $dsn
defined $dsn
not ref $dsn
Truth table66%2/3
A and not(B)
A= defined $dsnB= not ref $dsn
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 3 | ▶ | return $1 if $dsn =~ /\Adbi:([^:;]+)/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 3 | ▶ | sub _coerce_hashref { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_coerce_hashref: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 3 | my ($val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 3 | ▶ | return $val if ref $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 3 | ▶ | return _json_to_data($val) if defined $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | return $val; | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 5 | ▶ | sub _coerce_connect_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_coerce_connect_info: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 5 | my ($val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 5 | ▶ | return [$val] if ref $val eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | 4 | ▶ | return $val if ref $val eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 3 | ▶ | return _json_to_data($val) if defined $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | return $val; | |||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | 3 | ▶ | sub _normalized_connect_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalized_connect_info: called CC=5 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 3 | my ($connect_info) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 3 | ▶ | if (ref $connect_info eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my %h = %$connect_info; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my $dsn = delete $h{dsn}; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | my $user = delete($h{user}) // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $h{"user"} // ""
MC/DC0%0/1
delete $h{"user"} // ""
delete $h{"user"}
Truth table0%0/2
A
A= delete $h{"user"}
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | my $pass = delete($h{password}) // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $h{"password"} // ""
MC/DC0%0/1
delete $h{"password"} // ""
delete $h{"password"}
Truth table0%0/2
A
A= delete $h{"password"}
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | return ($dsn, $user, $pass, \%h); | |||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | 3 | ▶ | if (ref $connect_info eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 3 | return @$connect_info; | |||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | Carp::croak('connect_info must resolve to an arrayref or hashref'); | |||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 6 | ▶ | sub _json_to_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_json_to_data: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 6 | my ($json_str) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 455 | 6 | my $json = _build_json_decoder(); | |||||||||||||||||||||||||||||||||||||||||
| 456 | 6 | return $json->decode($json_str); | |||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | 6 | ▶ | sub _build_json_decoder { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_json_decoder: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | 6 | ▶ | return eval { | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
eval {
do {
'JSON::MaybeXS'->new('allow_barekey', 1, 'allow_singlequote', 1, 'relaxed', 1, 'canonical', 1, 'convert_blessed', 1)
}
} || 'JSON::MaybeXS'->new('relaxed', 1, 'canonical', 1, 'convert_blessed', 1)
MC/DC0%0/2
eval {
do {
'JSON::MaybeXS'->new('allow_barekey', 1, 'allow_singlequote', 1, 'relaxed', 1, 'canonical', 1, 'convert_blessed', 1)
}
} || 'JSON::MaybeXS'->new('relaxed', 1, 'canonical', 1, 'convert_blessed', 1)
eval {
do {
'JSON::MaybeXS'->new('allow_barekey', 1, 'allow_singlequote', 1, 'relaxed', 1, 'canonical', 1, 'convert_blessed', 1)
}
}
'JSON::MaybeXS'->new('relaxed', 1, 'canonical', 1, 'convert_blessed', 1)
Truth table33%1/3
A || B
A= eval {
do {
'JSON::MaybeXS'->new('allow_barekey', 1, 'allow_singlequote', 1, 'relaxed', 1, 'canonical', 1, 'convert_blessed', 1)
}
}B= 'JSON::MaybeXS'->new('relaxed', 1, 'canonical', 1, 'convert_blessed', 1)
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 6 | JSON::MaybeXS->new( | |||||||||||||||||||||||||||||||||||||||||
| 462 | allow_barekey => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 463 | allow_singlequote => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 464 | relaxed => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 465 | canonical => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 466 | convert_blessed => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 467 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 468 | } || JSON::MaybeXS->new( | ||||||||||||||||||||||||||||||||||||||||||
| 469 | relaxed => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 470 | canonical => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 471 | convert_blessed => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 472 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 5 | ▶ | sub _require_module { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_require_module: called CC=4 SCAR=19.4
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 5 | my ($module, $hint) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 477 | 5 | (my $file = "$module.pm") =~ s{::}{/}g; | |||||||||||||||||||||||||||||||||||||||||
| 478 | 5 | ▶ | return 1 if eval { require $file; 1 }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | my $err = $@ || "Unable to load $module"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || "Unable to load $module"
MC/DC0%0/1
$@ || "Unable to load $module"
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | Carp::croak($hint ? "$hint ($err)" : $err); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | __END__ | ||||||||||||||||||||||||||||||||||||||||||