blib/lib/DBIO/Test.pm

filter: Statementstmt 78.5% 143 / 182 Branchbran 69.2% 54 / 78 Conditioncond 40.3% 25 / 62 MC/DCmcdc 17.1% 6 / 35 Subroutinesub 80.9% 17 / 21 Podpod 100% 6 / 6 totaltotal 65.3% 251 / 384 CC 67 SCAR 28.9
CC
67
Cov
69%
init_schema
34.0
_uses_fake_storage
26.6
is_smoker
20.0
CRAP 18.0
« blib/lib/DBIO/Generate/Style/Moose.pm ↑ Summary blib/lib/DBIO/Generate.pm »
1 package DBIO::Test;
2 # ABSTRACT: Test utilities for DBIO and DBIO driver distributions
3  
4 253 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 253 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 253 our $VERSION = '0.900007';
8  
9 253 ▶use DBIO::Test::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 253 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 253 ▶use DBIO::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 253 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15  
16  
17 0 ▶sub is_smoker {
Subroutine is_smoker: not called CC=4 SCAR=30.0
Pod documented
18 return (
19 $ENV{AUTOMATED_TESTING}
20 && !$ENV{PERL5_CPANM_IS_RUNNING}
21 && !$ENV{RELEASE_TESTING}
22 0 ▶ ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'AUTOMATED_TESTING'} && !$ENV{'PERL5_CPANM_IS_RUNNING'} && !$ENV{'RELEASE_TESTING'} ? : 0 0 0
Condition0%0/6
$ENV{"AUTOMATED_TESTING"} and not $ENV{"PERL5_CPANM_IS_RUNNING"} and not $ENV{"RELEASE_TESTING"}
!ll&&!rl&&r
000
$ENV{"AUTOMATED_TESTING"} and not $ENV{"PERL5_CPANM_IS_RUNNING"}
!ll&&!rl&&r
000
MC/DC0%0/3
$ENV{"AUTOMATED_TESTING"} and not $ENV{"PERL5_CPANM_IS_RUNNING"} and not $ENV{"RELEASE_TESTING"}
$ENV{"AUTOMATED_TESTING"} not $ENV{"PERL5_CPANM_IS_RUNNING"} not $ENV{"RELEASE_TESTING"}
Truth table0%0/4
A and not(B) and not(C)
A= $ENV{"AUTOMATED_TESTING"}B= not $ENV{"PERL5_CPANM_IS_RUNNING"}C= not $ENV{"RELEASE_TESTING"}
ABCresult
0XX0
10X0
1100
1111
23 }
24  
25  
26 0 ▶sub is_plain {
Subroutine is_plain: not called CC=3 SCAR=24.8
Pod documented
27 0 ▶ return ( !__PACKAGE__->is_smoker && !$ENV{RELEASE_TESTING} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!(__PACKAGE__->is_smoker || $ENV{'RELEASE_TESTING'}) ? : 0 0 0
Condition0%0/3
__PACKAGE__->is_smoker || $ENV{'RELEASE_TESTING'}
l!l&&r!l&&!r
000
MC/DC0%0/2
__PACKAGE__->is_smoker || $ENV{'RELEASE_TESTING'}
__PACKAGE__->is_smoker $ENV{'RELEASE_TESTING'}
Truth table0%0/3
A || B
A= __PACKAGE__->is_smokerB= $ENV{'RELEASE_TESTING'}
ABresult
1X1
011
000
28 }
29  
30 252 ▶sub import {
Subroutine import: called CC=4 SCAR=13.9
31 252 my $self = shift;
32  
33 252 for my $exp (@_) {
34 41 ▶ if ($exp eq ':DiffSQL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($exp eq ':DiffSQL') { } 41 0 41
35 41 require DBIO::SQLMaker;
36 41 require SQL::Abstract::Test;
37 41 my $into = caller(0);
38 41 for (qw(is_same_sql_bind is_same_sql is_same_bind)) {
39 253 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 123 *{"${into}::$_"} = \&{"SQL::Abstract::Test::$_"};
41 }
42 }
43 else {
44 0 croak "Unknown export $exp requested from $self";
45 }
46 }
47 }
48  
49  
50 1007 ▶sub init_schema {
Subroutine init_schema: called CC=31 SCAR=35.3
Pod documented
51 1007 my $self = shift;
52 1007 my %args = @_;
53 # What the caller names, before replicated => 1 turns it into a
54 # replicated storage_type that names a driver only when this did.
55 1007 my $driver_given = defined $args{storage_type};
56 1007 %args = %{ __PACKAGE__->normalize_init_schema_args(\%args) };
57  
58 1007 my $schema;
59  
60 1007 ▶ if ($args{no_connect}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"no_connect"}) 60 947 1007
61 60 $schema = DBIO::Test::Schema->compose_namespace('DBIO::Test');
62 60 ▶ $schema->storage_type($args{storage_type}) if $args{storage_type};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"storage_type"} 59 1 60
63 60 return $schema;
64 }
65  
66 947 ▶ if ($args{dsn} || $args{connect_info}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'dsn'} or $args{'connect_info'}) { } 5 942 947
Condition100%3/3
$args{"dsn"} or $args{"connect_info"}
l!l&&r!l&&!r
41942
MC/DC100%2/2
$args{"dsn"} or $args{"connect_info"}
$args{"dsn"} $args{"connect_info"}
Truth table100%3/3
A or B
A= $args{"dsn"}B= $args{"connect_info"}
ABresult
1X1
011
000
67 # Real database connection. A schema always has a driver (ADR 0067), and
68 # DBIO::Test::Schema keeps none in its class: the caller names it.
69 5 ▶ DBIO::Exception->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $driver_given 3 2 5
70 'DBIO::Test->init_schema with a dsn or connect_info needs the driver: '
71 . "pass storage_type (for example storage_type => 'DBIO::PostgreSQL::Storage'). "
72 . 'DBIO::Test::Schema declares none, and a schema always has one (ADR 0067).'
73 ) unless $driver_given;
74  
75 my @connect = $args{connect_info}
76 0 ▶ ? @{$args{connect_info}}
Condition50%2/4
$args{"user"} or ""
l!l
02
$args{"pass"} or ""
l!l
02
MC/DC0%0/1
$args{"user"} or ""
$args{"user"}
MC/DC0%0/1
$args{"pass"} or ""
$args{"pass"}
Truth table50%1/2
A
A= $args{"user"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"pass"}
Aresult
11
00
77 : ($args{dsn}, $args{user}||'', $args{pass}||'', {
78 AutoCommit => 1,
79 2 ▶ %{ $args{connect_opts} || {} },
Branch: 1 branch
BranchTrueFalseTotal
$args{'connect_info'} ? : 0 2 2
Condition50%1/2
$args{'connect_opts'} || {}
l!l
02
MC/DC0%0/1
$args{'connect_opts'} || {}
$args{'connect_opts'}
Truth table50%1/2
A
A= $args{'connect_opts'}
Aresult
11
00
80 });
81  
82 2 $schema = DBIO::Test::Schema->clone;
83 $schema->storage_type(
84 __PACKAGE__->_real_storage_type($args{storage_type})
85 2 );
86 2 $schema = $schema->connect(@connect);
87  
88 2 ▶ if ($args{replicant_connect_info} && $schema->storage->isa('DBIO::Replicated::Storage')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"replicant_connect_info"} and $schema->storage->isa("DBIO::Replicated::Storage")) 0 2 2
Condition33%1/3
$args{"replicant_connect_info"} and $schema->storage->isa("DBIO::Replicated::Storage")
!ll&&!rl&&r
200
MC/DC0%0/2
$args{"replicant_connect_info"} and $schema->storage->isa("DBIO::Replicated::Storage")
$args{"replicant_connect_info"} $schema->storage->isa("DBIO::Replicated::Storage")
Truth table33%1/3
A and B
A= $args{"replicant_connect_info"}B= $schema->storage->isa("DBIO::Replicated::Storage")
ABresult
0X0
100
111
89 0 $schema->storage->connect_replicants(@{ $args{replicant_connect_info} });
90 }
91 }
92 else {
93 # Fake storage -- no database needed
94 942 require DBIO::Test::Storage;
95 my ($storage_class, $storage_args) = $args{storage_type}
96 ? __PACKAGE__->_normalize_storage_type($args{storage_type})
97 942 ▶ : (undef, {});
Branch: 1 branch
BranchTrueFalseTotal
$args{'storage_type'} ? : 53 889 942
98  
99 942 ▶ my $replicated = $storage_class
Condition100%3/3
$storage_class && $storage_class eq 'DBIO::Replicated::Storage'
!ll&&!rl&&r
8892924
MC/DC100%2/2
$storage_class && $storage_class eq 'DBIO::Replicated::Storage'
$storage_class $storage_class eq 'DBIO::Replicated::Storage'
Truth table100%3/3
A && B
A= $storage_classB= $storage_class eq 'DBIO::Replicated::Storage'
ABresult
0X0
100
111
100 && $storage_class eq 'DBIO::Replicated::Storage';
101  
102 942 my ($backend_storage_class, %replicated_args);
103 942 ▶ if ($replicated) {
Branch: 1 branch
BranchTrueFalseTotal
if ($replicated) 24 918 942
104 24 ▶ %replicated_args = %{ $storage_args || {} };
Condition50%1/2
$storage_args || {}
l!l
240
MC/DC0%0/1
$storage_args || {}
$storage_args
Truth table50%1/2
A
A= $storage_args
Aresult
11
00
105 24 $backend_storage_class = delete $replicated_args{backend_storage_class};
106 24 my $backend_storage_type = delete $replicated_args{backend_storage_type};
107  
108 24 ▶ $backend_storage_class ||= $backend_storage_type
Branch: 1 branch
BranchTrueFalseTotal
$backend_storage_type ? : 2 3 5
Condition66%2/3
$backend_storage_class ||= $backend_storage_type ? __PACKAGE__->_build_fake_storage_class($backend_storage_type) : "DBIO::Test::Storage"
l!l&&r!l&&!r
1950
MC/DC0%0/2
$backend_storage_class ||= $backend_storage_type ? __PACKAGE__->_build_fake_storage_class($backend_storage_type) : "DBIO::Test::Storage"
$backend_storage_class $backend_storage_type ? __PACKAGE__->_build_fake_storage_class($backend_storage_type) : "DBIO::Test::Storage"
Truth table66%2/3
A ||= B
A= $backend_storage_classB= $backend_storage_type ? __PACKAGE__->_build_fake_storage_class($backend_storage_type) : "DBIO::Test::Storage"
ABresult
1X1
011
000
109 ? __PACKAGE__->_build_fake_storage_class($backend_storage_type)
110 : 'DBIO::Test::Storage';
111 }
112  
113 # The fake storage is the driver of the mock suite, declared like any
114 # other before connecting (ADR 0067): DBIO::Test::Storage, or the hybrid
115 # of it over a requested driver storage, which is a DBIO::Test::Storage.
116 942 ▶ my $fake_class = $replicated ? $backend_storage_class
Branch: 2 branches
BranchTrueFalseTotal
$replicated ? : 24 918 942
$storage_class ? : 29 889 918
117 : $storage_class ? __PACKAGE__->_build_fake_storage_class($storage_class)
118 : 'DBIO::Test::Storage';
119  
120 942 $schema = DBIO::Test::Schema->clone;
121 942 $schema->storage_type("+$fake_class");
122 $schema = $schema->connect(
123 0 ▶ sub { }, # dummy connect coderef, Storage overrides everything
Subroutine __ANON__: not called CC=1 SCAR=0.0
124 942 );
125  
126 942 my $storage;
127  
128 942 ▶ if ($replicated) {
Branch: 1 branch
BranchTrueFalseTotal
if ($replicated) { } 24 918 942
129 24 require DBIO::Replicated::Storage;
130  
131 24 $storage = DBIO::Replicated::Storage->new($schema, {
132 %replicated_args,
133 backend_storage_class => $backend_storage_class,
134 });
135  
136 $storage->connect_info([
137 'dbi:DBIO:test:master',
138 '',
139 '',
140 24 ▶ { AutoCommit => 1, %{ $args{connect_opts} || {} } },
Condition50%1/2
$args{'connect_opts'} || {}
l!l
024
MC/DC0%0/1
$args{'connect_opts'} || {}
$args{'connect_opts'}
Truth table50%1/2
A
A= $args{'connect_opts'}
Aresult
11
00
141 ]);
142 }
143 else {
144 918 my $effective_class = $fake_class;
145  
146 918 $storage = $effective_class->new($schema);
147  
148 # Propagate the storage class's quoting to the sql_maker opts so the
149 # sql_maker picks it up. An explicit init_schema(quote_char => ...) arg
150 # overrides the inherited driver default -- including an empty-string
151 # quote_char, which means "no quoting" and must win (hence exists, not
152 # truthiness).
153 my $qc = exists $args{quote_char}
154 ? $args{quote_char}
155 918 ▶ : $effective_class->sql_quote_char;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'quote_char'} ? : 3 915 918
156 918 ▶ if (defined $qc) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $qc) 918 0 918
157 my $ns = exists $args{name_sep}
158 ? $args{name_sep}
159 918 ▶ : ($effective_class->sql_name_sep || '.');
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'name_sep'} ? : 1 917 918
Condition50%1/2
$effective_class->sql_name_sep or "."
l!l
9170
MC/DC0%0/1
$effective_class->sql_name_sep or "."
$effective_class->sql_name_sep
Truth table50%1/2
A
A= $effective_class->sql_name_sep
Aresult
11
00
160 918 $storage->{_sql_maker_opts}{quote_char} = $qc;
161 918 $storage->{_sql_maker_opts}{name_sep} = $ns;
162 # Also set on the storage instance so paths that read sql_quote_char
163 # directly (introspection, diff) see the override too.
164 918 $storage->sql_quote_char($qc);
165 918 ▶ $storage->sql_name_sep($ns) if defined $ns;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ns 918 0 918
166 }
167 }
168  
169 942 $schema->storage($storage);
170  
171 942 ▶ if ($args{replicant_connect_info} && $schema->storage->isa('DBIO::Replicated::Storage')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"replicant_connect_info"} and $schema->storage->isa("DBIO::Replicated::Storage")) 1 941 942
Condition66%2/3
$args{"replicant_connect_info"} and $schema->storage->isa("DBIO::Replicated::Storage")
!ll&&!rl&&r
94101
MC/DC50%1/2
$args{"replicant_connect_info"} and $schema->storage->isa("DBIO::Replicated::Storage")
$args{"replicant_connect_info"} $schema->storage->isa("DBIO::Replicated::Storage")
Truth table66%2/3
A and B
A= $args{"replicant_connect_info"}B= $schema->storage->isa("DBIO::Replicated::Storage")
ABresult
0X0
100
111
172 1 $schema->storage->connect_replicants(@{ $args{replicant_connect_info} });
173 }
174 }
175  
176 944 ▶ if (!$args{no_deploy}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"no_deploy"}) 685 259 944
177 685 __PACKAGE__->deploy_schema($schema, $args{deploy_args});
178 685 ▶ __PACKAGE__->populate_schema($schema) unless $args{no_populate};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"no_populate"} 685 0 685
179 }
180  
181 944 return $schema;
182 }
183  
184  
185 685 ▶sub deploy_schema {
Subroutine deploy_schema: called CC=3 SCAR=14.2
Pod documented
186 685 my ($self, $schema, $args) = @_;
187 685 ▶ $args ||= {};
Condition50%1/2
$args ||= {}
l!l
0685
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
188  
189 # Fake storage doesn't need deployment
190 685 ▶ return if __PACKAGE__->_uses_fake_storage($schema);
Branch: 1 branch
BranchTrueFalseTotal
if __PACKAGE__->_uses_fake_storage($schema) 685 0 685
191  
192 # Let the storage declare its own deploy requirements — no driver-name
193 # matching here. Caller-supplied args take precedence over defaults.
194 0 my %deploy_args = ($schema->storage->deploy_defaults, %$args);
195  
196 # Pre-deploy setup hook (e.g. MySQL strips incompatible sql_mode flags)
197 0 $schema->storage->deploy_setup($schema);
198  
199 0 $schema->deploy(\%deploy_args);
200 }
201  
202  
203 685 ▶sub populate_schema {
Subroutine populate_schema: called CC=2 SCAR=15.7
Pod documented
204 685 my ($self, $schema) = @_;
205  
206 # Fake storage can't hold data
207 685 ▶ return if __PACKAGE__->_uses_fake_storage($schema);
Branch: 1 branch
BranchTrueFalseTotal
if __PACKAGE__->_uses_fake_storage($schema) 685 0 685
208  
209 0 $schema->populate('Genre', [
210 [qw/genreid name/],
211 [qw/1 emo /],
212 ]);
213  
214 0 $schema->populate('Artist', [
215 [ qw/artistid name/ ],
216 [ 1, 'Caterwauler McCrae' ],
217 [ 2, 'Random Boy Band' ],
218 [ 3, 'We Are Goth' ],
219 ]);
220  
221 0 $schema->populate('CD', [
222 [ qw/cdid artist title year genreid/ ],
223 [ 1, 1, "Spoonful of bees", 1999, 1 ],
224 [ 2, 1, "Forkful of bees", 2001 ],
225 [ 3, 1, "Caterwaulin' Blues", 1997 ],
226 [ 4, 2, "Generic Manufactured Singles", 2001 ],
227 [ 5, 3, "Come Be Depressed With Us", 1998 ],
228 ]);
229  
230 0 $schema->populate('LinerNotes', [
231 [ qw/liner_id notes/ ],
232 [ 2, "Buy Whiskey!" ],
233 [ 4, "Buy Merch!" ],
234 [ 5, "Kill Yourself!" ],
235 ]);
236  
237 0 $schema->populate('Tag', [
238 [ qw/tagid cd tag/ ],
239 [ 1, 1, "Blue" ],
240 [ 2, 2, "Blue" ],
241 [ 3, 3, "Blue" ],
242 [ 4, 5, "Blue" ],
243 [ 5, 2, "Cheesy" ],
244 [ 6, 4, "Cheesy" ],
245 [ 7, 5, "Cheesy" ],
246 [ 8, 2, "Shiny" ],
247 [ 9, 4, "Shiny" ],
248 ]);
249  
250 0 $schema->populate('TwoKeys', [
251 [ qw/artist cd/ ],
252 [ 1, 1 ],
253 [ 1, 2 ],
254 [ 2, 2 ],
255 ]);
256  
257 0 $schema->populate('FourKeys', [
258 [ qw/foo bar hello goodbye sensors/ ],
259 [ 1, 2, 3, 4, 'online' ],
260 [ 5, 4, 3, 6, 'offline' ],
261 ]);
262  
263 0 $schema->populate('OneKey', [
264 [ qw/id artist cd/ ],
265 [ 1, 1, 1 ],
266 [ 2, 1, 2 ],
267 [ 3, 2, 2 ],
268 ]);
269  
270 0 $schema->populate('SelfRef', [
271 [ qw/id name/ ],
272 [ 1, 'First' ],
273 [ 2, 'Second' ],
274 ]);
275  
276 0 $schema->populate('SelfRefAlias', [
277 [ qw/self_ref alias/ ],
278 [ 1, 2 ]
279 ]);
280  
281 0 $schema->populate('ArtistUndirectedMap', [
282 [ qw/id1 id2/ ],
283 [ 1, 2 ]
284 ]);
285  
286 0 $schema->populate('Producer', [
287 [ qw/producerid name/ ],
288 [ 1, 'Matt S Trout' ],
289 [ 2, 'Bob The Builder' ],
290 [ 3, 'Fred The Phenotype' ],
291 ]);
292  
293 0 $schema->populate('CD_to_Producer', [
294 [ qw/cd producer/ ],
295 [ 1, 1 ],
296 [ 1, 2 ],
297 [ 1, 3 ],
298 ]);
299  
300 0 $schema->populate('TreeLike', [
301 [ qw/id parent name/ ],
302 [ 1, undef, 'root' ],
303 [ 2, 1, 'foo' ],
304 [ 3, 2, 'bar' ],
305 [ 6, 2, 'blop' ],
306 [ 4, 3, 'baz' ],
307 [ 5, 4, 'quux' ],
308 [ 7, 3, 'fong' ],
309 ]);
310  
311 0 $schema->populate('Track', [
312 [ qw/trackid cd position title/ ],
313 [ 4, 2, 1, "Stung with Success"],
314 [ 5, 2, 2, "Stripy"],
315 [ 6, 2, 3, "Sticky Honey"],
316 [ 7, 3, 1, "Yowlin"],
317 [ 8, 3, 2, "Howlin"],
318 [ 9, 3, 3, "Fowlin"],
319 [ 10, 4, 1, "Boring Name"],
320 [ 11, 4, 2, "Boring Song"],
321 [ 12, 4, 3, "No More Ideas"],
322 [ 13, 5, 1, "Sad"],
323 [ 14, 5, 2, "Under The Weather"],
324 [ 15, 5, 3, "Suicidal"],
325 [ 16, 1, 1, "The Bees Knees"],
326 [ 17, 1, 2, "Apiary"],
327 [ 18, 1, 3, "Beehind You"],
328 ]);
329  
330 0 $schema->populate('Event', [
331 [ qw/id starts_at created_on varchar_date varchar_datetime skip_inflation/ ],
332 [ 1, '2006-04-25 22:24:33', '2006-06-22 21:00:05', '2006-07-23', '2006-05-22 19:05:07', '2006-04-21 18:04:06'],
333 ]);
334  
335 0 $schema->populate('Link', [
336 [ qw/id url title/ ],
337 [ 1, '', 'aaa' ]
338 ]);
339  
340 0 $schema->populate('Bookmark', [
341 [ qw/id link/ ],
342 [ 1, 1 ]
343 ]);
344  
345 0 $schema->populate('Collection', [
346 [ qw/collectionid name/ ],
347 [ 1, "Tools" ],
348 [ 2, "Body Parts" ],
349 ]);
350  
351 0 $schema->populate('TypedObject', [
352 [ qw/objectid type value/ ],
353 [ 1, "pointy", "Awl" ],
354 [ 2, "round", "Bearing" ],
355 [ 3, "pointy", "Knife" ],
356 [ 4, "pointy", "Tooth" ],
357 [ 5, "round", "Head" ],
358 ]);
359  
360 0 $schema->populate('CollectionObject', [
361 [ qw/collection object/ ],
362 [ 1, 1 ],
363 [ 1, 2 ],
364 [ 1, 3 ],
365 [ 2, 4 ],
366 [ 2, 5 ],
367 ]);
368  
369 0 $schema->populate('Owners', [
370 [ qw/id name/ ],
371 [ 1, "Newton" ],
372 [ 2, "Waltham" ],
373 ]);
374  
375 0 $schema->populate('BooksInLibrary', [
376 [ qw/id owner title source price/ ],
377 [ 1, 1, "Programming Perl", "Library", 23 ],
378 [ 2, 1, "Dynamical Systems", "Library", 37 ],
379 [ 3, 2, "Best Recipe Cookbook", "Library", 65 ],
380 ]);
381 }
382  
383 57 ▶sub _normalize_storage_type {
Subroutine _normalize_storage_type: called CC=5 SCAR=18.7
384 57 my ($class, $storage_type) = @_;
385  
386 57 ▶ if (ref $storage_type eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $storage_type eq 'ARRAY') { } 0 57 57
elsif (ref $storage_type eq 'HASH') { } 25 32 57
387 0 my ($normalized_class, $args) = @$storage_type;
388 0 ▶ $normalized_class =~ s/^\+// if defined $normalized_class;
Branch: 1 branch
BranchTrueFalseTotal
if defined $normalized_class 0 0 0
389 0 return ($normalized_class, $args);
390 }
391 elsif (ref $storage_type eq 'HASH') {
392 25 my ($normalized_class, $args) = %$storage_type;
393 25 ▶ $normalized_class =~ s/^\+// if defined $normalized_class;
Branch: 1 branch
BranchTrueFalseTotal
if defined $normalized_class 25 0 25
394 25 return ($normalized_class, $args);
395 }
396  
397 32 $storage_type =~ s/^\+//;
398 32 return ($storage_type, {});
399 }
400  
401 # The storage_type for the real-database path. A replicated one runs its
402 # backends on the driver replicated => 1 was given (ADR 0067): the
403 # backend_storage_type normalize_init_schema_args records becomes the
404 # backend_storage_class DBIO::Replicated::Storage builds them from, unless
405 # that is given itself. Any other storage_type is used as given.
406 2 ▶sub _real_storage_type {
Subroutine _real_storage_type: called CC=6 SCAR=18.8
407 2 my ($class, $storage_type) = @_;
408  
409 2 my ($storage_class, $args) = $class->_normalize_storage_type($storage_type);
410 2 ▶ return $storage_type
Branch: 1 branch
BranchTrueFalseTotal
unless ref $storage_type and $storage_class eq "DBIO::Replicated::Storage" 1 1 2
Condition66%2/3
ref $storage_type and $storage_class eq "DBIO::Replicated::Storage"
!ll&&!rl&&r
101
MC/DC50%1/2
ref $storage_type and $storage_class eq "DBIO::Replicated::Storage"
ref $storage_type $storage_class eq "DBIO::Replicated::Storage"
Truth table66%2/3
A and B
A= ref $storage_typeB= $storage_class eq "DBIO::Replicated::Storage"
ABresult
0X0
100
111
411 unless ref $storage_type and $storage_class eq 'DBIO::Replicated::Storage';
412  
413 1 ▶ my %replicated_args = %{ $args || {} };
Condition50%1/2
$args || {}
l!l
10
MC/DC0%0/1
$args || {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
414 1 my $backend = delete $replicated_args{backend_storage_type};
415 1 ▶ $replicated_args{backend_storage_class} //= $backend if defined $backend;
Branch: 1 branch
BranchTrueFalseTotal
if defined $backend 1 0 1
Condition33%1/3
$replicated_args{"backend_storage_class"} //= $backend
l!l&&r!l&&!r
010
MC/DC0%0/2
$replicated_args{"backend_storage_class"} //= $backend
$replicated_args{"backend_storage_class"} $backend
Truth table33%1/3
A //= B
A= $replicated_args{"backend_storage_class"}B= $backend
ABresult
1X1
011
000
416  
417 1 return [ "+$storage_class", \%replicated_args ];
418 }
419  
420  
421 1007 ▶sub normalize_init_schema_args {
Subroutine normalize_init_schema_args: called CC=8 SCAR=22.2
Pod documented
422 1007 my ($class, $args) = @_;
423 1007 ▶ my %normalized = %{$args || {}};
Condition50%1/2
$args || {}
l!l
10070
MC/DC0%0/1
$args || {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
424  
425 1007 my $replicated = delete $normalized{replicated};
426 1007 ▶ return \%normalized unless $replicated;
Branch: 1 branch
BranchTrueFalseTotal
unless $replicated 1001 6 1007
427  
428 0 ▶ my %replicated_args = ref $replicated eq 'HASH' ? %{$replicated} : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $replicated eq 'HASH' ? : 0 6 6
429  
430 6 ▶ if (exists $normalized{storage_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $normalized{"storage_type"}) 2 4 6
431 my ($backend_storage_type, $backend_storage_args)
432 2 = $class->_normalize_storage_type($normalized{storage_type});
433  
434 2 ▶ if (keys %{ $backend_storage_args || {} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$backend_storage_args or {};}) 0 2 2
Condition50%1/2
$backend_storage_args || {}
l!l
20
MC/DC0%0/1
$backend_storage_args || {}
$backend_storage_args
Truth table50%1/2
A
A= $backend_storage_args
Aresult
11
00
435 0 croak 'replicated => 1 does not support storage_type constructor args; pass the full replicated storage_type hashref instead';
436 }
437  
438 2 ▶ $replicated_args{backend_storage_type} ||= $backend_storage_type;
Condition33%1/3
$replicated_args{"backend_storage_type"} ||= $backend_storage_type
l!l&&r!l&&!r
020
MC/DC0%0/2
$replicated_args{"backend_storage_type"} ||= $backend_storage_type
$replicated_args{"backend_storage_type"} $backend_storage_type
Truth table33%1/3
A ||= B
A= $replicated_args{"backend_storage_type"}B= $backend_storage_type
ABresult
1X1
011
000
439 }
440  
441 $normalized{storage_type} = {
442 6 'DBIO::Replicated::Storage' => \%replicated_args,
443 };
444  
445 6 return \%normalized;
446 }
447  
448 0 ▶sub _normalize_init_schema_args {
Subroutine _normalize_init_schema_args: not called CC=1 SCAR=6.9
449 0 shift->normalize_init_schema_args(@_);
450 }
451  
452 32 ▶sub _build_fake_storage_class {
Subroutine _build_fake_storage_class: called CC=4 SCAR=13.9
453 32 my ($class, $storage_class) = @_;
454 32 require DBIO::Test::Storage;
455  
456 32 $storage_class =~ s/^\+//;
457  
458 32 (my $st_file = "$storage_class.pm") =~ s|::|/|g;
459 32 require $st_file;
460  
461 32 my $hybrid = "DBIO::Test::Storage::_hybrid_::${storage_class}";
462 32 ▶ if (!$hybrid->isa('DBIO::Test::Storage')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hybrid->isa("DBIO::Test::Storage")) 21 11 32
463 253 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
464 21 @{"${hybrid}::ISA"} = ('DBIO::Test::Storage', $storage_class);
465 21 mro::set_mro($hybrid, 'c3');
466 21 for my $attr (qw(sql_quote_char sql_name_sep)) {
467 42 my $val = $storage_class->$attr;
468 42 ▶ $hybrid->$attr($val) if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 42 0 42
469 }
470 # DBIO::Test::Storage sits before the driver in the hybrid's C3 mro, so a
471 # driver SQLMaker (Oracle ROWNUM/CONNECT BY rewrite, 30-char identifier
472 # shortening, ...) is shadowed by the inherited default. Pin the driver's
473 # sql_maker_class explicitly on the hybrid so offline SQL-gen matches the
474 # real driver.
475 21 $hybrid->sql_maker_class($storage_class->sql_maker_class);
476 21 $hybrid->datetime_parser_type('DBIO::Test::DateTimeParser');
477 }
478  
479 32 return $hybrid;
480 }
481  
482 1370 ▶sub _uses_fake_storage {
Subroutine _uses_fake_storage: called CC=7 SCAR=32.8
483 1370 my ($class, $schema) = @_;
484 1370 ▶ my $storage = $schema->storage or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $storage = $schema->storage or return 0 1370 0 1370
485  
486 1370 ▶ return 1 if $storage->isa('DBIO::Test::Storage');
Branch: 1 branch
BranchTrueFalseTotal
if $storage->isa("DBIO::Test::Storage") 1370 0 1370
487  
488 return (
489 0 ▶ $storage->isa('DBIO::Replicated::Storage')
Branch: 1 branch
BranchTrueFalseTotal
$storage->isa('DBIO::Replicated::Storage') && $storage->master && $storage->master->storage && $storage->master->storage->isa('DBIO::Test::Storage') ? : 0 0 0
Condition0%0/9
$storage->isa("DBIO::Replicated::Storage") and $storage->master and $storage->master->storage and $storage->master->storage->isa("DBIO::Test::Storage")
!ll&&!rl&&r
000
$storage->isa("DBIO::Replicated::Storage") and $storage->master and $storage->master->storage
!ll&&!rl&&r
000
$storage->isa("DBIO::Replicated::Storage") and $storage->master
!ll&&!rl&&r
000
MC/DC0%0/4
$storage->isa("DBIO::Replicated::Storage") and $storage->master and $storage->master->storage and $storage->master->storage->isa("DBIO::Test::Storage")
$storage->isa("DBIO::Replicated::Storage") $storage->master $storage->master->storage $storage->master->storage->isa("DBIO::Test::Storage")
Truth table0%0/5
A and B and C and D
A= $storage->isa("DBIO::Replicated::Storage")B= $storage->masterC= $storage->master->storageD= $storage->master->storage->isa("DBIO::Test::Storage")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
490 && $storage->master
491 && $storage->master->storage
492 && $storage->master->storage->isa('DBIO::Test::Storage')
493 ) ? 1 : 0;
494 }
495  
496 253 1;
497  
498 __END__
« blib/lib/DBIO/Generate/Style/Moose.pm ↑ Summary blib/lib/DBIO/Generate.pm »