Object/ConventionManager.pm

filter: Statementstmt 55.8% 187 / 335 Branchbran 36.1% 68 / 188 Conditioncond 19.2% 20 / 104 MC/DCmcdc 5.0% 3 / 59 Subroutinesub 66.0% 33 / 50 Podpod 71.0% 27 / 38 totaltotal 43.6% 338 / 774 CC 145 SCAR 41.2
CC
145
Cov
44%
method_name_conflicts
306.0
auto_foreign_key_name
210.0
auto_foreign_key
85.8
CRAP 61.8
« Object/Metadata/PrimaryKey.pm ↑ Summary Object/Metadata/Auto/Informix.pm »
1 package Rose::DB::Object::ConventionManager;
2  
3 61 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 61 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 61 ▶use Scalar::Util();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 61 ▶use Rose::DB::Object::Metadata::ForeignKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 61 ▶use Rose::DB::Object::Metadata::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 61 our @ISA = qw(Rose::DB::Object::Metadata::Object);
12  
13 61 our $VERSION = '0.795';
14  
15 61 our $Debug = 0;
16  
17 use Rose::Object::MakeMethods::Generic
18 61 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
19 61 'scalar --get_set_init' =>
20 [
21 'singular_to_plural_function',
22 'plural_to_singular_function',
23 ],
24  
25 boolean =>
26 [
27 tables_are_singular => { default => 0 },
28 force_lowercase => { default => 0 },
29 no_auto_sequences => { default => 0 },
30 ],
31 61 );
32  
33 61 *meta = \&Rose::DB::Object::Metadata::Object::parent;
34  
35 sub class_to_table_singular
36 109 ▶{
Subroutine class_to_table_singular: called CC=2 SCAR=7.2
Pod documented
37 109 my($self, $class) = @_;
38  
39 109 ▶ $class ||= $self->meta->class;
Condition33%1/3
$class ||= $self->meta->class
l!l&&r!l&&!r
01090
MC/DC0%0/2
$class ||= $self->meta->class
$class $self->meta->class
Truth table33%1/3
A ||= B
A= $classB= $self->meta->class
ABresult
1X1
011
000
40  
41 109 my $table = $self->class_suffix($class);
42 109 $table =~ s/([a-z]\d*|^\d+)([A-Z])/$1_$2/g;
43 109 return lc $table;
44 }
45  
46 sub class_suffix
47 109 ▶{
Subroutine class_suffix: called CC=1 SCAR=0.0
Pod undocumented
48 109 my($self, $class) = @_;
49  
50 109 $class =~ /(\w+)$/;
51 109 return $1;
52 }
53  
54 sub class_to_table_plural
55 92 ▶{
Subroutine class_to_table_plural: called CC=1 SCAR=0.0
Pod documented
56 92 my($self) = shift;
57 92 $self->singular_to_plural($self->class_to_table_singular(@_));
58 }
59  
60 sub table_to_class_plural
61 12 ▶{
Subroutine table_to_class_plural: called CC=1 SCAR=0.0
Pod undocumented
62 12 my($self, $table, $prefix) = @_;
63 12 return $self->table_to_class($table, $prefix, 1);
64 }
65  
66 sub table_to_class
67 67 ▶{
Subroutine table_to_class: called CC=4 SCAR=13.9
Pod documented
68 67 my($self, $table, $prefix, $plural) = @_;
69 67 ▶ $table = lc $table if ($self->force_lowercase);
Branch: 1 branch
BranchTrueFalseTotal
if $self->force_lowercase 0 67 67
70 67 ▶ $table = $self->plural_to_singular($table) unless($plural);
Branch: 1 branch
BranchTrueFalseTotal
unless $plural 55 12 67
71 67 $table =~ s/_(.)/\U$1/g;
72 67 $table =~ s/[^\w:]/_/g;
73 67 ▶ return ($prefix || '') . ucfirst $table;
Condition100%2/2
$prefix || ''
l!l
4027
MC/DC100%1/1
$prefix || ''
$prefix
Truth table100%2/2
A
A= $prefix
Aresult
11
00
74 }
75  
76 sub auto_manager_base_name
77 7 ▶{
Subroutine auto_manager_base_name: called CC=4 SCAR=14.6
Pod documented
78 7 my($self, $table, $object_class) = @_;
79  
80 7 ▶ $table ||= $self->class_to_table_plural;
Condition66%2/3
$table ||= $self->class_to_table_plural
l!l&&r!l&&!r
340
MC/DC0%0/2
$table ||= $self->class_to_table_plural
$table $self->class_to_table_plural
Truth table66%2/3
A ||= B
A= $tableB= $self->class_to_table_plural
ABresult
1X1
011
000
81  
82 7 ▶ $table = lc $table if($self->force_lowercase);
Branch: 1 branch
BranchTrueFalseTotal
if $self->force_lowercase 0 7 7
83  
84 7 ▶ return $self->tables_are_singular ? $self->singular_to_plural($table) : $table;
Branch: 1 branch
BranchTrueFalseTotal
$self->tables_are_singular ? : 0 7 7
85 }
86  
87 1 ▶sub auto_manager_base_class { 'Rose::DB::Object::Manager' }
Subroutine auto_manager_base_class: called CC=1 SCAR=0.0
Pod documented
88  
89 sub auto_manager_class_name
90 2 ▶{
Subroutine auto_manager_class_name: called CC=2 SCAR=7.0
Pod documented
91 2 my($self, $object_class) = @_;
92  
93 2 ▶ $object_class ||= $self->meta->class;
Condition66%2/3
$object_class ||= $self->meta->class
l!l&&r!l&&!r
110
MC/DC0%0/2
$object_class ||= $self->meta->class
$object_class $self->meta->class
Truth table66%2/3
A ||= B
A= $object_classB= $self->meta->class
ABresult
1X1
011
000
94  
95 2 return "${object_class}::Manager";
96 }
97  
98 sub auto_manager_method_name
99 1 ▶{
Subroutine auto_manager_method_name: called CC=1 SCAR=0.0
Pod documented
100 1 my($self, $type, $base_name, $object_class) = @_;
101 1 return undef; # rely on hard-coded defaults in Manager
102 }
103  
104 sub class_prefix
105 51 ▶{
Subroutine class_prefix: called CC=2 SCAR=6.9
Pod documented
106 51 my($self, $class) = @_;
107 51 $class =~ /^((?:\w+::)*)/;
108 51 ▶ return $1 || '';
Condition100%2/2
$1 || ''
l!l
501
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
109 }
110  
111 sub related_table_to_class
112 39 ▶{
Subroutine related_table_to_class: called CC=1 SCAR=0.0
Pod documented
113 39 my($self, $table, $local_class, $plural) = @_;
114 39 return $self->table_to_class($table, $self->class_prefix($local_class), $plural);
115 }
116  
117 sub table_singular
118 0 ▶{
Subroutine table_singular: not called CC=2 SCAR=17.9
Pod documented
119 0 my($self) = shift;
120  
121 0 my $table = $self->meta->table;
122  
123 0 ▶ if($self->tables_are_singular)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tables_are_singular) 0 0 0
124 {
125 0 return $table;
126 }
127  
128 0 return $self->plural_to_singular($table);
129 }
130  
131 sub table_plural
132 0 ▶{
Subroutine table_plural: not called CC=2 SCAR=17.9
Pod documented
133 0 my($self) = shift;
134  
135 0 my $table = $self->meta->table;
136  
137 0 ▶ if($self->tables_are_singular)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tables_are_singular) 0 0 0
138 {
139 0 return $self->singular_to_plural($table);
140 }
141  
142 0 return $table;
143 }
144  
145 sub auto_table_name
146 89 ▶{
Subroutine auto_table_name: called CC=2 SCAR=6.9
Pod documented
147 89 my($self) = shift;
148  
149 89 ▶ if($self->tables_are_singular)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tables_are_singular) { } 1 88 89
150 {
151 1 return $self->class_to_table_singular;
152 }
153 else
154 {
155 88 return $self->class_to_table_plural;
156 }
157 }
158  
159 sub auto_primary_key_column_names
160 77 ▶{
Subroutine auto_primary_key_column_names: called CC=6 SCAR=19.0
Pod documented
161 77 my($self) = shift;
162  
163 77 my $meta = $self->meta;
164  
165 # 1. Column named "id"
166 77 ▶ return [ 'id' ] if($meta->column('id'));
Branch: 1 branch
BranchTrueFalseTotal
if $meta->column("id") 65 12 77
167  
168 # 2. Column named <table singular>_id
169 12 my $column = $self->class_to_table_singular . '_id';
170 12 ▶ return [ $column ] if($meta->column($column));
Branch: 1 branch
BranchTrueFalseTotal
if $meta->column($column) 1 11 12
171  
172 # 3. The first serial column in the column list, alphabetically
173 11 foreach my $column (sort { lc $a->name cmp lc $b->name } $meta->columns)
174 {
175 12 ▶ return [ $column->name ] if($column->type =~ /^(?:big)?serial$/);
Branch: 1 branch
BranchTrueFalseTotal
if $column->type =~ /^(?:big)?serial$/ 11 1 12
176 }
177  
178 # 4. The first column
179 0 ▶ if(my $column = $meta->first_column)
Branch: 1 branch
BranchTrueFalseTotal
if (my $column = $meta->first_column) 0 0 0
180 {
181 0 return [ $column->name ];
182 }
183  
184 0 return;
185 }
186  
187 sub auto_column_method_name
188 184 ▶{
Subroutine auto_column_method_name: called CC=2 SCAR=7.1
Pod documented
189 184 my($self, $type, $column, $name, $object_class) = @_;
190 184 ▶ return lc $name if ($self->force_lowercase);
Branch: 1 branch
BranchTrueFalseTotal
if $self->force_lowercase 0 184 184
191 184 return undef; # rely on hard-coded defaults in Metadata
192 }
193  
194 110 ▶sub init_singular_to_plural_function { }
Subroutine init_singular_to_plural_function: called CC=1 SCAR=0.0
Pod documented
195 62 ▶sub init_plural_to_singular_function { }
Subroutine init_plural_to_singular_function: called CC=1 SCAR=0.0
Pod documented
196  
197 sub singular_to_plural
198 110 ▶{
Subroutine singular_to_plural: called CC=4 SCAR=14.0
Pod documented
199 110 my($self, $word) = @_;
200  
201 110 ▶ if(my $code = $self->singular_to_plural_function)
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->singular_to_plural_function) 0 110 110
202 {
203 0 return $code->($word);
204 }
205  
206 110 ▶ if($word =~ /(?:x|[se]s)$/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ /(?:x|[se]s)$/i) { } 9 101 110
207 {
208 9 return $word . 'es';
209 }
210 else
211 {
212 101 $word =~ s/y$/ies/i;
213 }
214  
215 101 ▶ return $word =~ /s$/i ? $word : ($word . 's');
Branch: 1 branch
BranchTrueFalseTotal
$word =~ /s$/i ? : 6 95 101
216 }
217  
218 sub plural_to_singular
219 62 ▶{
Subroutine plural_to_singular: called CC=4 SCAR=14.0
Pod documented
220 62 my($self, $word) = @_;
221  
222 62 ▶ if(my $code = $self->plural_to_singular_function)
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->plural_to_singular_function) 0 62 62
223 {
224 0 return $code->($word);
225 }
226  
227 62 $word =~ s/ies$/y/i;
228  
229 62 ▶ return $word if($word =~ s/ses$/s/i);
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ses$/s/i 1 61 62
230 61 ▶ return $word if($word =~ /[aeiouy]ss$/i);
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /[aeiouy]ss$/i 1 60 61
231  
232 60 $word =~ s/s$//i;
233  
234 60 return $word;
235 }
236  
237 sub method_name_conflicts
238 0 ▶{
Subroutine method_name_conflicts: not called CC=17 SCAR=57.2
Pod undocumented
239 0 my($self, $name) = @_;
240  
241 0 ▶ return 1 if(Rose::DB::Object->can($name));
Branch: 1 branch
BranchTrueFalseTotal
if "Rose::DB::Object"->can($name) 0 0 0
242  
243 0 my $meta = $self->meta;
244  
245 0 foreach my $column ($meta->columns)
246 {
247 0 foreach my $type ($column->auto_method_types)
248 {
249 0 ▶ my $method = $column->method_name($type) ||
Condition0%0/5
$column->method_name($type) || $meta->method_name_from_column_name($column->name, $type) || (next)
l!l
00
$column->method_name($type) or $meta->method_name_from_column_name($column->name, $type)
l!l&&r!l&&!r
000
MC/DC0%0/2
$column->method_name($type) || $meta->method_name_from_column_name($column->name, $type) || (next)
$column->method_name($type) $meta->method_name_from_column_name($column->name, $type)
Truth table0%0/3
A or B
A= $column->method_name($type)B= $meta->method_name_from_column_name($column->name, $type)
ABresult
1X1
011
000
250 $meta->method_name_from_column_name($column->name, $type) ||
251 next;
252  
253 0 ▶ return 1 if($name eq $method);
Branch: 1 branch
BranchTrueFalseTotal
if $name eq $method 0 0 0
254 }
255 }
256  
257 0 foreach my $foreign_key ($meta->foreign_keys)
258 {
259 0 foreach my $type ($foreign_key->auto_method_types)
260 {
261 0 ▶ my $method =
Condition0%0/5
$foreign_key->method_name($type) || $foreign_key->build_method_name_for_type($type) || (next)
l!l
00
$foreign_key->method_name($type) or $foreign_key->build_method_name_for_type($type)
l!l&&r!l&&!r
000
MC/DC0%0/2
$foreign_key->method_name($type) || $foreign_key->build_method_name_for_type($type) || (next)
$foreign_key->method_name($type) $foreign_key->build_method_name_for_type($type)
Truth table0%0/3
A or B
A= $foreign_key->method_name($type)B= $foreign_key->build_method_name_for_type($type)
ABresult
1X1
011
000
262 $foreign_key->method_name($type) ||
263 $foreign_key->build_method_name_for_type($type) || next;
264  
265 0 ▶ return 1 if($name eq $method);
Branch: 1 branch
BranchTrueFalseTotal
if $name eq $method 0 0 0
266 }
267 }
268  
269 0 foreach my $relationship ($meta->relationships)
270 {
271 0 foreach my $type ($relationship->auto_method_types)
272 {
273 0 ▶ my $method =
Condition0%0/5
$relationship->method_name($type) || $relationship->build_method_name_for_type($type) || (next)
l!l
00
$relationship->method_name($type) or $relationship->build_method_name_for_type($type)
l!l&&r!l&&!r
000
MC/DC0%0/2
$relationship->method_name($type) || $relationship->build_method_name_for_type($type) || (next)
$relationship->method_name($type) $relationship->build_method_name_for_type($type)
Truth table0%0/3
A or B
A= $relationship->method_name($type)B= $relationship->build_method_name_for_type($type)
ABresult
1X1
011
000
274 $relationship->method_name($type) ||
275 $relationship->build_method_name_for_type($type) || next;
276  
277 0 ▶ return 1 if($name eq $method);
Branch: 1 branch
BranchTrueFalseTotal
if $name eq $method 0 0 0
278 }
279 }
280  
281 0 return 0;
282 }
283  
284 sub auto_column_sequence_name
285 0 ▶{
Subroutine auto_column_sequence_name: not called CC=5 SCAR=34.0
Pod undocumented
286 0 my($self, $table, $column, $db) = @_;
287 0 my $name = join('_', $table, $column, 'seq');
288 0 ▶ return uc $name if($db && $db->likes_uppercase_sequence_names);
Branch: 1 branch
BranchTrueFalseTotal
if $db and $db->likes_uppercase_sequence_names 0 0 0
Condition0%0/3
$db and $db->likes_uppercase_sequence_names
!ll&&!rl&&r
000
MC/DC0%0/2
$db and $db->likes_uppercase_sequence_names
$db $db->likes_uppercase_sequence_names
Truth table0%0/3
A and B
A= $dbB= $db->likes_uppercase_sequence_names
ABresult
0X0
100
111
289 0 ▶ return lc $name if($db && $db->likes_lowercase_sequence_names);
Branch: 1 branch
BranchTrueFalseTotal
if $db and $db->likes_lowercase_sequence_names 0 0 0
Condition0%0/3
$db and $db->likes_lowercase_sequence_names
!ll&&!rl&&r
000
MC/DC0%0/2
$db and $db->likes_lowercase_sequence_names
$db $db->likes_lowercase_sequence_names
Truth table0%0/3
A and B
A= $dbB= $db->likes_lowercase_sequence_names
ABresult
0X0
100
111
290 0 return $name;
291 }
292  
293 0 ▶sub auto_primary_key_column_sequence_name { shift->auto_column_sequence_name(@_) }
Subroutine auto_primary_key_column_sequence_name: not called CC=1 SCAR=6.9
Pod undocumented
294  
295 sub auto_foreign_key_name
296 0 ▶{
Subroutine auto_foreign_key_name: not called CC=14 SCAR=53.5
Pod documented
297 0 my($self, $f_class, $current_name, $key_columns, $used_names) = @_;
298  
299 0 ▶ if($self->force_lowercase)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->force_lowercase) 0 0 0
300 {
301 0 $current_name = lc $current_name;
302 0 $key_columns = { map { lc } %$key_columns };
303 }
304  
305 0 ▶ my $f_meta = $f_class->meta or return $current_name;
Branch: 1 branch
BranchTrueFalseTotal
my $f_meta = $f_class->meta or return $current_name 0 0 0
306 0 ▶ my $name = $self->plural_to_singular($f_meta->table) || $current_name;
Condition0%0/3
$self->plural_to_singular($f_meta->table) || $current_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->plural_to_singular($f_meta->table) || $current_name
$self->plural_to_singular($f_meta->table) $current_name
Truth table0%0/3
A || B
A= $self->plural_to_singular($f_meta->table)B= $current_name
ABresult
1X1
011
000
307  
308 0 ▶ if(keys %$key_columns == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$key_columns == 1) 0 0 0
309 {
310 0 my($local_column, $foreign_column) = %$key_columns;
311  
312 # Try to lop off foreign column name. Example:
313 # my_foreign_object_id -> my_foreign_object
314 0 ▶ if($local_column =~ s/_$foreign_column$//i)
Branch: 1 branch
BranchTrueFalseTotal
if ($local_column =~ s/_$foreign_column$//i) { } 0 0 0
315 {
316 0 $name = $local_column;
317 }
318 else
319 {
320 0 ▶ $name = $self->plural_to_singular($f_meta->table) || $current_name;
Condition0%0/3
$self->plural_to_singular($f_meta->table) || $current_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->plural_to_singular($f_meta->table) || $current_name
$self->plural_to_singular($f_meta->table) $current_name
Truth table0%0/3
A || B
A= $self->plural_to_singular($f_meta->table)B= $current_name
ABresult
1X1
011
000
321 }
322 }
323  
324 # Avoid method name conflicts
325 0 ▶ if($self->method_name_conflicts($name) || $used_names->{$name})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->method_name_conflicts($name) or $used_names->{$name}) 0 0 0
Condition0%0/3
$self->method_name_conflicts($name) or $used_names->{$name}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->method_name_conflicts($name) or $used_names->{$name}
$self->method_name_conflicts($name) $used_names->{$name}
Truth table0%0/3
A or B
A= $self->method_name_conflicts($name)B= $used_names->{$name}
ABresult
1X1
011
000
326 {
327 0 foreach my $s ('_obj', '_object')
328 {
329 # Try the name with a suffix appended
330 0 ▶ unless($self->method_name_conflicts($name . $s) ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->method_name_conflicts($name . $s) or $$used_names{$name . $s}) 0 0 0
Condition0%0/3
$self->method_name_conflicts($name . $s) or $$used_names{$name . $s}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->method_name_conflicts($name . $s) or $$used_names{$name . $s}
$self->method_name_conflicts($name . $s) $$used_names{$name . $s}
Truth table0%0/3
A or B
A= $self->method_name_conflicts($name . $s)B= $$used_names{$name . $s}
ABresult
1X1
011
000
331 $used_names->{$name . $s})
332 {
333 0 return $name . $s;
334 }
335 }
336  
337 0 my $i = 1;
338  
339 # Give up and go with numbers...
340 $i++ while($self->method_name_conflicts($name . $i) ||
341 0 ▶ $used_names->{$name . $i});
Branch: 1 branch
BranchTrueFalseTotal
$self->method_name_conflicts($name . $i) || $$used_names{$name . $i} and do { ++$i } 0 0 0
Condition0%0/3
$self->method_name_conflicts($name . $i) or $$used_names{$name . $i}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->method_name_conflicts($name . $i) or $$used_names{$name . $i}
$self->method_name_conflicts($name . $i) $$used_names{$name . $i}
Truth table0%0/3
A or B
A= $self->method_name_conflicts($name . $i)B= $$used_names{$name . $i}
ABresult
1X1
011
000
342  
343 0 return $name . $i;
344 }
345  
346 0 return $name;
347 }
348  
349 sub auto_table_to_relationship_name_plural
350 0 ▶{
Subroutine auto_table_to_relationship_name_plural: not called CC=3 SCAR=24.8
Pod undocumented
351 0 my($self, $table) = @_;
352 0 ▶ $table = lc $table if ($self->force_lowercase);
Branch: 1 branch
BranchTrueFalseTotal
if $self->force_lowercase 0 0 0
353 0 ▶ return $self->tables_are_singular ? $self->singular_to_plural($table) : $table;
Branch: 1 branch
BranchTrueFalseTotal
$self->tables_are_singular ? : 0 0 0
354 }
355  
356 sub auto_class_to_relationship_name_plural
357 0 ▶{
Subroutine auto_class_to_relationship_name_plural: not called CC=1 SCAR=6.9
Pod undocumented
358 0 my($self, $class) = @_;
359 0 return $self->class_to_table_plural($class);
360 }
361  
362 sub auto_foreign_key_to_relationship_name_plural
363 0 ▶{
Subroutine auto_foreign_key_to_relationship_name_plural: not called CC=2 SCAR=17.9
Pod undocumented
364 0 my($self, $fk) = @_;
365 0 ▶ my $name = $self->force_lowercase ? lc $fk->name : $fk->name;
Branch: 1 branch
BranchTrueFalseTotal
$self->force_lowercase ? : 0 0 0
366 0 return $self->singular_to_plural($name);
367 }
368  
369 sub auto_relationship_name_one_to_many
370 0 ▶{
Subroutine auto_relationship_name_one_to_many: not called CC=5 SCAR=34.0
Pod documented
371 0 my($self, $table, $class) = @_;
372 #return $self->auto_class_to_relationship_name_plural($class);
373 0 my $name = $self->auto_table_to_relationship_name_plural($table);
374  
375 # Avoid method name conflicts
376 0 ▶ if($self->method_name_conflicts($name))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->method_name_conflicts($name)) 0 0 0
377 {
378 0 foreach my $s ('_objs', '_objects')
379 {
380 # Try the name with a suffix appended
381 0 ▶ unless($self->method_name_conflicts($name . $s))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->method_name_conflicts($name . $s)) 0 0 0
382 {
383 0 return $name . $s;
384 }
385 }
386  
387 0 my $i = 1;
388  
389 # Give up and go with numbers...
390 0 ▶ $i++ while($self->method_name_conflicts($name . $i));
Branch: 1 branch
BranchTrueFalseTotal
$self->method_name_conflicts($name . $i) and do { ++$i } 0 0 0
391  
392 0 return $name . $i;
393 }
394  
395 0 return $name;
396 }
397  
398 sub auto_relationship_name_many_to_many
399 0 ▶{
Subroutine auto_relationship_name_many_to_many: not called CC=5 SCAR=34.0
Pod documented
400 0 my($self, $fk, $map_class) = @_;
401 0 my $name = $self->auto_foreign_key_to_relationship_name_plural($fk);
402  
403 # Avoid method name conflicts
404 0 ▶ if($self->method_name_conflicts($name))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->method_name_conflicts($name)) 0 0 0
405 {
406 0 foreach my $s ('_objs', '_objects')
407 {
408 # Try the name with a suffix appended
409 0 ▶ unless($self->method_name_conflicts($name . $s))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->method_name_conflicts($name . $s)) 0 0 0
410 {
411 0 return $name . $s;
412 }
413 }
414  
415 0 my $i = 1;
416  
417 # Give up and go with numbers...
418 0 ▶ $i++ while($self->method_name_conflicts($name . $i));
Branch: 1 branch
BranchTrueFalseTotal
$self->method_name_conflicts($name . $i) and do { ++$i } 0 0 0
419  
420 0 return $name . $i;
421 }
422  
423 0 return $name;
424 }
425  
426 sub auto_relationship_name_one_to_one
427 0 ▶{
Subroutine auto_relationship_name_one_to_one: not called CC=6 SCAR=37.4
Pod documented
428 0 my($self, $table, $class) = @_;
429  
430 0 ▶ $table = lc $table if ($self->force_lowercase);
Branch: 1 branch
BranchTrueFalseTotal
if $self->force_lowercase 0 0 0
431  
432 0 my $name = $self->plural_to_singular($table);
433  
434 # Avoid method name conflicts
435 0 ▶ if($self->method_name_conflicts($name))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->method_name_conflicts($name)) 0 0 0
436 {
437 0 foreach my $s ('_obj', '_object')
438 {
439 # Try the name with a suffix appended
440 0 ▶ unless($self->method_name_conflicts($name . $s))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->method_name_conflicts($name . $s)) 0 0 0
441 {
442 0 return $name . $s;
443 }
444 }
445  
446 0 my $i = 1;
447  
448 # Give up and go with numbers...
449 0 ▶ $i++ while($self->method_name_conflicts($name . $i));
Branch: 1 branch
BranchTrueFalseTotal
$self->method_name_conflicts($name . $i) and do { ++$i } 0 0 0
450  
451 0 return $name . $i;
452 }
453  
454 0 return $name;
455 }
456  
457 sub is_map_class
458 0 ▶{
Subroutine is_map_class: not called CC=5 SCAR=34.0
Pod documented
459 0 my($self, $class) = @_;
460  
461 0 ▶ return 0 unless(UNIVERSAL::isa($class, 'Rose::DB::Object'));
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($class, "Rose::DB::Object") 0 0 0
462  
463 0 my $is_map_table = $self->looks_like_map_table($class->meta->table);
464 0 my $is_map_class = $self->looks_like_map_class($class);
465  
466 0 ▶ return 1 if($is_map_table && (!defined $is_map_class || $is_map_class));
Branch: 1 branch
BranchTrueFalseTotal
if $is_map_table and !defined($is_map_class) || $is_map_class 0 0 0
Condition0%0/6
$is_map_table and !defined($is_map_class) || $is_map_class
!ll&&!rl&&r
000
not defined $is_map_class or $is_map_class
l!l&&r!l&&!r
000
MC/DC0%0/3
$is_map_table and !defined($is_map_class) || $is_map_class
$is_map_table not defined $is_map_class $is_map_class
Truth table0%0/4
A and not(B) or C
A= $is_map_tableB= not defined $is_map_classC= $is_map_class
ABCresult
0XX0
1000
11X1
1011
467 0 return 0;
468 }
469  
470 sub looks_like_map_class
471 0 ▶{
Subroutine looks_like_map_class: not called CC=6 SCAR=37.4
Pod documented
472 0 my($self, $class) = @_;
473  
474 0 ▶ unless(UNIVERSAL::isa($class, 'Rose::DB::Object'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($class, "Rose::DB::Object")) 0 0 0
475 {
476 0 return undef;
477 }
478  
479 0 my $meta = $class->meta;
480 0 my @fks = $meta->foreign_keys;
481  
482 0 ▶ return 1 if(@fks == 2);
Branch: 1 branch
BranchTrueFalseTotal
if @fks == 2 0 0 0
483 0 ▶ return 0 if(($meta->is_initialized || $meta->initialized_foreign_keys) &&
Branch: 1 branch
BranchTrueFalseTotal
if $meta->is_initialized || $meta->initialized_foreign_keys and not $meta->has_deferred_foreign_keys 0 0 0
Condition0%0/6
$meta->is_initialized || $meta->initialized_foreign_keys and not $meta->has_deferred_foreign_keys
!ll&&!rl&&r
000
$meta->is_initialized or $meta->initialized_foreign_keys
l!l&&r!l&&!r
000
MC/DC0%0/3
$meta->is_initialized || $meta->initialized_foreign_keys and not $meta->has_deferred_foreign_keys
$meta->is_initialized $meta->initialized_foreign_keys not $meta->has_deferred_foreign_keys
Truth table0%0/5
A or B and not(C)
A= $meta->is_initializedB= $meta->initialized_foreign_keysC= not $meta->has_deferred_foreign_keys
ABCresult
00X0
1X00
0100
1X11
0111
484 !$meta->has_deferred_foreign_keys);
485 0 return undef;
486 }
487  
488 sub looks_like_map_table
489 0 ▶{
Subroutine looks_like_map_table: not called CC=2 SCAR=17.9
Pod documented
490 0 my($self, $table) = @_;
491  
492 0 ▶ if($table =~ m{^(?:
Branch: 1 branch
BranchTrueFalseTotal
if ($table =~ /^(?: (?:\w+_){2,}map # foo_bar_map | (?:\w+_)*\w+_(?:\w+_)*\w+s # foo_bars | (?:\w+_)*\w+s_(?:\w+_)*\w+s # foos_bars )$/xi) 0 0 0
493 (?:\w+_){2,}map # foo_bar_map
494 | (?:\w+_)*\w+_(?:\w+_)*\w+s # foo_bars
495 | (?:\w+_)*\w+s_(?:\w+_)*\w+s # foos_bars
496 )$}xi)
497 {
498 0 return 1;
499 }
500  
501 0 return 0;
502 }
503  
504 sub auto_foreign_key
505 32 ▶{
Subroutine auto_foreign_key: called CC=16 SCAR=44.5
Pod documented
506 32 my($self, $name, $spec) = @_;
507  
508 32 ▶ $spec ||= {};
Condition100%2/2
$spec ||= {}
l!l
626
MC/DC100%1/1
$spec ||= {}
$spec
Truth table100%2/2
A
A= $spec
Aresult
11
00
509  
510 32 my $meta = $self->meta;
511  
512 32 ▶ unless($spec->{'class'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($spec->{"class"}) 27 5 32
513 {
514 27 my $class = $meta->class;
515  
516 27 my $fk_class = $self->related_table_to_class($name, $class);
517  
518 LOAD:
519 {
520 # Try to load class
521 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
522 27 ▶ unless(UNIVERSAL::isa($fk_class, 'Rose::DB::Object'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($fk_class, "Rose::DB::Object")) 0 27 27
523 {
524 0 local $@;
525 0 eval "require $fk_class";
526 0 ▶ return if($@ || !UNIVERSAL::isa($fk_class, 'Rose::DB::Object'));
Branch: 1 branch
BranchTrueFalseTotal
if $@ or not UNIVERSAL::isa($fk_class, "Rose::DB::Object") 0 0 0
Condition0%0/3
$@ or not UNIVERSAL::isa($fk_class, "Rose::DB::Object")
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not UNIVERSAL::isa($fk_class, "Rose::DB::Object")
$@ not UNIVERSAL::isa($fk_class, "Rose::DB::Object")
Truth table0%0/3
A or not(B)
A= $@B= not UNIVERSAL::isa($fk_class, "Rose::DB::Object")
ABresult
1X1
011
000
527 }
528 }
529  
530 #return unless(UNIVERSAL::isa($fk_class, 'Rose::DB::Object'));
531  
532 27 $spec->{'class'} = $fk_class;
533 }
534  
535 32 ▶ unless(defined $spec->{'key_columns'})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $spec->{"key_columns"}) 27 5 32
536 {
537 my @fpk_columns = UNIVERSAL::isa($spec->{'class'}, 'Rose::DB::Object') ?
538 27 ▶ $spec->{'class'}->meta->primary_key_column_names : ();
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($spec->{'class'}, 'Rose::DB::Object') ? : 27 0 27
539  
540 # Defer population of key columns until the foreign class is initialized
541 27 ▶ unless(@fpk_columns == 1)
Branch: 1 branch
BranchTrueFalseTotal
unless (@fpk_columns == 1) 0 27 27
542 {
543 # If the foreign class has more than one primary key column, give up
544 0 ▶ return if(@fpk_columns);
Branch: 1 branch
BranchTrueFalseTotal
if @fpk_columns 0 0 0
545  
546 # If the foreign class is initialized and the foreign key spec still
547 # has no key columns, then give up.
548 0 ▶ if(UNIVERSAL::isa($spec->{'class'}, 'Rose::DB::Object') &&
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($spec->{"class"}, "Rose::DB::Object") and $spec->{"class"}->meta->is_initialized) 0 0 0
Condition0%0/3
UNIVERSAL::isa($spec->{"class"}, "Rose::DB::Object") and $spec->{"class"}->meta->is_initialized
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::isa($spec->{"class"}, "Rose::DB::Object") and $spec->{"class"}->meta->is_initialized
UNIVERSAL::isa($spec->{"class"}, "Rose::DB::Object") $spec->{"class"}->meta->is_initialized
Truth table0%0/3
A and B
A= UNIVERSAL::isa($spec->{"class"}, "Rose::DB::Object")B= $spec->{"class"}->meta->is_initialized
ABresult
0X0
100
111
549 $spec->{'class'}->meta->is_initialized)
550 {
551 0 return;
552 }
553  
554 0 my %spec = %$spec;
555  
556 $meta->add_deferred_task(
557 {
558 class => $meta->class,
559 method => "foreign_key:$name",
560  
561 code => sub
562 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
563 # Generate new foreign key, then grab the key columns from it
564 0 ▶ my $new_fk = $self->auto_foreign_key($name, \%spec) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $new_fk = $self->auto_foreign_key($name, \%spec) or return 0 0 0
565 0 my $fk = $meta->foreign_key($name);
566 0 ▶ my $key_cols = $new_fk->key_columns or return;
Branch: 1 branch
BranchTrueFalseTotal
my $key_cols = $new_fk->key_columns or return 0 0 0
567  
568 0 $fk->key_columns($key_cols);
569 },
570  
571 check => sub
572 0 ▶ {
Subroutine __ANON__: not called CC=7 SCAR=40.3
573 0 ▶ my $fk = $meta->foreign_key($name) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $fk = $meta->foreign_key($name) or return 0 0 0 0
574  
575 # If the foreign class is initialized and the foreign key still
576 # has no key columns, then we should give up.
577 0 ▶ if(UNIVERSAL::isa($fk->class, 'Rose::DB::Object') &&
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($fk->class, "Rose::DB::Object") and $fk->class->meta->is_initialized) 0 0 0
Condition0%0/3
UNIVERSAL::isa($fk->class, "Rose::DB::Object") and $fk->class->meta->is_initialized
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::isa($fk->class, "Rose::DB::Object") and $fk->class->meta->is_initialized
UNIVERSAL::isa($fk->class, "Rose::DB::Object") $fk->class->meta->is_initialized
Truth table0%0/3
A and B
A= UNIVERSAL::isa($fk->class, "Rose::DB::Object")B= $fk->class->meta->is_initialized
ABresult
0X0
100
111
578 $fk->class->meta->is_initialized)
579 {
580 0 Carp::croak "Missing key columns for foreign key named ",
581 $fk->name, " in class ", $meta->class;
582 }
583  
584 0 ▶ my $cols = $fk->key_columns or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $cols = $fk->key_columns or return 0 0 0 0
585  
586 # Everything is okay if we have key columns
587 0 ▶ return (ref($cols) && keys(%$cols) > 0) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $cols && keys %$cols > 0 ? : 0 0 0
Condition0%0/3
ref $cols and keys %$cols > 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $cols and keys %$cols > 0
ref $cols keys %$cols > 0
Truth table0%0/3
A and B
A= ref $colsB= keys %$cols > 0
ABresult
0X0
100
111
588 }
589 0 });
590  
591 0 return Rose::DB::Object::Metadata::ForeignKey->new(name => $name, %$spec);
592 }
593  
594 27 my $aliases = $meta->column_aliases;
595  
596 27 ▶ if($meta->column($name) && $aliases->{$name} && $aliases->{$name} ne $name)
Branch: 2 branches
BranchTrueFalseTotal
if ($meta->column($name) and $aliases->{$name} and $aliases->{$name} ne $name) { } 0 27 27
elsif ($meta->column("${name}_$fpk_columns[0]")) { } 27 0 27
Condition33%2/6
$meta->column($name) and $aliases->{$name} and $aliases->{$name} ne $name
!ll&&!rl&&r
2700
$meta->column($name) and $aliases->{$name}
!ll&&!rl&&r
2700
MC/DC0%0/3
$meta->column($name) and $aliases->{$name} and $aliases->{$name} ne $name
$meta->column($name) $aliases->{$name} $aliases->{$name} ne $name
Truth table25%1/4
A and B and C
A= $meta->column($name)B= $aliases->{$name}C= $aliases->{$name} ne $name
ABCresult
0XX0
10X0
1100
1111
597 {
598 0 $spec->{'key_columns'} = { $name => $fpk_columns[0] };
599 }
600 elsif($meta->column("${name}_$fpk_columns[0]"))
601 {
602 27 $spec->{'key_columns'} = { "${name}_$fpk_columns[0]" => $fpk_columns[0] };
603 }
604 0 else { return }
605 }
606  
607 32 return Rose::DB::Object::Metadata::ForeignKey->new(name => $name, %$spec);
608 }
609  
610 sub auto_relationship
611 33 ▶{
Subroutine auto_relationship: called CC=17 SCAR=32.4
Pod documented
612 33 my($self, $name, $rel_class, $spec) = @_;
613  
614 33 ▶ $spec ||= {};
Condition50%1/2
$spec ||= {}
l!l
330
MC/DC0%0/1
$spec ||= {}
$spec
Truth table50%1/2
A
A= $spec
Aresult
11
00
615  
616 33 my $meta = $self->meta;
617 33 my $rel_type = $rel_class->type;
618  
619 33 ▶ unless($spec->{'class'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($spec->{"class"}) 30 3 33
620 {
621 30 ▶ if($rel_type eq 'one to many')
Branch: 2 branches
BranchTrueFalseTotal
if ($rel_type eq 'one to many') { } 3 27 30
elsif ($rel_type =~ /^(?:one|many) to one$/) { } 6 21 27
622 {
623 3 my $class = $meta->class;
624  
625 # Get class suffix from relationship name
626 3 my $table = $self->plural_to_singular($name);
627 3 my $f_class = $self->related_table_to_class($table, $class);
628  
629 LOAD:
630 {
631 # Try to load class
632 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
633 3 ▶ unless(UNIVERSAL::isa($f_class, 'Rose::DB::Object'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($f_class, "Rose::DB::Object")) 0 3 3
634 {
635 0 local $@;
636 0 eval "require $f_class";
637 0 ▶ return if($@ || !UNIVERSAL::isa($f_class, 'Rose::DB::Object'));
Branch: 1 branch
BranchTrueFalseTotal
if $@ or not UNIVERSAL::isa($f_class, "Rose::DB::Object") 0 0 0
Condition0%0/3
$@ or not UNIVERSAL::isa($f_class, "Rose::DB::Object")
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not UNIVERSAL::isa($f_class, "Rose::DB::Object")
$@ not UNIVERSAL::isa($f_class, "Rose::DB::Object")
Truth table0%0/3
A or not(B)
A= $@B= not UNIVERSAL::isa($f_class, "Rose::DB::Object")
ABresult
1X1
011
000
638 }
639 }
640  
641 #return unless(UNIVERSAL::isa($f_class, 'Rose::DB::Object'));
642  
643 3 $spec->{'class'} = $f_class;
644 }
645 elsif($rel_type =~ /^(?:one|many) to one$/)
646 {
647 6 my $class = $meta->class;
648  
649 # Get class suffix from relationship name
650 6 my $f_class = $self->related_table_to_class($name, $class);
651  
652 LOAD:
653 {
654 # Try to load class
655 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
656 6 ▶ unless(UNIVERSAL::isa($f_class, 'Rose::DB::Object'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($f_class, "Rose::DB::Object")) 0 6 6
657 {
658 0 local $@;
659 0 eval "require $f_class";
660 0 ▶ return if($@ || !UNIVERSAL::isa($f_class, 'Rose::DB::Object'));
Branch: 1 branch
BranchTrueFalseTotal
if $@ or not UNIVERSAL::isa($f_class, "Rose::DB::Object") 0 0 0
Condition0%0/3
$@ or not UNIVERSAL::isa($f_class, "Rose::DB::Object")
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not UNIVERSAL::isa($f_class, "Rose::DB::Object")
$@ not UNIVERSAL::isa($f_class, "Rose::DB::Object")
Truth table0%0/3
A or not(B)
A= $@B= not UNIVERSAL::isa($f_class, "Rose::DB::Object")
ABresult
1X1
011
000
661 }
662 }
663  
664 #return unless(UNIVERSAL::isa($f_class, 'Rose::DB::Object'));
665  
666 6 $spec->{'class'} = $f_class;
667 }
668 }
669  
670 # Make sure this class has its @ISA set up...
671 33 ▶ unless(UNIVERSAL::isa($spec->{'class'}, 'Rose::DB::Object'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($spec->{"class"}, "Rose::DB::Object")) 21 12 33
672 {
673 # ...but allow many-to-many relationships to pass because they tend to
674 # need more time before every piece of info is available.
675 21 ▶ return unless($rel_type eq 'many to many');
Branch: 1 branch
BranchTrueFalseTotal
unless $rel_type eq "many to many" 0 21 21
676 }
677  
678 33 ▶ if($rel_type eq 'one to one')
Branch: 4 branches
BranchTrueFalseTotal
if ($rel_type eq 'one to one') { } 4 29 33
elsif ($rel_type eq 'many to one') { } 4 25 29
elsif ($rel_type eq 'one to many') { } 4 21 25
elsif ($rel_type eq 'many to many') { } 21 0 21
679 {
680 4 return $self->auto_relationship_one_to_one($name, $rel_class, $spec);
681 }
682 elsif($rel_type eq 'many to one')
683 {
684 4 return $self->auto_relationship_many_to_one($name, $rel_class, $spec);
685 }
686 elsif($rel_type eq 'one to many')
687 {
688 4 return $self->auto_relationship_one_to_many($name, $rel_class, $spec);
689 }
690 elsif($rel_type eq 'many to many')
691 {
692 21 return $self->auto_relationship_many_to_many($name, $rel_class, $spec);
693 }
694  
695 0 return;
696 }
697  
698 sub auto_relationship_one_to_one
699 8 ▶{
Subroutine auto_relationship_one_to_one: called CC=9 SCAR=27.1
Pod undocumented
700 8 my($self, $name, $rel_class, $spec) = @_;
701  
702 8 ▶ $spec ||= {};
Condition50%1/2
$spec ||= {}
l!l
80
MC/DC0%0/1
$spec ||= {}
$spec
Truth table50%1/2
A
A= $spec
Aresult
11
00
703  
704 8 my $meta = $self->meta;
705  
706 8 ▶ unless(defined $spec->{'column_map'})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $spec->{"column_map"}) 6 2 8
707 {
708 6 my @fpk_columns = $spec->{'class'}->meta->primary_key_column_names;
709 6 ▶ return unless(@fpk_columns == 1);
Branch: 1 branch
BranchTrueFalseTotal
unless @fpk_columns == 1 0 6 6
710  
711 6 my $aliases = $meta->column_aliases;
712  
713 6 ▶ if($meta->column($name) && $aliases->{$name} && $aliases->{$name} ne $name)
Branch: 3 branches
BranchTrueFalseTotal
if ($meta->column($name) and $aliases->{$name} and $aliases->{$name} ne $name) { } 0 6 6
elsif ($meta->column("${name}_$fpk_columns[0]")) { } 6 0 6
elsif ($meta->column("${name}_id")) { } 0 0 0
Condition33%2/6
$meta->column($name) and $aliases->{$name} and $aliases->{$name} ne $name
!ll&&!rl&&r
600
$meta->column($name) and $aliases->{$name}
!ll&&!rl&&r
600
MC/DC0%0/3
$meta->column($name) and $aliases->{$name} and $aliases->{$name} ne $name
$meta->column($name) $aliases->{$name} $aliases->{$name} ne $name
Truth table25%1/4
A and B and C
A= $meta->column($name)B= $aliases->{$name}C= $aliases->{$name} ne $name
ABCresult
0XX0
10X0
1100
1111
714 {
715 0 $spec->{'column_map'} = { $name => $fpk_columns[0] };
716 }
717 elsif($meta->column("${name}_$fpk_columns[0]"))
718 {
719 6 $spec->{'column_map'} = { "${name}_$fpk_columns[0]" => $fpk_columns[0] };
720 }
721 elsif($meta->column("${name}_id"))
722 {
723 0 $spec->{'column_map'} = { "${name}_id" => $fpk_columns[0] };
724 }
725 0 else { return }
726 }
727  
728 8 return $rel_class->new(name => $name, %$spec);
729 }
730  
731 61 *auto_relationship_many_to_one = \&auto_relationship_one_to_one;
732  
733 sub auto_relationship_one_to_many
734 4 ▶{
Subroutine auto_relationship_one_to_many: called CC=7 SCAR=20.5
Pod undocumented
735 4 my($self, $name, $rel_class, $spec) = @_;
736  
737 4 ▶ $spec ||= {};
Condition50%1/2
$spec ||= {}
l!l
40
MC/DC0%0/1
$spec ||= {}
$spec
Truth table50%1/2
A
A= $spec
Aresult
11
00
738  
739 4 my $meta = $self->meta;
740 4 my $l_col_name = $self->class_to_table_singular;
741  
742 4 ▶ unless(defined $spec->{'column_map'})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $spec->{"column_map"}) 3 1 4
743 {
744 3 my @pk_columns = $meta->primary_key_column_names;
745 3 ▶ return unless(@pk_columns == 1);
Branch: 1 branch
BranchTrueFalseTotal
unless @pk_columns == 1 0 3 3
746  
747 3 my @fpk_columns = $meta->primary_key_column_names;
748 3 ▶ return unless(@fpk_columns == 1);
Branch: 1 branch
BranchTrueFalseTotal
unless @fpk_columns == 1 0 3 3
749  
750 3 my $f_meta = $spec->{'class'}->meta;
751  
752 3 my $aliases = $f_meta->column_aliases;
753  
754 3 ▶ if($f_meta->column($l_col_name))
Branch: 2 branches
BranchTrueFalseTotal
if ($f_meta->column($l_col_name)) { } 0 3 3
elsif ($f_meta->column("${l_col_name}_$pk_columns[0]")) { } 3 0 3
755 {
756 0 $spec->{'column_map'} = { $pk_columns[0] => $l_col_name };
757 }
758 elsif($f_meta->column("${l_col_name}_$pk_columns[0]"))
759 {
760 3 $spec->{'column_map'} = { $pk_columns[0] => "${l_col_name}_$pk_columns[0]" };
761 }
762 0 else { return }
763 }
764  
765 4 return $rel_class->new(name => $name, %$spec);
766 }
767  
768 sub auto_relationship_many_to_many
769 21 ▶{
Subroutine auto_relationship_many_to_many: called CC=9 SCAR=22.6
Pod undocumented
770 21 my($self, $name, $rel_class, $spec) = @_;
771  
772 21 ▶ $spec ||= {};
Condition50%1/2
$spec ||= {}
l!l
210
MC/DC0%0/1
$spec ||= {}
$spec
Truth table50%1/2
A
A= $spec
Aresult
11
00
773  
774 21 my $meta = $self->meta;
775  
776 21 ▶ unless($spec->{'map_class'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($spec->{"map_class"}) 12 9 21
777 {
778 12 my $class = $meta->class;
779  
780 # Given:
781 # Class: My::Object
782 # Rel name: other_objects
783 # Foreign class: My::OtherObject
784 #
785 # Consider map class names:
786 # My::ObjectsOtherObjectsMap
787 # My::ObjectOtherObjectMap
788 # My::OtherObjectsObjectsMap
789 # My::OtherObjectObjectMap
790 # My::ObjectsOtherObjects
791 # My::ObjectOtherObjects
792 # My::OtherObjectsObjects
793 # My::OtherObjectObjects
794 # My::OtherObjectMap
795 # My::OtherObjectsMap
796 # My::ObjectMap
797 # My::ObjectsMap
798  
799 12 my $prefix = $self->class_prefix($class);
800  
801 12 my @consider;
802  
803 12 my $f_class_suffix = $self->table_to_class($name);
804 12 my $f_class_suffix_pl = $self->table_to_class_plural($name);
805  
806 12 $class =~ /(\w+)$/;
807 12 my $class_suffix = $1;
808 12 my $class_suffix_pl = $self->singular_to_plural($class_suffix);
809  
810 12 push(@consider, map { "${prefix}$_" }
811 $class_suffix_pl . $f_class_suffix_pl . 'Map',
812 $class_suffix . $f_class_suffix . 'Map',
813  
814 $f_class_suffix_pl . $class_suffix_pl . 'Map',
815 $f_class_suffix . $class_suffix . 'Map',
816  
817 $class_suffix_pl . $f_class_suffix_pl,
818 $class_suffix . $f_class_suffix_pl,
819  
820 $f_class_suffix_pl . $class_suffix_pl,
821 $f_class_suffix . $class_suffix_pl,
822  
823 $f_class_suffix . 'Map',
824 $f_class_suffix_pl . 'Map',
825  
826 $class_suffix . 'Map',
827 $class_suffix_pl . 'Map');
828  
829 12 my $map_class;
830  
831 12 CLASS: foreach my $class (@consider)
832 {
833 LOAD:
834 {
835 # Try to load class
836 61 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
837 78 ▶ if(UNIVERSAL::isa($class, 'Rose::DB::Object'))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($class, 'Rose::DB::Object')) { } 12 66 78
838 {
839 12 $map_class = $class;
840 12 last CLASS;
841 }
842 else
843 {
844 66 local $@;
845 66 eval "require $class";
846  
847 66 ▶ unless($@)
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 66 66
848 {
849 0 $map_class = $class;
850 0 ▶ last CLASS if(UNIVERSAL::isa($class, 'Rose::DB::Object'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($class, "Rose::DB::Object") 0 0 0
851 }
852 }
853 }
854 }
855  
856 12 ▶ return unless($map_class && UNIVERSAL::isa($map_class, 'Rose::DB::Object'));
Branch: 1 branch
BranchTrueFalseTotal
unless $map_class and UNIVERSAL::isa($map_class, "Rose::DB::Object") 0 12 12
Condition33%1/3
$map_class and UNIVERSAL::isa($map_class, "Rose::DB::Object")
!ll&&!rl&&r
0012
MC/DC0%0/2
$map_class and UNIVERSAL::isa($map_class, "Rose::DB::Object")
$map_class UNIVERSAL::isa($map_class, "Rose::DB::Object")
Truth table33%1/3
A and B
A= $map_classB= UNIVERSAL::isa($map_class, "Rose::DB::Object")
ABresult
0X0
100
111
857  
858 12 $spec->{'map_class'} = $map_class;
859 }
860  
861 21 return $rel_class->new(name => $name, %$spec);
862 }
863  
864 61 1;
865  
866 __END__
« Object/Metadata/PrimaryKey.pm ↑ Summary Object/Metadata/Auto/Informix.pm »