Object/Metadata/Relationship/ManyToMany.pm

filter: Statementstmt 78.7% 126 / 160 Branchbran 50.0% 48 / 96 Conditioncond 25.4% 14 / 55 MC/DCmcdc 10.3% 3 / 29 Subroutinesub 85.7% 18 / 21 Podpod 50.0% 4 / 8 totaltotal 57.7% 213 / 369 CC 70 SCAR 52.3
CC
70
Cov
60%
is_ready_to_make_methods
308.5
__ANON__
42.0
build_method_name_for_type
16.1
CRAP 186.5
« Object/Metadata/Util.pm ↑ Summary Object/Metadata/Auto/Pg.pm »
1 package Rose::DB::Object::Metadata::Relationship::ManyToMany;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Rose::DB::Object::Metadata::Relationship;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 our @ISA = qw(Rose::DB::Object::Metadata::Relationship);
10  
11 2 ▶use Rose::DB::Object::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Rose::Object::MakeMethods::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Rose::DB::Object::MakeMethods::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use Rose::DB::Object::Constants qw(PRIVATE_PREFIX);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 our $VERSION = '0.784';
18  
19 2 our $Debug = 0;
20  
21 2 __PACKAGE__->default_auto_method_types(qw(find get_set_on_save add_on_save));
22  
23 2 __PACKAGE__->add_common_method_maker_argument_names
24 (
25 qw(share_db map_class map_from map_to manager_class manager_method
26 manager_count_method manager_iterator_method manager_find_method
27 manager_args query_args map_record_method)
28 );
29  
30 use Rose::Object::MakeMethods::Generic
31 2 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 boolean =>
33 [
34 'share_db' => { default => 1 },
35 ],
36 2 );
37  
38 2 Rose::Object::MakeMethods::Generic->make_methods
39 (
40 { preserve_existing => 1 },
41 scalar =>
42 [
43 __PACKAGE__->common_method_maker_argument_names,
44 ],
45  
46 # These are set by the method maker when make_methods() is called
47  
48 scalar =>
49 [
50 'foreign_class', # class to be fetched
51 ],
52  
53 hash =>
54 [
55 # Map from map-table columns to self-table columns
56 'column_map',
57 ]
58 );
59  
60 2 __PACKAGE__->method_maker_info
61 (
62 count =>
63 {
64 class => 'Rose::DB::Object::MakeMethods::Generic',
65 type => 'objects_by_map',
66 interface => 'count',
67 },
68  
69 find =>
70 {
71 class => 'Rose::DB::Object::MakeMethods::Generic',
72 type => 'objects_by_map',
73 interface => 'find',
74 },
75  
76 iterator =>
77 {
78 class => 'Rose::DB::Object::MakeMethods::Generic',
79 type => 'objects_by_map',
80 interface => 'iterator',
81 },
82  
83 get_set =>
84 {
85 class => 'Rose::DB::Object::MakeMethods::Generic',
86 type => 'objects_by_map',
87 interface => 'get_set',
88 },
89  
90 get_set_now =>
91 {
92 class => 'Rose::DB::Object::MakeMethods::Generic',
93 type => 'objects_by_map',
94 interface => 'get_set_now',
95 },
96  
97 get_set_on_save =>
98 {
99 class => 'Rose::DB::Object::MakeMethods::Generic',
100 type => 'objects_by_map',
101 interface => 'get_set_on_save',
102 },
103  
104 add_now =>
105 {
106 class => 'Rose::DB::Object::MakeMethods::Generic',
107 type => 'objects_by_map',
108 interface => 'add_now',
109 },
110  
111 add_on_save =>
112 {
113 class => 'Rose::DB::Object::MakeMethods::Generic',
114 type => 'objects_by_map',
115 interface => 'add_on_save',
116 },
117 );
118  
119 49 ▶sub type { 'many to many' }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
120  
121 0 ▶sub is_singular { 0 }
Subroutine is_singular: not called CC=1 SCAR=6.9
Pod documented
122  
123 2 ▶use constant MAP_RECORD_ATTR => PRIVATE_PREFIX . '_map_record';
Subroutine BEGIN: called CC=1 SCAR=0.0
124 2 ▶use constant MAP_RECORD_METHOD => 'map_record';
Subroutine BEGIN: called CC=1 SCAR=0.0
125  
126 MAKE_MAP_RECORD_METHOD:
127 {
128 2 my $counter = 1;
129  
130 sub make_map_record_method
131 1 ▶ {
Subroutine make_map_record_method: called CC=1 SCAR=2.8
Pod undocumented
132 1 my($map_to_class, $map_record_method, $map_class) = @_;
133  
134 1 my $key = MAP_RECORD_ATTR . '_' . $counter++;
135  
136 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
137 1 *{"${map_to_class}::$map_record_method"} = sub
138 0 ▶ {
Subroutine __ANON__: not called CC=6 SCAR=37.4
139 0 my($self) = shift;
140  
141 0 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
142 {
143 0 my $arg = shift;
144 0 my $weaken = shift;
145  
146 0 ▶ if(ref $arg eq 'HASH')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $arg eq 'HASH') { } 0 0 0
elsif (not ref $arg && UNIVERSAL::isa($arg, $map_class)) { } 0 0 0
147 {
148 0 return $self->{$key} = $map_class->new(%$arg);
149 }
150 ▶ elsif(!ref $arg || !UNIVERSAL::isa($arg, $map_class))
Condition0%0/3
ref $arg && UNIVERSAL::isa($arg, $map_class)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $arg && UNIVERSAL::isa($arg, $map_class)
ref $arg UNIVERSAL::isa($arg, $map_class)
Truth table0%0/3
A && B
A= ref $argB= UNIVERSAL::isa($arg, $map_class)
ABresult
0X0
100
111
151 {
152 0 Carp::croak "Illegal map record argument: $arg";
153 }
154  
155 0 ▶ return $weaken ? (weaken($self->{$key} = $arg)) : ($self->{$key} = $arg);
Branch: 1 branch
BranchTrueFalseTotal
$weaken ? : 0 0 0
156 }
157  
158 0 return $self->{$key}; # ||= $map_class->new;
159 1 };
160  
161 1 $map_to_class->meta->map_record_method_key($map_record_method => $key);
162  
163 1 return $key;
164 }
165 }
166  
167 sub manager_args
168 2 ▶{
Subroutine manager_args: called CC=4 SCAR=14.0
Pod documented
169 65 my($self) = shift;
170  
171 65 ▶ return $self->{'manager_args'} unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 56 9 65
172  
173 9 my $args = $self->{'manager_args'} = shift;
174  
175 9 ▶ if(my $method = $args->{'with_map_records'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $args->{"with_map_records"}) 9 0 9
176 {
177 9 ▶ $method = MAP_RECORD_METHOD unless($method =~ /^[A-Za-z_]\w*$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $method =~ /^[A-Za-z_]\w*$/ 9 0 9
178  
179 9 $self->map_record_method($method);
180 }
181  
182 9 return $args;
183 }
184  
185 sub build_method_name_for_type
186 42 ▶{
Subroutine build_method_name_for_type: called CC=9 SCAR=27.8
Pod documented
187 42 my($self, $type) = @_;
188  
189 42 ▶ if($type eq 'get_set' || $type eq 'get_set_now' || $type eq 'get_set_on_save')
Branch: 5 branches
BranchTrueFalseTotal
if ($type eq 'get_set' or $type eq 'get_set_now' or $type eq 'get_set_on_save') { } 14 28 42
elsif ($type eq 'add_now' or $type eq 'add_on_save') { } 14 14 28
elsif ($type eq 'find') { } 14 0 14
elsif ($type eq 'iterator') { } 0 0 0
elsif ($type eq 'count') { } 0 0 0
Condition50%3/6
$type eq "get_set" or $type eq "get_set_now" or $type eq "get_set_on_save"
l!l&&r!l&&!r
01428
$type eq "get_set" or $type eq "get_set_now"
l!l&&r!l&&!r
0042
MC/DC33%1/3
$type eq "get_set" or $type eq "get_set_now" or $type eq "get_set_on_save"
$type eq "get_set" $type eq "get_set_now" $type eq "get_set_on_save"
Truth table50%2/4
A or B or C
A= $type eq "get_set"B= $type eq "get_set_now"C= $type eq "get_set_on_save"
ABCresult
1XX1
01X1
0011
0000
190 {
191 14 return $self->name;
192 }
193 ▶ elsif($type eq 'add_now' || $type eq 'add_on_save')
Condition66%2/3
$type eq "add_now" or $type eq "add_on_save"
l!l&&r!l&&!r
01414
MC/DC50%1/2
$type eq "add_now" or $type eq "add_on_save"
$type eq "add_now" $type eq "add_on_save"
Truth table66%2/3
A or B
A= $type eq "add_now"B= $type eq "add_on_save"
ABresult
1X1
011
000
194 {
195 14 return 'add_' . $self->name;
196 }
197 elsif($type eq 'find')
198 {
199 14 return 'find_' . $self->name;
200 }
201 elsif($type eq 'iterator')
202 {
203 0 return $self->name . '_iterator';
204 }
205 elsif($type eq 'count')
206 {
207 0 return $self->name . '_count';
208 }
209  
210 0 return undef;
211 }
212  
213 sub sanity_check
214 2 ▶{
Subroutine sanity_check: called CC=2 SCAR=7.1
Pod undocumented
215 2 my($self) = shift;
216  
217 2 ▶ defined $self->map_class or
Branch: 1 branch
BranchTrueFalseTotal
defined $self->map_class or Carp::croak($self->type, " relationship '", $self->name, "' is missing a map_class") 2 0 2
218 Carp::croak $self->type, " relationship '", $self->name,
219 "' is missing a map_class";
220  
221 2 return 1;
222 }
223 2 my $i;
224 my %C;
225  
226 sub is_ready_to_make_methods
227 21 ▶{
Subroutine is_ready_to_make_methods: called CC=53 SCAR=57.3
Pod undocumented
228 21 my($self) = shift;
229  
230 21 my $error;
231  
232 TRY:
233 {
234 21 local $@;
235  
236 # This code is (ug) duplicated from the method-maker itself, and
237 # slightly modified to run here. If the method-maker can't get all
238 # the info it needs, then we're not yet ready to make these methods.
239 eval
240 21 {
241 # Workaround for http://rt.perl.org/rt3/Ticket/Display.html?id=60890
242 21 local $SIG{'__DIE__'};
243  
244 21 ▶ my $map_class = $self->map_class or die "Missing map class";
Branch: 1 branch
BranchTrueFalseTotal
my $map_class = $self->map_class or die "Missing map class" 21 0 21
245  
246 21 ▶ unless(UNIVERSAL::isa($map_class, 'Rose::DB::Object'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($map_class, "Rose::DB::Object")) 0 21 21
247 {
248 0 die Rose::DB::Object::Exception::ClassNotReady->new(
249 "Map class $map_class not yet ready");
250 }
251  
252 21 ▶ my $map_meta = $map_class->meta or die
Branch: 1 branch
BranchTrueFalseTotal
my $map_meta = $map_class->meta or die "Rose::DB::Object::Exception::ClassNotReady"->new("Missing meta object for $map_class") 21 0 21
253 Rose::DB::Object::Exception::ClassNotReady->new(
254 "Missing meta object for $map_class");
255  
256 21 my $map_from = $self->map_from;
257 21 my $map_to = $self->map_to;
258 21 my $relationship = $self;
259  
260 21 my $target_class = $self->parent->class;
261 21 ▶ my $meta = $target_class->meta or die
Branch: 1 branch
BranchTrueFalseTotal
my $meta = $target_class->meta or die "Rose::DB::Object::Exception::ClassNotReady"->new("Missing meta object for $target_class") 21 0 21
262 Rose::DB::Object::Exception::ClassNotReady->new(
263 "Missing meta object for $target_class");
264  
265 21 my($map_to_class, $map_to_meta, $map_to_method);
266  
267 # "map" is the map table, "self" is the $target_class, and "remote"
268 # is the foreign object class
269 21 my(%map_column_to_self_method,
270 %map_column_to_self_column,
271 %map_method_to_remote_method);
272  
273 # Also grab the foreign object class that the mapper points to,
274 # the relationship name that points back to us, and the class
275 # name of the objects we really want to fetch.
276 21 my($require_objects, $local_rel, $foreign_class, %seen_fk);
277  
278 21 foreach my $item ($map_meta->foreign_keys, $map_meta->relationships)
279 {
280 # Track which foreign keys we've seen
281 56 ▶ if($item->isa('Rose::DB::Object::Metadata::ForeignKey'))
Branch: 2 branches
BranchTrueFalseTotal
if ($item->isa('Rose::DB::Object::Metadata::ForeignKey')) { } 28 28 56
elsif ($item->isa('Rose::DB::Object::Metadata::Relationship')) { } 28 0 28
282 {
283 28 $seen_fk{$item->id}++;
284 }
285 elsif($item->isa('Rose::DB::Object::Metadata::Relationship'))
286 {
287 # Skip a relationship if we've already seen the equivalent foreign key
288 28 ▶ next if($seen_fk{$item->id});
Branch: 1 branch
BranchTrueFalseTotal
if $seen_fk{$item->id} 28 0 28
289 }
290  
291 28 ▶ if($item->can('class') && $item->class eq $target_class)
Branch: 1 branch
BranchTrueFalseTotal
if ($item->can("class") and $item->class eq $target_class) 14 14 28
Condition66%2/3
$item->can("class") and $item->class eq $target_class
!ll&&!rl&&r
01414
MC/DC50%1/2
$item->can("class") and $item->class eq $target_class
$item->can("class") $item->class eq $target_class
Truth table66%2/3
A and B
A= $item->can("class")B= $item->class eq $target_class
ABresult
0X0
100
111
292 {
293 # Skip if there was an explicit local relationship name and
294 # this is not that name.
295 14 ▶ unless($map_from && $item->name ne $map_from)
Branch: 1 branch
BranchTrueFalseTotal
unless ($map_from and $item->name ne $map_from) 14 0 14
Condition33%1/3
$map_from and $item->name ne $map_from
!ll&&!rl&&r
1400
MC/DC0%0/2
$map_from and $item->name ne $map_from
$map_from $item->name ne $map_from
Truth table33%1/3
A and B
A= $map_fromB= $item->name ne $map_from
ABresult
0X0
100
111
296 {
297 14 ▶ if(%map_column_to_self_method)
Branch: 1 branch
BranchTrueFalseTotal
if (%map_column_to_self_method) 0 14 14
298 {
299 0 die Rose::DB::Object::Exception::ClassNotReady->new(
300 "Map class $map_class has more than one foreign key " .
301 "and/or 'many to one' relationship that points to the " .
302 "class $target_class. Please specify one by name " .
303 "with a 'local' parameter in the 'map' hash");
304 }
305  
306 14 $map_from = $local_rel = $item->name;
307  
308 14 ▶ my $map_columns =
Branch: 1 branch
BranchTrueFalseTotal
$item->can('column_map') ? : 14 0 14
309 $item->can('column_map') ? $item->column_map : $item->key_columns;
310  
311 # "local" and "foreign" here are relative to the *mapper* class
312 14 ▶ while(my($local_column, $foreign_column) = each(%$map_columns))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$map_columns) 14 14 28
313 {
314 14 ▶ my $foreign_method = $meta->column_accessor_method_name($foreign_column)
Branch: 1 branch
BranchTrueFalseTotal
my $foreign_method = $meta->column_accessor_method_name($foreign_column) or die "Rose::DB::Object::Exception::ClassNotReady"->new("Missing accessor method for column '${foreign_column}'" . ' in class ' . $meta->class) 14 0 14
315 or die Rose::DB::Object::Exception::ClassNotReady->new(
316 "Missing accessor method for column '$foreign_column'" .
317 " in class " . $meta->class);
318 14 $map_column_to_self_method{$local_column} = $foreign_method;
319 14 $map_column_to_self_column{$local_column} = $foreign_column;
320 }
321  
322 14 next;
323 }
324 }
325  
326 14 ▶ if($item->isa('Rose::DB::Object::Metadata::ForeignKey') ||
Branch: 1 branch
BranchTrueFalseTotal
if ($item->isa("Rose::DB::Object::Metadata::ForeignKey") or $item->type eq "many to one") 14 0 14
Condition33%1/3
$item->isa("Rose::DB::Object::Metadata::ForeignKey") or $item->type eq "many to one"
l!l&&r!l&&!r
1400
MC/DC0%0/2
$item->isa("Rose::DB::Object::Metadata::ForeignKey") or $item->type eq "many to one"
$item->isa("Rose::DB::Object::Metadata::ForeignKey") $item->type eq "many to one"
Truth table33%1/3
A or B
A= $item->isa("Rose::DB::Object::Metadata::ForeignKey")B= $item->type eq "many to one"
ABresult
1X1
011
000
327 $item->type eq 'many to one')
328 {
329 # Skip if there was an explicit foreign relationship name and
330 # this is not that name.
331 14 ▶ next if($map_to && $item->name ne $map_to);
Branch: 1 branch
BranchTrueFalseTotal
if $map_to and $item->name ne $map_to 0 14 14
Condition33%1/3
$map_to and $item->name ne $map_to
!ll&&!rl&&r
1400
MC/DC0%0/2
$map_to and $item->name ne $map_to
$map_to $item->name ne $map_to
Truth table33%1/3
A and B
A= $map_toB= $item->name ne $map_to
ABresult
0X0
100
111
332  
333 14 $map_to = $item->name;
334  
335 14 ▶ if($require_objects)
Branch: 1 branch
BranchTrueFalseTotal
if ($require_objects) 0 14 14
336 {
337 0 die Rose::DB::Object::Exception::ClassNotReady->new(
338 "Map class $map_class has more than one foreign key " .
339 "and/or 'many to one' relationship that points to a " .
340 "class other than $target_class. Please specify one " .
341 "by name with a 'foreign' parameter in the 'map' hash");
342 }
343  
344 14 $map_to_class = $item->class;
345  
346 14 ▶ unless(UNIVERSAL::isa($map_to_class, 'Rose::DB::Object'))
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($map_to_class, "Rose::DB::Object")) 0 14 14
347 {
348 0 die Rose::DB::Object::Exception::ClassNotReady->new(
349 "Map-to-class $map_to_class not yet ready");
350 }
351  
352 14 ▶ $map_to_meta = $map_to_class->meta or die
Branch: 1 branch
BranchTrueFalseTotal
$map_to_meta = $map_to_class->meta or die "Rose::DB::Object::Exception::ClassNotReady"->new("Missing meta object for $map_to_class") 14 0 14
353 Rose::DB::Object::Exception::ClassNotReady->new(
354 "Missing meta object for $map_to_class");
355  
356 14 ▶ my $map_columns =
Branch: 1 branch
BranchTrueFalseTotal
$item->can('column_map') ? : 14 0 14
357 $item->can('column_map') ? $item->column_map : $item->key_columns;
358  
359 # "local" and "foreign" here are relative to the *mapper* class
360 14 ▶ while(my($local_column, $foreign_column) = each(%$map_columns))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$map_columns) 14 14 28
361 {
362 14 ▶ my $local_method = $map_meta->column_accessor_method_name($local_column)
Branch: 1 branch
BranchTrueFalseTotal
my $local_method = $map_meta->column_accessor_method_name($local_column) or die "Rose::DB::Object::Exception::ClassNotReady"->new("Missing accessor method for column '${local_column}'" . ' in class ' . $map_meta->class) 14 0 14
363 or die Rose::DB::Object::Exception::ClassNotReady->new(
364 "Missing accessor method for column '$local_column'" .
365 " in class " . $map_meta->class);
366  
367 14 ▶ my $foreign_method = $map_to_meta->column_accessor_method_name($foreign_column)
Branch: 1 branch
BranchTrueFalseTotal
my $foreign_method = $map_to_meta->column_accessor_method_name($foreign_column) or die "Rose::DB::Object::Exception::ClassNotReady"->new("Missing accessor method for column '${foreign_column}'" . ' in class ' . $map_to_meta->class) 14 0 14
368 or die Rose::DB::Object::Exception::ClassNotReady->new(
369 "Missing accessor method for column '$foreign_column'" .
370 " in class " . $map_to_meta->class);
371  
372 # local foreign
373 # Map:color_id => Color:id
374 14 $map_method_to_remote_method{$local_method} = $foreign_method;
375 }
376  
377 14 $require_objects = [ $item->name ];
378 14 $foreign_class = $item->class;
379  
380 14 ▶ $map_to_method = $item->method_name('get_set') ||
Condition37%3/8
$item->method_name('get_set') || $item->method_name('get_set_now') || $item->method_name('get_set_on_save') || die('Rose::DB::Object::Exception::ClassNotReady'->new(q[No 'get_*' method found for ] . $item->name))
l!l
140
$item->method_name("get_set") or $item->method_name("get_set_now") or $item->method_name("get_set_on_save")
l!l&&r!l&&!r
0140
$item->method_name("get_set") or $item->method_name("get_set_now")
l!l&&r!l&&!r
0014
MC/DC0%0/3
$item->method_name('get_set') || $item->method_name('get_set_now') || $item->method_name('get_set_on_save') || die('Rose::DB::Object::Exception::ClassNotReady'->new(q[No 'get_*' method found for ] . $item->name))
$item->method_name("get_set") $item->method_name("get_set_now") $item->method_name("get_set_on_save")
Truth table25%1/4
A or B or C
A= $item->method_name("get_set")B= $item->method_name("get_set_now")C= $item->method_name("get_set_on_save")
ABCresult
1XX1
01X1
0011
0000
381 $item->method_name('get_set_now') ||
382 $item->method_name('get_set_on_save') ||
383 die Rose::DB::Object::Exception::ClassNotReady->new(
384 "No 'get_*' method found for " . $item->name);
385 }
386 }
387  
388 21 ▶ unless(%map_column_to_self_method)
Branch: 1 branch
BranchTrueFalseTotal
unless (%map_column_to_self_method) 7 14 21
389 {
390 7 die Rose::DB::Object::Exception::ClassNotReady->new(
391 "Could not find a foreign key or 'many to one' relationship " .
392 "in $map_class that points to $target_class");
393 }
394  
395 14 ▶ unless(%map_column_to_self_column)
Branch: 1 branch
BranchTrueFalseTotal
unless (%map_column_to_self_column) 0 14 14
396 {
397 0 ▶ die Rose::DB::Object::Exception::ClassNotReady->new(
Condition0%0/3
$map_to_class || $map_to
l!l&&r!l&&!r
000
MC/DC0%0/2
$map_to_class || $map_to
$map_to_class $map_to
Truth table0%0/3
A || B
A= $map_to_classB= $map_to
ABresult
1X1
011
000
398 "Could not find a foreign key or 'many to one' relationship " .
399 "in $map_class that points to " . ($map_to_class || $map_to));
400 }
401  
402 14 ▶ unless($require_objects)
Branch: 1 branch
BranchTrueFalseTotal
unless ($require_objects) 0 14 14
403 {
404 # Make a second attempt to find a suitable foreign relationship in the
405 # map class, this time looking for links back to $target_class so long as
406 # it's a different relationship than the one used in the local link.
407 0 foreach my $item ($map_meta->foreign_keys, $map_meta->relationships)
408 {
409 # Skip a relationship if we've already seen the equivalent foreign key
410 0 ▶ if($item->isa('Rose::DB::Object::Metadata::Relationship'))
Branch: 1 branch
BranchTrueFalseTotal
if ($item->isa("Rose::DB::Object::Metadata::Relationship")) 0 0 0
411 {
412 0 ▶ next if($seen_fk{$item->id});
Branch: 1 branch
BranchTrueFalseTotal
if $seen_fk{$item->id} 0 0 0
413 }
414  
415 0 ▶ if(($item->isa('Rose::DB::Object::Metadata::ForeignKey') ||
Branch: 1 branch
BranchTrueFalseTotal
if ($item->isa("Rose::DB::Object::Metadata::ForeignKey") || $item->type eq "many to one" and $item->class eq $target_class and $item->name ne $local_rel) 0 0 0
Condition0%0/9
$item->isa("Rose::DB::Object::Metadata::ForeignKey") || $item->type eq "many to one" and $item->class eq $target_class and $item->name ne $local_rel
!ll&&!rl&&r
000
$item->isa("Rose::DB::Object::Metadata::ForeignKey") || $item->type eq "many to one" and $item->class eq $target_class
!ll&&!rl&&r
000
$item->isa("Rose::DB::Object::Metadata::ForeignKey") or $item->type eq "many to one"
l!l&&r!l&&!r
000
MC/DC0%0/4
$item->isa("Rose::DB::Object::Metadata::ForeignKey") || $item->type eq "many to one" and $item->class eq $target_class and $item->name ne $local_rel
$item->isa("Rose::DB::Object::Metadata::ForeignKey") $item->type eq "many to one" $item->class eq $target_class $item->name ne $local_rel
Truth table0%0/7
A or B and C and D
A= $item->isa("Rose::DB::Object::Metadata::ForeignKey")B= $item->type eq "many to one"C= $item->class eq $target_classD= $item->name ne $local_rel
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
416 $item->type eq 'many to one') &&
417 $item->class eq $target_class && $item->name ne $local_rel)
418 {
419 0 ▶ if($require_objects)
Branch: 1 branch
BranchTrueFalseTotal
if ($require_objects) 0 0 0
420 {
421 0 die Rose::DB::Object::Exception::ClassNotReady->new(
422 "Map class $map_class has more than two foreign keys " .
423 "and/or 'many to one' relationships that points to a " .
424 "$target_class. Please specify which ones to use " .
425 "by including 'local' and 'foreign' parameters in the " .
426 "'map' hash");
427 }
428  
429 0 $require_objects = [ $item->name ];
430 0 $foreign_class = $item->class;
431 0 ▶ $map_to_method = $item->method_name('get_set') ||
Condition0%0/8
$item->method_name('get_set') || $item->method_name('get_set_now') || $item->method_name('get_set_on_save') || die('Rose::DB::Object::Exception::ClassNotReady'->new(q[No 'get_*' method found for ] . $item->name))
l!l
00
$item->method_name("get_set") or $item->method_name("get_set_now") or $item->method_name("get_set_on_save")
l!l&&r!l&&!r
000
$item->method_name("get_set") or $item->method_name("get_set_now")
l!l&&r!l&&!r
000
MC/DC0%0/3
$item->method_name('get_set') || $item->method_name('get_set_now') || $item->method_name('get_set_on_save') || die('Rose::DB::Object::Exception::ClassNotReady'->new(q[No 'get_*' method found for ] . $item->name))
$item->method_name("get_set") $item->method_name("get_set_now") $item->method_name("get_set_on_save")
Truth table0%0/4
A or B or C
A= $item->method_name("get_set")B= $item->method_name("get_set_now")C= $item->method_name("get_set_on_save")
ABCresult
1XX1
01X1
0011
0000
432 $item->method_name('get_set_now') ||
433 $item->method_name('get_set_on_save') ||
434 die Rose::DB::Object::Exception::ClassNotReady->new(
435 "No 'get_*' method found for " . $item->name);
436 }
437 }
438 }
439  
440 14 ▶ unless($require_objects)
Branch: 1 branch
BranchTrueFalseTotal
unless ($require_objects) 0 14 14
441 {
442 0 die Rose::DB::Object::Exception::ClassNotReady->new(
443 "Could not find a foreign key or 'many to one' relationship " .
444 "in $map_class that points to a class other than $target_class");
445 }
446  
447 14 ▶ unless($foreign_class)
Branch: 1 branch
BranchTrueFalseTotal
unless ($foreign_class) 0 14 14
448 {
449 0 die Rose::DB::Object::Exception::ClassNotReady->new("Missing foreign class");
450 }
451 };
452  
453 21 $error = $@;
454 }
455  
456 21 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 7 14 21
457 {
458 7 ▶ if($Debug || $Rose::DB::Object::Metadata::Debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($Rose::DB::Object::Metadata::Relationship::ManyToMany::Debug or $Rose::DB::Object::Metadata::Debug) 0 7 7
Condition33%1/3
$Rose::DB::Object::Metadata::Relationship::ManyToMany::Debug or $Rose::DB::Object::Metadata::Debug
l!l&&r!l&&!r
007
MC/DC0%0/2
$Rose::DB::Object::Metadata::Relationship::ManyToMany::Debug or $Rose::DB::Object::Metadata::Debug
$Rose::DB::Object::Metadata::Relationship::ManyToMany::Debug $Rose::DB::Object::Metadata::Debug
Truth table33%1/3
A or B
A= $Rose::DB::Object::Metadata::Relationship::ManyToMany::DebugB= $Rose::DB::Object::Metadata::Debug
ABresult
1X1
011
000
459 {
460 0 my $err = $error;
461 0 $err =~ s/ at .*//;
462 0 warn $self->parent->class, ': many-to-many relationship ', $self->name, " NOT READY - $err";
463 }
464  
465 7 ▶ die $error unless(UNIVERSAL::isa($error, 'Rose::DB::Object::Exception::ClassNotReady'));
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($error, "Rose::DB::Object::Exception::ClassNotReady") 0 7 7
466 }
467  
468 21 ▶ return $error ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$error ? : 7 14 21
469 }
470  
471 sub perl_relationship_definition_attributes
472 0 ▶{
Subroutine perl_relationship_definition_attributes: not called CC=1 SCAR=6.9
Pod undocumented
473 0 grep { $_ !~ /^(?:column_map|foreign_class)$/ }
474 shift->SUPER::perl_relationship_definition_attributes(@_);
475 }
476  
477 2 1;
478  
479 __END__
« Object/Metadata/Util.pm ↑ Summary Object/Metadata/Auto/Pg.pm »