blib/lib/DBIO/Admin.pm

filter: Statementstmt 69.4% 173 / 249 Branchbran 53.2% 66 / 124 Conditioncond 46.3% 50 / 108 MC/DCmcdc 11.4% 7 / 61 Subroutinesub 80.4% 37 / 46 Podpod 100% 24 / 24 totaltotal 58.3% 357 / 612 CC 108 SCAR 25.4
CC
108
Cov
60%
_find_stanza
56.0
update
35.6
delete
26.3
CRAP 12.7
« blib/lib/DBIO/Extension/Protocol.pm ↑ Summary blib/lib/DBIO/Replicated.pm »
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
BranchTrueFalseTotal
if exists $args{$attr} 9 87 96
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
BranchTrueFalseTotal
if exists $args{$attr} 20 76 96
$args{$attr} ? : 20 0 20
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
BranchTrueFalseTotal
if exists $args{$attr} 3 45 48
32 }
33  
34 16 ▶ if (exists $args{connect_info}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"connect_info"}) 5 11 16
35 5 $self->{connect_info} = _coerce_connect_info($args{connect_info});
36 }
37  
38 16 ▶ if (exists $args{config}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"config"}) 0 16 16
39 0 $self->{config} = _coerce_hashref($args{config});
40 }
41  
42 16 ▶ if (exists $args{schema}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"schema"}) 11 5 16
43 11 $self->{schema} = $args{schema};
44 }
45  
46 16 ▶ if ($self->{schema_class}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"schema_class"}) 5 11 16
47 5 _require_module($self->{schema_class});
48 }
49  
50 16 ▶ $self->{mode} ||= 'auto';
Condition50%1/2
$self->{"mode"} ||= "auto"
l!l
016
MC/DC0%0/1
$self->{"mode"} ||= "auto"
$self->{"mode"}
Truth table50%1/2
A
A= $self->{"mode"}
Aresult
11
00
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
BranchTrueFalseTotal
if (@_ > 1) 0 4 4
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
BranchTrueFalseTotal
if (@_ > 1) 0 15 15
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
BranchTrueFalseTotal
if (@_ > 1) 0 6 6
82 0 ▶ $_[0]->{dry_run} = $_[1] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
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
BranchTrueFalseTotal
if (@_ > 1) 0 2 2
91 0 ▶ $_[0]->{all} = $_[1] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
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
BranchTrueFalseTotal
$_[0]{'all'} ? : 2 8 10
99 }
100  
101  
102 13 ▶sub quiet {
Subroutine quiet: called CC=2 SCAR=9.2
Pod documented
103 13 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 13 13
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
BranchTrueFalseTotal
if (@_ > 1) 1 7 8
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
BranchTrueFalseTotal
if (@_ > 1) 0 6 6
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
BranchTrueFalseTotal
if (@_ > 1) 0 1 1
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
BranchTrueFalseTotal
if (@_ > 1) 0 7 7
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
BranchTrueFalseTotal
if (@args) 0 0 0
150 0 ▶ $self->{trace} = $args[0] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args[0] ? : 0 0 0
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
l!l&&r!l&&!r
1504
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
ABresult
1X1
011
000
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] ||= {}
l!l
12
MC/DC100%1/1
$connect[3] ||= {}
$connect[3]
Truth table100%2/2
A
A= $connect[3]
Aresult
11
00
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
BranchTrueFalseTotal
if $self->{"trace"} 0 0 0
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
l!l&&r!l&&!r
700
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
ABresult
1X1
011
000
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
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
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'
l!l
70
MC/DC0%0/1
$self->mode || 'auto'
$self->mode
Truth table50%1/2
A
A= $self->mode
Aresult
11
00
216 7 ▶ Carp::croak("Unsupported mode '$mode' (expected auto|native)")
Branch: 1 branch
BranchTrueFalseTotal
unless $mode =~ /\A(?:auto|native)\z/ 1 6 7
217 unless $mode =~ /\A(?:auto|native)\z/;
218  
219 6 ▶ my $deploy = $self->_native_deploy
Branch: 1 branch
BranchTrueFalseTotal
my $deploy = $self->_native_deploy or Carp::croak("No native upgrade path available for this schema/driver") 6 0 6
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
BranchTrueFalseTotal
unless $diff->has_changes 0 6 6
224  
225 6 ▶ if ($self->dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dry_run) 1 5 6
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
BranchTrueFalseTotal
$self->force ? : 2 3 5
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'} || []
l!l
50
MC/DC0%0/1
$diff->classify->{'refused'} || []
$diff->classify->{'refused'}
Truth table50%1/2
A
A= $diff->classify->{'refused'}
Aresult
11
00
234 5 ▶ if (!$allow && !$refused && (my @risky = $diff->destructive_operations)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $allow || $refused and my(@risky) = $diff->destructive_operations) 2 3 5
Condition83%5/6
not $allow || $refused and my(@risky) = $diff->destructive_operations
!ll&&!rl&&r
212
$allow || $refused
l!l&&r!l&&!r
203
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
ABCresult
1XX0
01X0
0000
0011
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
BranchTrueFalseTotal
unless $self->_confirm 1 1 2
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
BranchTrueFalseTotal
if ($schema->can("pg_deploy")) 0 0 0
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
l!l&&r!l&&!r
210
MC/DC0%0/2
$rs ||= $self->resultset
$rs $self->resultset
Truth table66%2/3
A ||= B
A= $rsB= $self->resultset
ABresult
1X1
011
000
271 3 ▶ $set ||= $self->set;
Condition66%2/3
$set ||= $self->set
l!l&&r!l&&!r
210
MC/DC0%0/2
$set ||= $self->set
$set $self->set
Truth table66%2/3
A ||= B
A= $setB= $self->set
ABresult
1X1
011
000
272 3 ▶ Carp::croak('insert requires --resultset/--class and --set') unless $rs && $set;
Branch: 1 branch
BranchTrueFalseTotal
unless $rs and $set 0 3 3
Condition33%1/3
$rs and $set
!ll&&!rl&&r
003
MC/DC0%0/2
$rs and $set
$rs $set
Truth table33%1/3
A and B
A= $rsB= $set
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $self->quiet 0 3 3
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
l!l&&r!l&&!r
400
MC/DC0%0/2
$rs ||= $self->resultset
$rs $self->resultset
Truth table33%1/3
A ||= B
A= $rsB= $self->resultset
ABresult
1X1
011
000
285 4 ▶ $set ||= $self->set;
Condition33%1/3
$set ||= $self->set
l!l&&r!l&&!r
400
MC/DC0%0/2
$set ||= $self->set
$set $self->set
Truth table33%1/3
A ||= B
A= $setB= $self->set
ABresult
1X1
011
000
286 4 ▶ $where ||= $self->where || {};
Condition60%3/5
$where ||= $self->where || {}
l!l&&r!l&&!r
220
$self->where || {}
l!l
02
MC/DC0%0/2
$where ||= $self->where || {}
$where $self->where
Truth table33%1/3
A ||= B
A= $whereB= $self->where
ABresult
1X1
011
000
287 4 ▶ Carp::croak('update requires --resultset/--class and --set') unless $rs && $set;
Branch: 1 branch
BranchTrueFalseTotal
unless $rs and $set 0 4 4
Condition33%1/3
$rs and $set
!ll&&!rl&&r
004
MC/DC0%0/2
$rs and $set
$rs $set
Truth table33%1/3
A and B
A= $rsB= $set
ABresult
0X0
100
111
288  
289 4 my $resultset = $self->schema->resultset($rs)->search($where);
290 4 ▶ if (!$self->quiet) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->quiet) 0 4 4
291 0 my $count = eval { $resultset->count };
292 0 ▶ if (defined $count && !$@) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $count and not $@) { } 0 0 0
Condition0%0/3
defined $count and not $@
!ll&&!rl&&r
000
MC/DC0%0/2
defined $count and not $@
defined $count not $@
Truth table0%0/3
A and not(B)
A= defined $countB= not $@
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $self->force or $self->_confirm 0 4 4
Condition33%1/3
$self->force or $self->_confirm
l!l&&r!l&&!r
040
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
ABresult
1X1
011
000
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
l!l&&r!l&&!r
330
MC/DC0%0/2
$rs ||= $self->resultset
$rs $self->resultset
Truth table66%2/3
A ||= B
A= $rsB= $self->resultset
ABresult
1X1
011
000
309 6 ▶ $where ||= $self->where || {};
Condition80%4/5
$where ||= $self->where || {}
l!l&&r!l&&!r
330
$self->where || {}
l!l
12
MC/DC0%0/2
$where ||= $self->where || {}
$where $self->where
Truth table66%2/3
A ||= B
A= $whereB= $self->where
ABresult
1X1
011
000
310 6 ▶ $attrs ||= $self->attrs || {};
Condition60%3/5
$attrs ||= $self->attrs || {}
l!l&&r!l&&!r
060
$self->attrs || {}
l!l
15
MC/DC0%0/2
$attrs ||= $self->attrs || {}
$attrs $self->attrs
Truth table33%1/3
A ||= B
A= $attrsB= $self->attrs
ABresult
1X1
011
000
311 6 ▶ Carp::croak('delete requires --resultset/--class') unless $rs;
Branch: 1 branch
BranchTrueFalseTotal
unless $rs 0 6 6
312  
313 6 my $resultset = $self->schema->resultset($rs)->search($where, $attrs);
314 6 ▶ if (!$self->quiet) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->quiet) 0 6 6
315 0 my $count = eval { $resultset->count };
316 0 ▶ if (defined $count && !$@) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $count and not $@) { } 0 0 0
Condition0%0/3
defined $count and not $@
!ll&&!rl&&r
000
MC/DC0%0/2
defined $count and not $@
defined $count not $@
Truth table0%0/3
A and not(B)
A= defined $countB= not $@
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $self->force or $self->_confirm 0 6 6
Condition33%1/3
$self->force or $self->_confirm
l!l&&r!l&&!r
060
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
ABresult
1X1
011
000
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
l!l&&r!l&&!r
200
MC/DC0%0/2
$rs ||= $self->resultset
$rs $self->resultset
Truth table33%1/3
A ||= B
A= $rsB= $self->resultset
ABresult
1X1
011
000
333 2 ▶ $where ||= $self->where || {};
Condition60%3/5
$where ||= $self->where || {}
l!l&&r!l&&!r
110
$self->where || {}
l!l
01
MC/DC0%0/2
$where ||= $self->where || {}
$where $self->where
Truth table33%1/3
A ||= B
A= $whereB= $self->where
ABresult
1X1
011
000
334 2 ▶ $attrs ||= $self->attrs || {};
Condition60%3/5
$attrs ||= $self->attrs || {}
l!l&&r!l&&!r
110
$self->attrs || {}
l!l
01
MC/DC0%0/2
$attrs ||= $self->attrs || {}
$attrs $self->attrs
Truth table33%1/3
A ||= B
A= $attrsB= $self->attrs
ABresult
1X1
011
000
335 2 ▶ Carp::croak('select requires --resultset/--class') unless $rs;
Branch: 1 branch
BranchTrueFalseTotal
unless $rs 0 2 2
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
BranchTrueFalseTotal
if (my $row = $resultset->next) 2 2 4
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
BranchTrueFalseTotal
if $self->{"_confirm"} 11 1 12
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 || ''
l!l
10
MC/DC0%0/1
$response || ''
$response
Truth table50%1/2
A
A= $response
Aresult
11
00
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
BranchTrueFalseTotal
unless defined $stanza and length $stanza 0 0 0
Condition0%0/3
defined $stanza and length $stanza
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
359 unless defined $stanza && length $stanza;
360  
361 0 my @path = split /::/, $stanza;
362 0 ▶ while (my $path = shift @path) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = shift @path) 0 0 0
363 0 ▶ if (exists $cfg->{$path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cfg->{$path}) { } 0 0 0
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
BranchTrueFalseTotal
if ref $cfg eq "HASH" and exists $cfg->{"connect_info"} 0 0 0
Condition0%0/3
ref $cfg eq "HASH" and exists $cfg->{"connect_info"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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)
l!l
31
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)
Aresult
11
00
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)
l!l
12
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}
Aresult
11
00
393  
394 1 for my $mod (@$candidates) {
395 2 ▶ return 1 if eval "require $mod; 1";
Branch: 1 branch
BranchTrueFalseTotal
if eval "require $mod; 1" 0 2 2
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
BranchTrueFalseTotal
if (ref $connect_info eq 'ARRAY') { } 4 0 4
elsif (ref $connect_info eq 'HASH') { } 0 0 0
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
BranchTrueFalseTotal
unless defined $dsn and not ref $dsn 1 3 4
Condition66%2/3
defined $dsn and not ref $dsn
!ll&&!rl&&r
013
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
ABresult
0X0
100
111
416 3 ▶ return $1 if $dsn =~ /\Adbi:([^:;]+)/i;
Branch: 1 branch
BranchTrueFalseTotal
if $dsn =~ /\Adbi:([^:;]+)/i 3 0 3
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
BranchTrueFalseTotal
if ref $val 0 3 3
423 3 ▶ return _json_to_data($val) if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 3 0 3
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
BranchTrueFalseTotal
if ref $val eq "HASH" 1 4 5
430 4 ▶ return $val if ref $val eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $val eq "ARRAY" 1 3 4
431 3 ▶ return _json_to_data($val) if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 3 0 3
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
BranchTrueFalseTotal
if (ref $connect_info eq "HASH") 0 3 3
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"} // ""
l!l
00
MC/DC0%0/1
delete $h{"user"} // ""
delete $h{"user"}
Truth table0%0/2
A
A= delete $h{"user"}
Aresult
11
00
442 0 ▶ my $pass = delete($h{password}) // '';
Condition0%0/2
delete $h{"password"} // ""
l!l
00
MC/DC0%0/1
delete $h{"password"} // ""
delete $h{"password"}
Truth table0%0/2
A
A= delete $h{"password"}
Aresult
11
00
443 0 return ($dsn, $user, $pass, \%h);
444 }
445  
446 3 ▶ if (ref $connect_info eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $connect_info eq "ARRAY") 3 0 3
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)
l!l&&r!l&&!r
600
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)
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if eval { do { require $file; 1 } } 5 0 5
479  
480 0 ▶ my $err = $@ || "Unable to load $module";
Condition0%0/2
$@ || "Unable to load $module"
l!l
00
MC/DC0%0/1
$@ || "Unable to load $module"
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
481 0 ▶ Carp::croak($hint ? "$hint ($err)" : $err);
Branch: 1 branch
BranchTrueFalseTotal
$hint ? : 0 0 0
482 0 return 1;
483 }
484  
485 10 1;
486  
487 __END__
« blib/lib/DBIO/Extension/Protocol.pm ↑ Summary blib/lib/DBIO/Replicated.pm »