Object/Loader.pm

filter: Statementstmt 17.9% 87 / 486 Branchbran 0.3% 1 / 316 Conditioncond 0.0% 0 / 79 MC/DCmcdc 0.0% 0 / 44 Subroutinesub 46.3% 25 / 54 Podpod 66.6% 14 / 21 totaltotal 12.7% 127 / 1000 CC 194 SCAR 85.3
CC
194
Cov
10%
make_classes
10881.5
make_modules
650.0
manager_base_classes
90.0
CRAP 5056.7
« Object/QueryBuilder.pm ↑ Summary Object/MakeMethods/Date.pm »
1 package Rose::DB::Object::Loader;
2  
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 29 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 29 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 29 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 29 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 29 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 29 ▶use Rose::DB;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 29 ▶use Rose::DB::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 29 ▶use Rose::DB::Object::ConventionManager;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 29 ▶use Rose::DB::Object::Metadata::Util qw(perl_hashref);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 29 ▶use Rose::DB::Object::Metadata::Auto;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 29 ▶use Rose::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 29 our @ISA = qw(Rose::Object);
19  
20 29 our $VERSION = '0.799';
21  
22 29 our $Debug = 0;
23  
24 use Rose::Object::MakeMethods::Generic
25 29 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
26 29 scalar =>
27 [
28 'db_catalog',
29 'db_database',
30 'db_schema',
31 'db_username',
32 'db_password',
33 'db_options',
34 'include_tables',
35 'exclude_tables',
36 'filter_tables',
37 'pre_init_hook',
38 'post_init_hook',
39 'module_dir',
40 'module_preamble',
41 'module_postamble',
42 ],
43  
44 'scalar --get_set_init' =>
45 [
46 'with_relationships',
47 ],
48  
49 boolean =>
50 [
51 'using_default_base_class',
52 'require_primary_key' => { default => 1 },
53 'include_views' => { default => 0 },
54 'with_managers' => { default => 1 },
55 'with_foreign_keys' => { default => 1 },
56 'with_unique_keys' => { default => 1 },
57 'convention_manager_was_set' => { default => 0 },
58 'include_predicated_unique_indexes' => { default => 0 },
59 'warn_on_missing_primary_key',
60 'no_auto_sequences' => { default => 0 },
61 ],
62 29 );
63  
64 0 ▶sub warn_on_missing_pk { shift->warn_on_missing_primary_key(@_) }
Subroutine warn_on_missing_pk: not called CC=1 SCAR=6.9
Pod documented
65  
66 CHOOSE_CLONE:
67 {
68 29 local $@;
69  
70 # Get the best available clone method
71 eval
72 29 {
73 29 require Scalar::Util::Clone;
74 0 *clone = \&Scalar::Util::Clone::clone;
75 };
76  
77 29 ▶ if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 29 0 29
78 {
79 29 require Clone;
80 29 *clone = \&Clone::clone;
81 }
82 }
83  
84 0 ▶sub init_with_relationships { 1 }
Subroutine init_with_relationships: not called CC=1 SCAR=6.9
Pod undocumented
85  
86 29 my $Base_Class_Counter = 1;
87  
88 sub generate_object_base_class_name
89 0 ▶{
Subroutine generate_object_base_class_name: not called CC=2 SCAR=17.9
Pod undocumented
90 0 my($self) = shift;
91  
92 0 ▶ return ($self->class_prefix ?
Branch: 1 branch
BranchTrueFalseTotal
$self->class_prefix ? : 0 0 0
93 ($self->class_prefix . 'DB::Object::AutoBase') :
94 'Rose::DB::Object::LoaderGenerated::AutoBase') .
95 $Base_Class_Counter++;
96 }
97  
98 sub generate_db_base_class_name
99 0 ▶{
Subroutine generate_db_base_class_name: not called CC=2 SCAR=17.9
Pod undocumented
100 0 my($self) = shift;
101  
102 0 ▶ return ($self->class_prefix ?
Branch: 1 branch
BranchTrueFalseTotal
$self->class_prefix ? : 0 0 0
103 ($self->class_prefix . 'DB::AutoBase') :
104 'Rose::DB::LoaderGenerated::AutoBase') .
105 $Base_Class_Counter++;
106 }
107  
108 sub generate_manager_class_name
109 0 ▶{
Subroutine generate_manager_class_name: not called CC=2 SCAR=17.9
Pod documented
110 0 my($self, $object_class, $cm) = @_;
111 0 ▶ return $cm ? $cm->auto_manager_class_name($object_class) :
Branch: 1 branch
BranchTrueFalseTotal
$cm ? : 0 0 0
112 $self->convention_manager->auto_manager_class_name($object_class);
113 }
114  
115 sub base_classes
116 0 ▶{
Subroutine base_classes: not called CC=9 SCAR=42.6
Pod documented
117 0 my($self) = shift;
118  
119 0 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 0 0
120 {
121 0 ▶ if(my $bc = $self->{'base_classes'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $bc = $self->{"base_classes"}) 0 0 0
122 {
123 0 ▶ return wantarray ? @$bc : $bc;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
124 }
125  
126 # Make new base class
127 0 my $bc = $self->{'base_classes'} = [ $self->generate_object_base_class_name ];
128  
129 0 $self->using_default_base_class(1);
130  
131 29 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
132 0 @{"$bc->[0]::ISA"} = qw(Rose::DB::Object);
133  
134 0 ▶ return wantarray ? @$bc : $bc;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
135 }
136  
137 0 my $bc = shift;
138  
139 0 ▶ unless(ref $bc)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $bc) 0 0 0
140 {
141 0 $bc = [ $bc ];
142 }
143  
144 #my $found_rdbo = 0;
145  
146 0 foreach my $class (@$bc)
147 {
148 0 ▶ unless($class =~ /^(?:\w+::)*\w+$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ /^(?:\w+::)*\w+$/) 0 0 0
149 {
150 0 croak "Illegal base class name: $class";
151 }
152  
153 #$found_rdbo = 1 if(UNIVERSAL::isa($class, 'Rose::DB::Object'));
154 }
155  
156 #unless($found_rdbo)
157 #{
158 # croak "None of the base classes inherit from Rose::DB::Object";
159 #}
160  
161 0 $self->using_default_base_class(0);
162 0 $self->{'base_classes'} = $bc;
163  
164 0 ▶ return wantarray ? @$bc : $bc;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
165 }
166  
167 0 ▶sub base_class { shift->base_classes(@_) }
Subroutine base_class: not called CC=1 SCAR=6.9
Pod documented
168  
169 29 ▶use constant DEFAULT_MANAGER_BASE_CLASS => 'Rose::DB::Object::Manager';
Subroutine BEGIN: called CC=1 SCAR=0.0
170  
171 sub manager_base_classes
172 0 ▶{
Subroutine manager_base_classes: not called CC=9 SCAR=45.0
Pod documented
173 0 my($self) = shift;
174  
175 0 ▶ if(my $bc = shift)
Branch: 1 branch
BranchTrueFalseTotal
if (my $bc = shift()) 0 0 0
176 {
177 0 ▶ unless(ref $bc)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $bc) 0 0 0
178 {
179 0 $bc = [ $bc ];
180 }
181  
182 #my $found_base = 0;
183  
184 0 foreach my $class (@$bc)
185 {
186 0 ▶ unless($class =~ /^(?:\w+::)*\w+$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ /^(?:\w+::)*\w+$/) 0 0 0
187 {
188 0 croak "Illegal manager base class name: $class";
189 }
190  
191 #$found_base = 1 if(UNIVERSAL::isa($class, 'Rose::DB::Object::Manager'));
192 }
193  
194 #unless($found_base)
195 #{
196 # croak "None of the manager base classes inherit from ",
197 # "Rose::DB::Object::Manager";
198 #}
199  
200 0 $self->{'manager_base_classes'} = $bc;
201 }
202  
203 0 my $bc = $self->{'manager_base_classes'};
204  
205 0 ▶ unless(defined $bc && @$bc)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bc and @$bc) 0 0 0
Condition0%0/3
defined $bc and @$bc
!ll&&!rl&&r
000
MC/DC0%0/2
defined $bc and @$bc
defined $bc @$bc
Truth table0%0/3
A and B
A= defined $bcB= @$bc
ABresult
0X0
100
111
206 {
207 0 ▶ return wantarray ? DEFAULT_MANAGER_BASE_CLASS : [ DEFAULT_MANAGER_BASE_CLASS ];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
208 }
209  
210 0 return wantarray ? @{$self->{'manager_base_classes'}} :
211 0 ▶ $self->{'manager_base_classes'}
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
212 }
213  
214 0 ▶sub manager_base_class { shift->manager_base_classes(@_) }
Subroutine manager_base_class: not called CC=1 SCAR=6.9
Pod documented
215  
216 sub convention_manager
217 0 ▶{
Subroutine convention_manager: not called CC=6 SCAR=37.4
Pod documented
218 0 my($self) = shift;
219  
220 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
221 {
222 0 my $cm = shift;
223  
224 0 ▶ if(ref $cm)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cm) { } 0 0 0
225 {
226 0 ▶ unless(UNIVERSAL::isa($cm, 'Rose::DB::Object::ConventionManager'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($cm, "Rose::DB::Object::ConventionManager")) 0 0 0
227 {
228 0 croak "Not a Rose::DB::Object::ConventionManager-derived object: $cm";
229 }
230  
231 0 $self->{'convention_manager'} = $cm;
232 }
233 else
234 {
235 0 ▶ unless(UNIVERSAL::isa($cm, 'Rose::DB::Object::ConventionManager'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($cm, "Rose::DB::Object::ConventionManager")) 0 0 0
236 {
237 0 croak "Not a Rose::DB::Object::ConventionManager-derived class: $cm";
238 }
239  
240 0 $self->{'convention_manager'} = $cm->new;
241 }
242  
243 0 $self->convention_manager_was_set(1);
244 }
245  
246 0 ▶ return $self->{'convention_manager'} ||= Rose::DB::Object::ConventionManager->new;
Condition0%0/3
$self->{"convention_manager"} ||= "Rose::DB::Object::ConventionManager"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"convention_manager"} ||= "Rose::DB::Object::ConventionManager"->new
$self->{"convention_manager"} "Rose::DB::Object::ConventionManager"->new
Truth table0%0/3
A ||= B
A= $self->{"convention_manager"}B= "Rose::DB::Object::ConventionManager"->new
ABresult
1X1
011
000
247 }
248  
249 sub class_prefix
250 0 ▶{
Subroutine class_prefix: not called CC=5 SCAR=34.0
Pod documented
251 0 my($self) = shift;
252  
253 0 ▶ return $self->{'class_prefix'} unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
254  
255 0 my $class_prefix = shift;
256  
257 0 ▶ if(length $class_prefix)
Branch: 1 branch
BranchTrueFalseTotal
if (length $class_prefix) 0 0 0
258 {
259 0 ▶ unless($class_prefix =~ /^(?:\w+::)*\w+(?:::)?$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($class_prefix =~ /^(?:\w+::)*\w+(?:::)?$/) 0 0 0
260 {
261 0 croak "Illegal class prefix: $class_prefix";
262 }
263  
264 0 ▶ $class_prefix .= '::' unless($class_prefix =~ /::$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $class_prefix =~ /::$/ 0 0 0
265 }
266  
267 0 return $self->{'class_prefix'} = $class_prefix;
268 }
269  
270 sub force_lowercase
271 0 ▶{
Subroutine force_lowercase: not called CC=4 SCAR=30.0
Pod documented
272 0 my($self) = shift;
273  
274 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
275 {
276 0 my $value = shift;
277 # Important: allow this attribute to be set to undef, unlike
278 # most "normal" boolean attributes.
279 0 ▶ return $self->{'force_lowercase'} = undef unless(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
280 0 ▶ return $self->{'force_lowercase'} = $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
281 }
282  
283 0 return $self->{'force_lowercase'};
284 }
285  
286 sub db
287 0 ▶{
Subroutine db: not called CC=4 SCAR=30.0
Pod documented
288 0 my($self) = shift;
289  
290 0 ▶ return $self->{'db'} unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
291  
292 0 my $db = shift;
293  
294 0 ▶ unless(UNIVERSAL::isa($db, 'Rose::DB'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($db, "Rose::DB")) 0 0 0
295 {
296 0 croak "Not a Rose::DB-derived object: $db";
297 }
298  
299 0 ▶ if(defined $db)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $db) 0 0 0
300 {
301 0 $self->{'db_class'} = $db->class;
302 0 $self->{'db_dsn'} = undef;
303 }
304  
305 0 return $self->{'db'} = $db;
306 }
307  
308 sub db_dsn
309 0 ▶{
Subroutine db_dsn: not called CC=3 SCAR=24.8
Pod documented
310 0 my($self) = shift;
311  
312 0 ▶ return $self->{'db_dsn'} unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
313  
314 0 my $db_dsn = shift;
315  
316 0 ▶ if(my $db = $self->db)
Branch: 1 branch
BranchTrueFalseTotal
if (my $db = $self->db) 0 0 0
317 {
318 0 $db->db_dsn($db_dsn);
319 }
320  
321 0 return $self->{'db_dsn'} = $db_dsn;
322 }
323  
324 0 ▶sub dsn { shift->db_dsn(@_) }
Subroutine dsn: not called CC=1 SCAR=6.9
Pod undocumented
325 0 ▶sub dbi_dsn { shift->db_dsn(@_) }
Subroutine dbi_dsn: not called CC=1 SCAR=6.9
Pod undocumented
326  
327 sub db_class
328 0 ▶{
Subroutine db_class: not called CC=9 SCAR=42.8
Pod documented
329 0 my($self) = shift;
330  
331 0 ▶ return $self->{'db_class'} unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
332  
333 0 my $db_class = shift;
334  
335 0 ▶ unless($db_class =~ /^(?:\w+::)*\w+$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($db_class =~ /^(?:\w+::)*\w+$/) 0 0 0
336 {
337 0 croak "Illegal class name: $db_class";
338 }
339  
340 0 ▶ unless(UNIVERSAL::isa($db_class, 'Rose::DB'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($db_class, "Rose::DB")) 0 0 0
341 {
342 0 my $error;
343  
344 TRY:
345 {
346 0 local $@;
347 0 eval "require $db_class";
348 0 $error = $@;
349 }
350  
351 29 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
352 0 ▶ if(!$error && @{"${db_class}::ISA"} && !UNIVERSAL::isa($db_class, 'Rose::DB'))
Branch: 1 branch
BranchTrueFalseTotal
if (not $error and @{"${db_class}::ISA";} and not UNIVERSAL::isa($db_class, "Rose::DB")) 0 0 0
Condition0%0/6
not $error and @{"${db_class}::ISA";} and not UNIVERSAL::isa($db_class, "Rose::DB")
!ll&&!rl&&r
000
not $error and @{"${db_class}::ISA";}
!ll&&!rl&&r
000
MC/DC0%0/3
not $error and @{"${db_class}::ISA";} and not UNIVERSAL::isa($db_class, "Rose::DB")
not $error @{"${db_class}::ISA";} not UNIVERSAL::isa($db_class, "Rose::DB")
Truth table0%0/4
not(A) and B and not(C)
A= not $errorB= @{"${db_class}::ISA";}C= not UNIVERSAL::isa($db_class, "Rose::DB")
ABCresult
0XX0
10X0
1100
1111
353 {
354 0 croak "Not a Rose::DB-derived class: $db_class";
355 }
356 }
357  
358 0 ▶ if(my $db = $self->db)
Branch: 1 branch
BranchTrueFalseTotal
if (my $db = $self->db) 0 0 0
359 {
360 0 ▶ $self->db(undef) unless($db->class eq $db_class);
Branch: 1 branch
BranchTrueFalseTotal
unless $db->class eq $db_class 0 0 0
361 }
362  
363 0 return $self->{'db_class'} = $db_class;
364 }
365  
366 sub make_modules
367 0 ▶{
Subroutine make_modules: not called CC=25 SCAR=64.8
Pod documented
368 0 my($self, %args) = @_;
369  
370 my $module_dir = exists $args{'module_dir'} ?
371 0 ▶ delete $args{'module_dir'} : $self->module_dir;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'module_dir'} ? : 0 0 0
372  
373 0 ▶ $module_dir = cwd() unless(defined $module_dir);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $module_dir 0 0 0
374  
375 0 ▶ unless(-d $module_dir)
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $module_dir) 0 0 0
376 {
377 0 croak "Module directory '$module_dir' does not exist";
378 }
379  
380 0 my(@extra_classes, %extra_info);
381  
382 0 $args{'extra_classes'} = \@extra_classes;
383 0 $args{'extra_info'} = \%extra_info;
384  
385 0 my @classes = $self->make_classes(%args);
386  
387 0 foreach my $class (@classes, @extra_classes)
388 {
389 0 my @path = split('::', $class);
390 0 $path[-1] .= '.pm';
391 0 unshift(@path, $module_dir);
392  
393 0 my $dir = File::Spec->catfile(@path[0 .. ($#path - 1)]);
394  
395 0 ▶ mkpath($dir) unless(-e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
396  
397 0 ▶ unless(-d $dir)
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 0 0 0
398 {
399 0 ▶ if(-f $dir)
Branch: 1 branch
BranchTrueFalseTotal
if (-f $dir) 0 0 0
400 {
401 0 croak "Could not create module directory '$module_dir' - a file ",
402 "with the same name already exists";
403 }
404 0 croak "Could not create module directory '$module_dir' - $!";
405 }
406  
407 0 my $file = File::Spec->catfile(@path);
408  
409 0 ▶ open(my $pm, '>', $file) or croak "Could not create $file - $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $pm, ">", $file or croak("Could not create $file - $!") 0 0 0
410  
411 my $preamble = exists $args{'module_preamble'} ?
412 0 ▶ $args{'module_preamble'} : $self->module_preamble;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'module_preamble'} ? : 0 0 0
413  
414 my $postamble = exists $args{'module_postamble'} ?
415 0 ▶ $args{'module_postamble'} : $self->module_postamble;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'module_postamble'} ? : 0 0 0
416  
417 0 ▶ if($class->isa('Rose::DB::Object'))
Branch: 3 branches
BranchTrueFalseTotal
if ($class->isa('Rose::DB::Object')) { } 0 0 0
elsif ($class->isa('Rose::DB::Object::Manager')) { } 0 0 0
elsif ($class->isa('Rose::DB')) { } 0 0 0
418 {
419 0 ▶ if($preamble)
Branch: 1 branch
BranchTrueFalseTotal
if ($preamble) 0 0 0
420 {
421 0 ▶ my $this_preamble = ref $preamble eq 'CODE' ?
Branch: 1 branch
BranchTrueFalseTotal
ref $preamble eq 'CODE' ? : 0 0 0
422 $preamble->($class->meta) : $preamble;
423  
424 0 print {$pm} $this_preamble;
425 }
426  
427 0 ▶ if($extra_info{'base_classes'}{$class})
Branch: 1 branch
BranchTrueFalseTotal
if ($extra_info{'base_classes'}{$class}) { } 0 0 0
428 {
429 0 print {$pm} _perl_base_class($class, \%extra_info, \%args);
430 }
431 else
432 {
433 0 print {$pm} _perl_class($class, \%extra_info, \%args);
434 }
435  
436 0 ▶ if($postamble)
Branch: 1 branch
BranchTrueFalseTotal
if ($postamble) 0 0 0
437 {
438 0 ▶ my $this_postamble = ref $postamble eq 'CODE' ?
Branch: 1 branch
BranchTrueFalseTotal
ref $postamble eq 'CODE' ? : 0 0 0
439 $postamble->($class->meta) : $postamble;
440  
441 0 print {$pm} $this_postamble;
442 }
443 }
444 elsif($class->isa('Rose::DB::Object::Manager'))
445 {
446 0 ▶ if($preamble)
Branch: 1 branch
BranchTrueFalseTotal
if ($preamble) 0 0 0
447 {
448 0 ▶ my $this_preamble = ref $preamble eq 'CODE' ?
Branch: 1 branch
BranchTrueFalseTotal
ref $preamble eq 'CODE' ? : 0 0 0
449 $preamble->($class->object_class->meta, $class) : $preamble;
450  
451 0 print {$pm} $this_preamble;
452 }
453  
454 0 print {$pm} $class->perl_class_definition(%args), "\n";
455  
456 0 ▶ if($postamble)
Branch: 1 branch
BranchTrueFalseTotal
if ($postamble) 0 0 0
457 {
458 0 ▶ my $this_postamble = ref $postamble eq 'CODE' ?
Branch: 1 branch
BranchTrueFalseTotal
ref $postamble eq 'CODE' ? : 0 0 0
459 $postamble->($class->object_class->meta, $class) : $postamble;
460  
461 0 print {$pm} $this_postamble;
462 }
463 }
464 elsif($class->isa('Rose::DB'))
465 {
466 0 print {$pm} _perl_db_class($class, \%extra_info, \%args);
467 }
468 0 else { croak "Unknown class: $class" }
469  
470 0 ▶ close($pm) or croak "Could not write $file - $!";
Branch: 1 branch
BranchTrueFalseTotal
close $pm or croak("Could not write $file - $!") 0 0 0
471 }
472  
473 0 ▶ return wantarray ? @classes : \@classes;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
474 }
475  
476 sub _perl_class
477 0 ▶{
Subroutine _perl_class: not called CC=5 SCAR=34.0
478 0 my($class, $info, $args) = @_;
479  
480 0 my $auto_load = $args->{'auto_load_related_classes'};
481 0 my $old_auto_load = $class->meta->auto_load_related_classes;
482  
483 0 ▶ if(defined $auto_load)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $auto_load) 0 0 0
484 {
485 0 $class->meta->auto_load_related_classes($auto_load);
486 }
487  
488 0 my $code = $class->meta->perl_class_definition(%$args);
489  
490 0 ▶ if(defined $auto_load)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $auto_load) 0 0 0
491 {
492 0 $class->meta->auto_load_related_classes($old_auto_load);
493 }
494  
495 0 ▶ if(!$info->{'init_db_in_base_class'} && $info->{'perl_init_db'})
Branch: 1 branch
BranchTrueFalseTotal
if (not $info->{"init_db_in_base_class"} and $info->{"perl_init_db"}) 0 0 0
Condition0%0/3
not $info->{"init_db_in_base_class"} and $info->{"perl_init_db"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $info->{"init_db_in_base_class"} and $info->{"perl_init_db"}
not $info->{"init_db_in_base_class"} $info->{"perl_init_db"}
Truth table0%0/3
not(A) and B
A= not $info->{"init_db_in_base_class"}B= $info->{"perl_init_db"}
ABresult
0X0
100
111
496 {
497 0 my $init_db = $info->{'perl_init_db'};
498  
499 0 $code =~ s/1;/$init_db\n\n1;/;
500 }
501  
502 0 return $code . "\n";
503 }
504  
505 sub _perl_base_class
506 0 ▶{
Subroutine _perl_base_class: not called CC=3 SCAR=24.8
507 0 my($class, $info, $args) = @_;
508  
509 0 my $init_db = '';
510  
511 0 ▶ if($info->{'init_db_in_base_class'} && $info->{'perl_init_db'})
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"init_db_in_base_class"} and $info->{"perl_init_db"}) 0 0 0
Condition0%0/3
$info->{"init_db_in_base_class"} and $info->{"perl_init_db"}
!ll&&!rl&&r
000
MC/DC0%0/2
$info->{"init_db_in_base_class"} and $info->{"perl_init_db"}
$info->{"init_db_in_base_class"} $info->{"perl_init_db"}
Truth table0%0/3
A and B
A= $info->{"init_db_in_base_class"}B= $info->{"perl_init_db"}
ABresult
0X0
100
111
512 {
513 0 $init_db = "\n" . $info->{'perl_init_db'} . "\n";
514 }
515  
516 0 return<<"EOF";
517 package $class;
518  
519 use base 'Rose::DB::Object';
520 $init_db
521 1;
522 EOF
523 }
524  
525 sub _perl_db_class
526 0 ▶{
Subroutine _perl_db_class: not called CC=4 SCAR=30.0
527 0 my($class, $info, $args) = @_;
528  
529 0 my $max = 0;
530  
531 0 foreach my $key (keys %{$info->{'db_entry'}})
532 {
533 0 ▶ $max = length($key) if(length($key) > $max);
Branch: 1 branch
BranchTrueFalseTotal
if length $key > $max 0 0 0
534 }
535  
536 my $hash = perl_hashref(hash => $info->{'db_entry'},
537 inline => 0,
538 no_curlies => 1,
539 key_padding => $max,
540 0 ▶ indent => $args->{'indent'} || 2);
Condition0%0/2
$args->{'indent'} || 2
l!l
00
MC/DC0%0/1
$args->{'indent'} || 2
$args->{'indent'}
Truth table0%0/2
A
A= $args->{'indent'}
Aresult
11
00
541  
542 0 return<<"EOF";
543 package $class;
544  
545 use strict;
546  
547 use base 'Rose::DB';
548  
549 __PACKAGE__->use_private_registry;
550  
551 __PACKAGE__->register_db
552 (
553 $hash
554 );
555  
556 1;
557 EOF
558 }
559  
560 0 ▶sub default_pre_init_hook { }
Subroutine default_pre_init_hook: not called CC=1 SCAR=0.0
Pod undocumented
561 0 ▶sub default_post_init_hook { }
Subroutine default_post_init_hook: not called CC=1 SCAR=0.0
Pod undocumented
562  
563 sub make_classes
564 0 ▶{
Subroutine make_classes: not called CC=113 SCAR=92.9
Pod documented
565 0 my($self, %args) = @_;
566  
567 0 my $extra_classes = delete $args{'extra_classes'};
568 0 my $extra_info = delete $args{'extra_info'};
569  
570 0 my $db = delete $args{'db'};
571  
572 0 $args{'stay_connected'} = 1;
573 0 ▶ $args{'passive'} = 1 unless(exists $args{'passive'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"passive"} 0 0 0
574  
575 my $require_primary_key = exists $args{'require_primary_key'} ?
576 0 ▶ delete $args{'require_primary_key'} : $self->require_primary_key;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'require_primary_key'} ? : 0 0 0
577  
578 # Check for parameter alias conflicts
579 0 ▶ if(exists $args{'warn_on_missing_pk'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"warn_on_missing_pk"}) 0 0 0
580 {
581 0 ▶ if(exists $args{'warn_on_missing_primary_key'} &&
Branch: 3 branches
BranchTrueFalseTotal
if (exists $args{"warn_on_missing_primary_key"} and ($args{"warn_on_missing_pk"} ? 1 : 0) != ($args{"warn_on_missing_primary_key"} ? 1 : 0)) 0 0 0
$args{'warn_on_missing_pk'} ? : 0 0 0
$args{'warn_on_missing_primary_key'} ? : 0 0 0
Condition0%0/3
exists $args{"warn_on_missing_primary_key"} and ($args{"warn_on_missing_pk"} ? 1 : 0) != ($args{"warn_on_missing_primary_key"} ? 1 : 0)
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args{"warn_on_missing_primary_key"} and ($args{"warn_on_missing_pk"} ? 1 : 0) != ($args{"warn_on_missing_primary_key"} ? 1 : 0)
exists $args{"warn_on_missing_primary_key"} ($args{"warn_on_missing_pk"} ? 1 : 0) != ($args{"warn_on_missing_primary_key"} ? 1 : 0)
Truth table0%0/3
A and B
A= exists $args{"warn_on_missing_primary_key"}B= ($args{"warn_on_missing_pk"} ? 1 : 0) != ($args{"warn_on_missing_primary_key"} ? 1 : 0)
ABresult
0X0
100
111
582 (($args{'warn_on_missing_pk'} ? 1 : 0) != ($args{'warn_on_missing_primary_key'} ? 1 : 0)))
583 {
584 0 croak "The warn_on_missing_primary_key and warn_on_missing_pk parameters ",
585 "were both passed, and they conflict. Since these two parameters are ",
586 "aliases for each other, try passing just one.";
587 }
588  
589 0 $args{'warn_on_missing_primary_key'} = delete $args{'warn_on_missing_pk'};
590 }
591  
592 0 my $warn_on_missing_primary_key;
593  
594 # If not requiring PKs and no explicit decision, either in args or
595 # in the object, has been made about whether to warn on missing PKs,
596 # then don't warn (because not requiring PKs is a strong indication
597 # that their absence is not worth a warning)
598 0 ▶ if(!$require_primary_key &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $require_primary_key and !(exists $args{'warn_on_missing_primary_key'} || defined $self->warn_on_missing_primary_key) || exists $args{'warn_on_missing_primary_key'} && !defined($args{'warn_on_missing_primary_key'})) { } 0 0 0
Condition0%0/12
not $require_primary_key and !(exists $args{"warn_on_missing_primary_key"} || defined $self->warn_on_missing_primary_key) || exists $args{"warn_on_missing_primary_key"} && !defined($args{"warn_on_missing_primary_key"})
!ll&&!rl&&r
000
not exists $args{"warn_on_missing_primary_key"} || defined $self->warn_on_missing_primary_key or exists $args{"warn_on_missing_primary_key"} and not defined $args{"warn_on_missing_primary_key"}
l!l&&r!l&&!r
000
exists $args{'warn_on_missing_primary_key'} || defined $self->warn_on_missing_primary_key
l!l&&r!l&&!r
000
exists $args{"warn_on_missing_primary_key"} and not defined $args{"warn_on_missing_primary_key"}
!ll&&!rl&&r
000
MC/DC0%0/5
not $require_primary_key and !(exists $args{"warn_on_missing_primary_key"} || defined $self->warn_on_missing_primary_key) || exists $args{"warn_on_missing_primary_key"} && !defined($args{"warn_on_missing_primary_key"})
not $require_primary_key exists $args{'warn_on_missing_primary_key'} defined $self->warn_on_missing_primary_key exists $args{"warn_on_missing_primary_key"} not defined $args{"warn_on_missing_primary_key"}
Truth table0%0/8
not(A) and not(B || C) or D and not(E)
A= not $require_primary_keyB= exists $args{'warn_on_missing_primary_key'}C= defined $self->warn_on_missing_primary_keyD= exists $args{"warn_on_missing_primary_key"}E= not defined $args{"warn_on_missing_primary_key"}
ABCDEresult
0XXXX0
11X0X0
11X100
1010X0
101100
100XX1
11X111
101111
599 ((!exists $args{'warn_on_missing_primary_key'} && !defined $self->warn_on_missing_primary_key) ||
600 exists $args{'warn_on_missing_primary_key'} && !defined $args{'warn_on_missing_primary_key'}))
601 {
602 0 $warn_on_missing_primary_key = 0;
603 }
604 else
605 {
606 $warn_on_missing_primary_key = exists $args{'warn_on_missing_primary_key'} ?
607 0 ▶ delete $args{'warn_on_missing_primary_key'} : $self->warn_on_missing_primary_key;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'warn_on_missing_primary_key'} ? : 0 0 0
608 }
609  
610 my $include_views = exists $args{'include_views'} ?
611 0 ▶ delete $args{'include_views'} : $self->include_views;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'include_views'} ? : 0 0 0
612  
613 my $with_managers = exists $args{'with_managers'} ?
614 0 ▶ delete $args{'with_managers'} : $self->with_managers;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'with_managers'} ? : 0 0 0
615  
616 $args{'with_relationships'} = $self->with_relationships
617 0 ▶ unless(exists $args{'with_relationships'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"with_relationships"} 0 0 0
618  
619 $args{'with_foreign_keys'} = $self->with_foreign_keys
620 0 ▶ unless(exists $args{'with_foreign_keys'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"with_foreign_keys"} 0 0 0
621  
622 $args{'with_unique_keys'} = $self->with_unique_keys
623 0 ▶ unless(exists $args{'with_unique_keys'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"with_unique_keys"} 0 0 0
624  
625 my $no_auto_sequences = exists $args{'no_auto_sequences'} ?
626 0 ▶ delete $args{'no_auto_sequences'} : $self->no_auto_sequences;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'no_auto_sequences'} ? : 0 0 0
627  
628 my $pre_init_hook = exists $args{'pre_init_hook'} ?
629 0 ▶ delete $args{'pre_init_hook'} : $self->pre_init_hook;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'pre_init_hook'} ? : 0 0 0
630  
631 my $post_init_hook = exists $args{'post_init_hook'} ?
632 0 ▶ delete $args{'post_init_hook'} : $self->post_init_hook;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'post_init_hook'} ? : 0 0 0
633  
634 my $include = exists $args{'include_tables'} ?
635 0 ▶ delete $args{'include_tables'} : $self->include_tables;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'include_tables'} ? : 0 0 0
636  
637 my $exclude = exists $args{'exclude_tables'} ?
638 0 ▶ delete $args{'exclude_tables'} : $self->exclude_tables;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'exclude_tables'} ? : 0 0 0
639  
640 0 ▶ my $filter = exists $args{'filter_tables'} ? delete $args{'filter_tables'} :
Branch: 2 branches
BranchTrueFalseTotal
exists $args{'filter_tables'} ? : 0 0 0
!(defined $include || defined $exclude) ? : 0 0 0
Condition0%0/3
defined $include || defined $exclude
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $include || defined $exclude
defined $include defined $exclude
Truth table0%0/3
A || B
A= defined $includeB= defined $exclude
ABresult
1X1
011
000
641 (!defined $include && !defined $exclude) ? $self->filter_tables : undef;
642  
643 0 ▶ if($include || $exclude)
Branch: 1 branch
BranchTrueFalseTotal
if ($include or $exclude) 0 0 0
Condition0%0/3
$include or $exclude
l!l&&r!l&&!r
000
MC/DC0%0/2
$include or $exclude
$include $exclude
Truth table0%0/3
A or B
A= $includeB= $exclude
ABresult
1X1
011
000
644 {
645 0 ▶ if($filter)
Branch: 1 branch
BranchTrueFalseTotal
if ($filter) 0 0 0
646 {
647 0 croak "The filter_tables parameter and/or object attribute cannot ",
648 "be used with the include_tables or exclude_tables parameters ",
649 "or object attributes";
650 }
651  
652 0 ▶ if(defined $include)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $include) 0 0 0
653 {
654 0 ▶ if(ref $include eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $include eq "ARRAY") 0 0 0
655 {
656 0 $include = '(?i)\A(?:' . join('|', map { quotemeta } @$include) . ')\z'
657 }
658  
659 0 $include = qr((?i)$include);
660 }
661  
662 0 ▶ if(defined $exclude)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $exclude) 0 0 0
663 {
664 0 ▶ if(ref $exclude eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $exclude eq "ARRAY") 0 0 0
665 {
666 0 $exclude = '(?i)\A(?:' . join('|', map { quotemeta } @$exclude) . ')\z'
667 }
668  
669 0 $exclude = qr((?i)$exclude);
670 }
671  
672 $filter = sub
673 0 ▶ {
Subroutine __ANON__: not called CC=5 SCAR=29.1
674 29 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
675 0 ▶ return 0 if((defined $include && !/$include/) ||
Branch: 1 branch
BranchTrueFalseTotal
if defined $include and not /$include/ or defined $exclude and /$exclude/ 0 0 0
Condition0%0/9
defined $include and not /$include/ or defined $exclude and /$exclude/
l!l&&r!l&&!r
000
defined $include and not /$include/
!ll&&!rl&&r
000
defined $exclude and /$exclude/
!ll&&!rl&&r
000
MC/DC0%0/4
defined $include and not /$include/ or defined $exclude and /$exclude/
defined $include not /$include/ defined $exclude /$exclude/
Truth table0%0/7
A and not(B) or C and D
A= defined $includeB= not /$include/C= defined $excludeD= /$exclude/
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
676 (defined $exclude && /$exclude/));
677 0 return 1;
678 0 };
679 }
680  
681 my $class_prefix = exists $args{'class_prefix'} ?
682 0 ▶ delete $args{'class_prefix'} : $self->class_prefix || '';
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'class_prefix'} ? : 0 0 0
Condition0%0/2
$self->class_prefix or ""
l!l
00
MC/DC0%0/1
$self->class_prefix or ""
$self->class_prefix
Truth table0%0/2
A
A= $self->class_prefix
Aresult
11
00
683  
684 0 ▶ if(length $class_prefix)
Branch: 1 branch
BranchTrueFalseTotal
if (length $class_prefix) 0 0 0
685 {
686 0 ▶ unless($class_prefix =~ /^(?:\w+::)*\w+(?:::)?$/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($class_prefix =~ /^(?:\w+::)*\w+(?:::)?$/) 0 0 0
687 {
688 0 croak "Illegal class prefix: $class_prefix";
689 }
690  
691 0 ▶ $class_prefix .= '::' unless($class_prefix =~ /::$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $class_prefix =~ /::$/ 0 0 0
692 }
693  
694 # Evil masking of object attribute
695 0 local $self->{'class_prefix'} = $class_prefix;
696  
697 # When setting explicit values for attributes that cascade to
698 # affect other attributes, save off the old values are restore
699 # them at the end.
700 0 my %save;
701  
702 0 ▶ if(exists $args{'db_class'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"db_class"}) 0 0 0
703 {
704 0 my $db_class = delete $args{'db_class'};
705  
706 0 ▶ if($db && $db_class && $db_class ne $db->class)
Branch: 1 branch
BranchTrueFalseTotal
if ($db and $db_class and $db_class ne $db->class) 0 0 0
Condition0%0/6
$db and $db_class and $db_class ne $db->class
!ll&&!rl&&r
000
$db and $db_class
!ll&&!rl&&r
000
MC/DC0%0/3
$db and $db_class and $db_class ne $db->class
$db $db_class $db_class ne $db->class
Truth table0%0/4
A and B and C
A= $dbB= $db_classC= $db_class ne $db->class
ABCresult
0XX0
10X0
1100
1111
707 {
708 0 Carp::croak "The db and db_class parameters conflict: ", $db->class,
709 " vs. $db_class";
710 }
711  
712 0 ▶ if(defined(my $db_class = $self->db_class))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $db_class = $self->db_class)) 0 0 0
713 {
714 0 $save{'db_class'} = $db_class;
715 }
716  
717 0 ▶ if(defined(my $db = $self->db))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $db = $self->db)) 0 0 0
718 {
719 0 $save{'db'} = $db;
720 }
721  
722 0 $self->db_class($db_class);
723 }
724  
725 #
726 # Get or create the db object
727 #
728  
729 0 ▶ $db ||= $self->db;
Condition0%0/3
$db ||= $self->db
l!l&&r!l&&!r
000
MC/DC0%0/2
$db ||= $self->db
$db $self->db
Truth table0%0/3
A ||= B
A= $dbB= $self->db
ABresult
1X1
011
000
730  
731 0 ▶ my $db_class = $db ? $db->class : undef;
Branch: 1 branch
BranchTrueFalseTotal
$db ? : 0 0 0
732  
733 0 my $made_new_db_class = 0;
734  
735 0 ▶ unless($db)
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 0 0
736 {
737 0 $db_class = $self->db_class;
738  
739 0 ▶ if($db_class)
Branch: 1 branch
BranchTrueFalseTotal
if ($db_class) { } 0 0 0
740 {
741 0 ▶ unless(UNIVERSAL::isa($db_class, 'Rose::DB'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($db_class, "Rose::DB")) 0 0 0
742 {
743 0 my $error;
744  
745 TRY:
746 {
747 0 local $@;
748 0 eval "require $db_class";
749 0 $error = $@;
750 }
751  
752 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
753 {
754 # Failed to load existing module
755 0 ▶ unless($error =~ /^Can't locate $db_class\.pm/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($error =~ /^Can't locate $db_class\.pm/) 0 0 0
756 {
757 0 croak "Could not load db class '$db_class' - $error";
758 }
759  
760 # Make the class
761 29 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
762 0 @{"${db_class}::ISA"} = qw(Rose::DB);
763 0 $db_class->registry(clone(Rose::DB->registry));
764 }
765 }
766 }
767 else
768 {
769 0 $db_class = $self->generate_db_base_class_name;
770  
771 # Make a class
772 29 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
773 0 @{"${db_class}::ISA"} = qw(Rose::DB);
774 0 $db_class->registry(clone(Rose::DB->registry));
775  
776 0 ▶ push(@$extra_classes, $db_class) if($extra_classes);
Branch: 1 branch
BranchTrueFalseTotal
if $extra_classes 0 0 0
777 0 $made_new_db_class = 1;
778 }
779 }
780  
781 # Create the init_db subroutine that will be used with the objects
782 0 my %db_args;
783  
784 0 ▶ if($db)
Branch: 1 branch
BranchTrueFalseTotal
if ($db) 0 0 0
785 {
786 0 %db_args =
787 (
788 type => $db->type,
789 domain => $db->domain,
790 );
791  
792 0 ▶ delete $db_args{'type'} if($db_args{'type'} eq $db->default_type);
Branch: 1 branch
BranchTrueFalseTotal
if $db_args{"type"} eq $db->default_type 0 0 0
793 0 ▶ delete $db_args{'domain'} if($db_args{'domain'} eq $db->default_domain);
Branch: 1 branch
BranchTrueFalseTotal
if $db_args{"domain"} eq $db->default_domain 0 0 0
794 }
795  
796 0 foreach my $attr (qw(db_dsn db_catalog db_schema db_username db_password db_database))
797 {
798 0 (my $db_attr = $attr) =~ s/^db_//;
799 29 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
800 0 ▶ $db_args{$db_attr} = $self->$attr() if(defined $self->$attr());
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->$attr 0 0 0
801 }
802  
803 0 ▶ $db_args{'connect_options'} = $self->db_options if(defined $self->db_options);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->db_options 0 0 0
804  
805 # Set up the object base class
806 0 my @base_classes = $self->base_classes;
807  
808 0 foreach my $class (@base_classes)
809 {
810 29 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
811 0 ▶ unless(UNIVERSAL::isa($class, 'Rose::DB::Object') || @{"${class}::ISA"})
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($class, "Rose::DB::Object") or @{"${class}::ISA";}) 0 0 0
Condition0%0/3
UNIVERSAL::isa($class, "Rose::DB::Object") or @{"${class}::ISA";}
l!l&&r!l&&!r
000
MC/DC0%0/2
UNIVERSAL::isa($class, "Rose::DB::Object") or @{"${class}::ISA";}
UNIVERSAL::isa($class, "Rose::DB::Object") @{"${class}::ISA";}
Truth table0%0/3
A or B
A= UNIVERSAL::isa($class, "Rose::DB::Object")B= @{"${class}::ISA";}
ABresult
1X1
011
000
812 {
813 0 my $error;
814  
815 TRY:
816 {
817 0 local $@;
818 0 eval "require $class";
819 0 $error = $@;
820 }
821  
822 0 ▶ croak $error if($error);
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
823 }
824 }
825  
826 0 my ($init_db, $need_new_init_db);
827  
828 # Check if the base class already has its own init_db
829 0 my $can_rdbo = Rose::DB::Object->can('init_db');
830 0 my $can_base = $base_classes[0]->can('init_db');
831  
832 0 ▶ unless($can_rdbo && $can_base && $can_rdbo ne $can_base)
Branch: 1 branch
BranchTrueFalseTotal
unless ($can_rdbo and $can_base and $can_rdbo ne $can_base) 0 0 0
Condition0%0/6
$can_rdbo and $can_base and $can_rdbo ne $can_base
!ll&&!rl&&r
000
$can_rdbo and $can_base
!ll&&!rl&&r
000
MC/DC0%0/3
$can_rdbo and $can_base and $can_rdbo ne $can_base
$can_rdbo $can_base $can_rdbo ne $can_base
Truth table0%0/4
A and B and C
A= $can_rdboB= $can_baseC= $can_rdbo ne $can_base
ABCresult
0XX0
10X0
1100
1111
833 {
834 0 $need_new_init_db = 1;
835 }
836  
837 0 ▶ if($made_new_db_class)
Branch: 1 branch
BranchTrueFalseTotal
if ($made_new_db_class) { } 0 0 0
838 {
839 0 ▶ if($db_args{'dsn'} && !$db_args{'driver'})
Branch: 1 branch
BranchTrueFalseTotal
if ($db_args{"dsn"} and not $db_args{"driver"}) 0 0 0
Condition0%0/3
$db_args{"dsn"} and not $db_args{"driver"}
!ll&&!rl&&r
000
MC/DC0%0/2
$db_args{"dsn"} and not $db_args{"driver"}
$db_args{"dsn"} not $db_args{"driver"}
Truth table0%0/3
A and not(B)
A= $db_args{"dsn"}B= not $db_args{"driver"}
ABresult
0X0
100
111
840 {
841 0 ▶ if(DBI->can('parse_dsn'))
Branch: 1 branch
BranchTrueFalseTotal
if ("DBI"->can("parse_dsn")) 0 0 0
842 {
843 0 $db_args{'driver'} = lc((DBI->parse_dsn($db_args{'dsn'}))[1]);
844 }
845  
846 0 ▶ unless($db_args{'driver'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($db_args{"driver"}) 0 0 0
847 {
848 0 ▶ $db_args{'dsn'} =~ /^dbi:(\w+)/i or
Branch: 1 branch
BranchTrueFalseTotal
$db_args{"dsn"} =~ /^dbi:(\w+)/i or Carp::croak(qq[Could not extract driver name from DSN: $db_args{"dsn"}]) 0 0 0
849 Carp::croak "Could not extract driver name from DSN: $db_args{'dsn'}";
850  
851 0 $db_args{'driver'} = lc $1;
852 }
853 }
854  
855 0 $db_class->register_db(domain => $db_class->default_domain,
856 type => $db_class->default_type,
857 %db_args);
858  
859 0 my $entry =
860 $db_class->registry->entry(domain => $db_class->default_domain,
861 type => $db_class->default_type);
862  
863 0 $extra_info->{'db_entry'} = { %db_args };
864  
865 0 ▶ unless($entry->database)
Branch: 1 branch
BranchTrueFalseTotal
unless ($entry->database) 0 0 0
866 {
867 # Need appropriate db just for parsing
868 0 my $tmp_db = $db_class->new;
869  
870 0 ▶ my $database = $tmp_db->database_from_dsn($entry->dsn) or
Branch: 1 branch
BranchTrueFalseTotal
my $database = $tmp_db->database_from_dsn($entry->dsn) or Carp::croak("Could not extract database name from DSN: ", $entry->dsn) 0 0 0
871 Carp::croak "Could not extract database name from DSN: ", $entry->dsn;
872  
873 0 $entry->database($database);
874  
875 0 $extra_info->{'database'} = $database;
876 }
877  
878 0 ▶ $init_db = sub { $db_class->new };
Subroutine __ANON__: not called CC=1 SCAR=6.9
879  
880 0 $extra_info->{'perl_init_db'} =
881 "use $db_class;\n\n" .
882 "sub init_db { $db_class->new }";
883 }
884 else
885 {
886 0 ▶ $init_db = $need_new_init_db ? sub { $db_class->new(%db_args) } : $can_base;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$need_new_init_db ? : 0 0 0
887  
888 0 my $hash = perl_hashref(hash => \%db_args,
889 inline => 1,
890 no_curlies => 1,
891 indent => 0);
892  
893 0 ▶ if($need_new_init_db)
Branch: 1 branch
BranchTrueFalseTotal
if ($need_new_init_db) 0 0 0
894 {
895 0 $extra_info->{'perl_init_db'} =
896 "use $db_class;\n\n" .
897 "sub init_db { $db_class->new($hash) }";
898 }
899 }
900  
901 # Refresh the db
902 0 $db = $init_db->();
903  
904 0 $extra_info->{'init_db_in_base_class'} = 0;
905  
906 # Install the init_db routine in the base class, but only if
907 # using the default base class.
908 0 ▶ if($self->using_default_base_class)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->using_default_base_class) { } 0 0 0
909 {
910 29 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
911 0 *{"$base_classes[0]::init_db"} = $init_db;
912 0 $extra_info->{'init_db_in_base_class'} = 1;
913 0 $extra_info->{'base_classes'}{$base_classes[0]}++;
914 0 push(@$extra_classes, $base_classes[0]);
915 }
916 else
917 {
918 0 ▶ if($made_new_db_class || $db_class ne 'Rose::DB')
Branch: 1 branch
BranchTrueFalseTotal
if ($made_new_db_class or $db_class ne 'Rose::DB') { } 0 0 0
Condition0%0/3
$made_new_db_class or $db_class ne "Rose::DB"
l!l&&r!l&&!r
000
MC/DC0%0/2
$made_new_db_class or $db_class ne "Rose::DB"
$made_new_db_class $db_class ne "Rose::DB"
Truth table0%0/3
A or B
A= $made_new_db_classB= $db_class ne "Rose::DB"
ABresult
1X1
011
000
919 {
920 0 ▶ if($need_new_init_db)
Branch: 1 branch
BranchTrueFalseTotal
if ($need_new_init_db) 0 0 0
921 {
922 29 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
923 29 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
924 0 *{"$base_classes[0]::init_db"} = $init_db;
925 }
926
927 0 $extra_info->{'init_db_in_base_class'} = 1;
928 0 $extra_info->{'base_classes'}{$base_classes[0]}++;
929 }
930 else
931 {
932 0 foreach my $base_class (@base_classes)
933 {
934 0 ▶ if($base_class->can('init_db'))
Branch: 1 branch
BranchTrueFalseTotal
if ($base_class->can("init_db")) 0 0 0
935 {
936 0 $extra_info->{'init_db_in_base_class'} = 1;
937 0 last;
938 }
939 }
940 }
941 }
942  
943 0 my $force_lowercase;
944  
945 0 ▶ if(exists $args{'force_lowercase'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'force_lowercase'}) { } 0 0 0
946 {
947 0 $force_lowercase = delete $args{'force_lowercase'};
948 }
949 else
950 {
951 0 ▶ unless(defined($force_lowercase = $self->force_lowercase))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($force_lowercase = $self->force_lowercase)) 0 0 0
952 {
953 0 ▶ $force_lowercase = $db->driver eq 'oracle' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$db->driver eq 'oracle' ? : 0 0 0
954 }
955 }
956  
957 0 my $cm;
958  
959 # XXX: Lame way to check if the convention_manager attribute has
960 # XXX: been set or fetched.
961 0 ▶ if($self->{'convention_manager'})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'convention_manager'}) { } 0 0 0
962 {
963 0 $cm = $self->convention_manager;
964 }
965 else
966 {
967 0 $cm = $base_classes[0]->meta->convention_manager;
968 0 $self->convention_manager($cm);
969 }
970  
971 0 ▶ die "Missing convention manager" unless($cm);
Branch: 1 branch
BranchTrueFalseTotal
unless $cm 0 0 0
972  
973 # Propagate CM-relevant attributes
974 0 $cm->force_lowercase($force_lowercase);
975 0 $cm->no_auto_sequences($no_auto_sequences);
976  
977 0 $self->convention_manager($cm);
978  
979 0 my @classes;
980  
981 my %list_args;
982 0 ▶ $list_args{'include_views'} = 1 if($include_views);
Branch: 1 branch
BranchTrueFalseTotal
if $include_views 0 0 0
983  
984 # XXX: Horrible hack. Replce eventually...
985 0 ▶ local $Rose::DB::Object::Metadata::Auto::Missing_PK_OK =
Branch: 1 branch
BranchTrueFalseTotal
$require_primary_key ? : 0 0 0
986 $require_primary_key ? 0 : 1;
987  
988 0 my %created;
989  
990 # Iterate over tables, creating RDBO classes for each
991 0 foreach my $table ($db->list_tables(%list_args))
992 {
993 0 local $_ = $table;
994 0 ▶ next unless(!$filter || $filter->($table));
Branch: 1 branch
BranchTrueFalseTotal
unless not $filter or &$filter($table) 0 0 0
Condition0%0/3
not $filter or &$filter($table)
l!l&&r!l&&!r
000
MC/DC0%0/2
not $filter or &$filter($table)
not $filter &$filter($table)
Truth table0%0/3
not(A) or B
A= not $filterB= &$filter($table)
ABresult
1X1
011
000
995  
996 0 ▶ unless($db->has_primary_key($table))
Branch: 1 branch
BranchTrueFalseTotal
unless ($db->has_primary_key($table)) 0 0 0
997 {
998 0 ▶ if($warn_on_missing_primary_key)
Branch: 1 branch
BranchTrueFalseTotal
if ($warn_on_missing_primary_key) 0 0 0
999 {
1000 # Warn about tables with no primary keys
1001 0 ▶ warn "Warning: table '$table' has no primary key defined.",
Branch: 1 branch
BranchTrueFalseTotal
$require_primary_key ? : 0 0 0
1002 ($require_primary_key ? " Skipping.\n" : "\n");
1003 }
1004  
1005 # Skip table if primary keys are required
1006 0 ▶ next if($require_primary_key);
Branch: 1 branch
BranchTrueFalseTotal
if $require_primary_key 0 0 0
1007 }
1008  
1009 0 my $obj_class = $class_prefix . $cm->table_to_class($table);
1010  
1011 0 ▶ $Debug && warn "Loader loading table: $table - $obj_class\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Object::Loader::Debug and warn "Loader loading table: $table - $obj_class\n" 0 0 0
1012  
1013 29 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1014 # Skip classes that have already been created
1015 #if($obj_class->isa('Rose::DB::Object') && $obj_class->meta->is_initialized)
1016 0 ▶ if($created{$obj_class})
Branch: 1 branch
BranchTrueFalseTotal
if ($created{$obj_class}) 0 0 0
1017 {
1018 0 ▶ $Debug && warn "Skipping: $obj_class already initialized\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::DB::Object::Loader::Debug and warn "Skipping: $obj_class already initialized\n" 0 0 0
1019 0 next;
1020 }
1021  
1022 # Set up the class
1023  
1024 0 @{"${obj_class}::ISA"} = @base_classes;
1025  
1026 0 ▶ unless($extra_info->{'init_db_in_base_class'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($extra_info->{"init_db_in_base_class"}) 0 0 0
1027 {
1028 0 *{"${obj_class}::init_db"} = $init_db;
1029 }
1030  
1031 0 my $meta = $obj_class->meta;
1032  
1033 0 $meta->db($db);
1034  
1035 0 ▶ if($pre_init_hook)
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_init_hook) 0 0 0
1036 {
1037 0 ▶ if(ref $pre_init_hook eq 'CODE')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $pre_init_hook eq 'CODE') { } 0 0 0
elsif (ref $pre_init_hook ne 'ARRAY') { } 0 0 0
1038 {
1039 0 $pre_init_hook = [ $pre_init_hook ];
1040 }
1041 elsif(ref $pre_init_hook ne 'ARRAY')
1042 {
1043 0 Carp::croak "Invalid pre_init_hook: $pre_init_hook";
1044 }
1045 }
1046  
1047 0 ▶ unshift(@$pre_init_hook, sub { $self->default_pre_init_hook(@_) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
1048  
1049 0 $meta->pre_init_hook($pre_init_hook);
1050  
1051 0 ▶ if($post_init_hook)
Branch: 1 branch
BranchTrueFalseTotal
if ($post_init_hook) 0 0 0
1052 {
1053 0 ▶ if(ref $post_init_hook eq 'CODE')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $post_init_hook eq 'CODE') { } 0 0 0
elsif (ref $post_init_hook ne 'ARRAY') { } 0 0 0
1054 {
1055 0 $post_init_hook = [ $post_init_hook ];
1056 }
1057 elsif(ref $post_init_hook ne 'ARRAY')
1058 {
1059 0 Carp::croak "Invalid post_init_hook: $post_init_hook";
1060 }
1061 }
1062  
1063 0 ▶ unshift(@$post_init_hook, sub { $self->default_post_init_hook(@_) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
1064  
1065 0 $meta->post_init_hook($post_init_hook);
1066  
1067 0 $meta->table($table);
1068 0 $meta->convention_manager($cm->clone);
1069 0 $meta->db($db);
1070  
1071 my $include_predicated_unique_indexes =
1072 exists $args{'include_predicated_unique_indexes'}
1073 0 ▶ ? delete $args{'include_predicated_unique_indexes'}
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'include_predicated_unique_indexes'} ? : 0 0 0
1074 : $self->include_predicated_unique_indexes;
1075  
1076 0 $meta->include_predicated_unique_indexes($include_predicated_unique_indexes);
1077  
1078 0 $meta->auto_initialize(%args);
1079  
1080 0 push(@classes, $obj_class);
1081  
1082 0 $created{$obj_class}++;
1083  
1084 # Make the manager class
1085 0 ▶ if($with_managers)
Branch: 1 branch
BranchTrueFalseTotal
if ($with_managers) 0 0 0
1086 {
1087 0 my $mgr_class = $self->generate_manager_class_name($obj_class, $cm);
1088  
1089 0 $meta->make_manager_class(
1090 class => $mgr_class,
1091 base_name => $cm->auto_manager_base_name($table, $obj_class),
1092 isa => scalar $self->manager_base_classes);
1093  
1094 0 push(@classes, $mgr_class);
1095 }
1096 }
1097  
1098 0 ▶ if(@classes)
Branch: 1 branch
BranchTrueFalseTotal
if (@classes) 0 0 0
1099 {
1100 0 my $meta = $classes[0]->meta;
1101  
1102 # Retry deferred stuff: two passes
1103 0 for(1 .. 2)
1104 {
1105 0 $meta->retry_deferred_tasks;
1106 0 $meta->retry_deferred_foreign_keys;
1107 0 $meta->retry_deferred_relationships;
1108 }
1109  
1110 0 $classes[0]->meta_class->clear_all_dbs;
1111 }
1112  
1113 0 ▶ if(%save)
Branch: 1 branch
BranchTrueFalseTotal
if (%save) 0 0 0
1114 {
1115 0 ▶ while(my($method, $value) = each(%save))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %save) 0 0 0
1116 {
1117 0 $self->$method($value);
1118 }
1119 }
1120  
1121 0 ▶ return wantarray ? @classes : \@classes;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1122 }
1123  
1124 29 1;
1125  
1126 __END__
« Object/QueryBuilder.pm ↑ Summary Object/MakeMethods/Date.pm »