Object/Metadata/Relationship.pm

filter: Statementstmt 32.6% 34 / 104 Branchbran 8.3% 5 / 60 Conditioncond 15.3% 2 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 52.6% 10 / 19 Podpod 20.0% 3 / 15 totaltotal 24.6% 54 / 219 CC 42 SCAR 49.3
CC
42
Cov
23%
perl_relationship_definition_attributes
342.0
perl_hash_definition
156.0
object_has_related_objects
30.0
CRAP 138.7
« Object/Metadata/Auto/SQLite.pm ↑ Summary Object/MakeMethods/Pg.pm »
1 package Rose::DB::Object::Metadata::Relationship;
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  
7 61 ▶use Rose::DB::Object::Metadata::Util qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 61 ▶use Rose::DB::Object::Metadata::MethodMaker;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 61 our @ISA = qw(Rose::DB::Object::Metadata::MethodMaker);
11  
12 61 our $VERSION = '0.780';
13  
14 61 __PACKAGE__->add_common_method_maker_argument_names
15 (
16 qw(relationship hash_key)
17 );
18  
19 61 Rose::Object::MakeMethods::Generic->make_methods
20 (
21 { preserve_existing => 1 },
22 scalar =>
23 [
24 'foreign_key',
25 'deferred_make_method_args',
26 id => { interface => 'get_set_init' },
27 __PACKAGE__->common_method_maker_argument_names,
28 ],
29 );
30  
31 0 ▶sub type { Carp::confess "Override in subclass" }
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
32  
33 0 ▶sub is_singular { Carp::confess "Override in subclass" }
Subroutine is_singular: not called CC=1 SCAR=6.9
Pod documented
34  
35 148 ▶sub relationship { $_[0] }
Subroutine relationship: called CC=1 SCAR=0.0
Pod documented
36  
37 8 ▶sub is_ready_to_make_methods { 1 }
Subroutine is_ready_to_make_methods: called CC=1 SCAR=0.0
Pod undocumented
38 0 ▶sub sanity_check { 1 }
Subroutine sanity_check: not called CC=1 SCAR=6.9
Pod undocumented
39  
40 61 my $Id_Counter = 0;
41  
42 14 ▶sub init_id { ++$Id_Counter }
Subroutine init_id: called CC=1 SCAR=0.0
Pod undocumented
43  
44 # Some object keys have different names when they appear
45 # in hashref-style relationship specs. This hash maps
46 # between the two in the case where they differ.
47 sub spec_hash_key_map
48 7 ▶{
Subroutine spec_hash_key_map: called CC=1 SCAR=0.0
Pod undocumented
49 {
50 # object key spec key
51 7 method_name => 'methods',
52 }
53 }
54  
55 sub spec_hash_method_map
56 7 ▶{
Subroutine spec_hash_method_map: called CC=1 SCAR=0.0
Pod undocumented
57 {
58 # object key object method
59 7 _share_db => 'share_db',
60 _key_columns => 'key_columns',
61 }
62 }
63  
64 # Return a hashref-style relationship spec
65 sub spec_hash
66 7 ▶{
Subroutine spec_hash: called CC=9 SCAR=25.1
Pod undocumented
67 7 my($self) = shift;
68  
69 7 ▶ my $key_map = $self->spec_hash_key_map || {};
Condition50%1/2
$self->spec_hash_key_map || {}
l!l
70
MC/DC0%0/1
$self->spec_hash_key_map || {}
$self->spec_hash_key_map
Truth table50%1/2
A
A= $self->spec_hash_key_map
Aresult
11
00
70 7 ▶ my $method_map = $self->spec_hash_method_map || {};
Condition50%1/2
$self->spec_hash_method_map || {}
l!l
70
MC/DC0%0/1
$self->spec_hash_method_map || {}
$self->spec_hash_method_map
Truth table50%1/2
A
A= $self->spec_hash_method_map
Aresult
11
00
71  
72 7 my %spec = (type => $self->type);
73  
74 7 foreach my $key (keys(%$self))
75 {
76 63 ▶ if(exists $key_map->{$key})
Branch: 2 branches
BranchTrueFalseTotal
if (exists $key_map->{$key}) { } 7 56 63
elsif (exists $method_map->{$key}) { } 0 56 56
77 {
78 7 ▶ my $spec_key = $key_map->{$key} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $spec_key = $key_map->{$key} or next 7 0 7
79 7 $spec{$spec_key} = $self->{$key};
80 }
81 elsif(exists $method_map->{$key})
82 {
83 0 ▶ my $method = $method_map->{$key} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $method = $method_map->{$key} or next 0 0 0
84 0 $spec{$method} = $self->$method();
85 }
86 else
87 {
88 56 $spec{$key} = $self->{$key};
89 }
90 }
91  
92 7 ▶ return wantarray ? %spec : \%spec;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 7 7
93 }
94  
95 61 our $DEFAULT_INLINE_LIMIT = 80;
96  
97 sub perl_hash_definition
98 0 ▶{
Subroutine perl_hash_definition: not called CC=12 SCAR=50.5
Pod undocumented
99 0 my($self, %args) = @_;
100  
101 0 my $meta = $self->parent;
102  
103 0 my $name_padding = $args{'name_padding'};
104  
105 0 my $braces = $args{'braces'};
106 0 ▶ my $indent = defined $args{'indent'} ? $args{'indent'} :
Branch: 2 branches
BranchTrueFalseTotal
defined $args{'indent'} ? : 0 0 0
$meta ? : 0 0 0
107 ($meta ? $meta->default_perl_indent : undef);
108  
109 0 ▶ my $inline = defined $args{'inline'} ? $args{'inline'} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'inline'} ? : 0 0 0
110 0 ▶ my $inline_limit = defined $args{'inline'} ? $args{'inline_limit'} : $DEFAULT_INLINE_LIMIT;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'inline'} ? : 0 0 0
111  
112 0 my %attrs = map { $_ => 1 } $self->perl_relationship_definition_attributes;
113 0 my %hash = $self->spec_hash;
114  
115 0 my @delete_keys = grep { !$attrs{$_} } keys %hash;
116 0 delete @hash{@delete_keys};
117  
118 0 ▶ $hash{'column_map'} = delete $hash{'key_columns'} if(exists $hash{'key_columns'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $hash{"key_columns"} 0 0 0
119  
120 0 my $max_len = 0;
121 0 my $min_len = -1;
122  
123 0 foreach my $name (keys %hash)
124 {
125 0 ▶ $max_len = length($name) if(length $name > $max_len);
Branch: 1 branch
BranchTrueFalseTotal
if length $name > $max_len 0 0 0
126 0 ▶ $min_len = length($name) if(length $name < $min_len || $min_len < 0);
Branch: 1 branch
BranchTrueFalseTotal
if length $name < $min_len or $min_len < 0 0 0 0
Condition0%0/3
length $name < $min_len or $min_len < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
length $name < $min_len or $min_len < 0
length $name < $min_len $min_len < 0
Truth table0%0/3
A or B
A= length $name < $min_lenB= $min_len < 0
ABresult
1X1
011
000
127 }
128  
129 0 ▶ if(defined $name_padding && $name_padding > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name_padding and $name_padding > 0) { } 0 0 0
Condition0%0/3
defined $name_padding and $name_padding > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name_padding and $name_padding > 0
defined $name_padding $name_padding > 0
Truth table0%0/3
A and B
A= defined $name_paddingB= $name_padding > 0
ABresult
0X0
100
111
130 {
131 0 return sprintf('%-*s => ', $name_padding, perl_quote_key($self->name)) .
132 perl_hashref(hash => \%hash,
133 braces => $braces,
134 inline => $inline,
135 inline_limit => $inline_limit,
136 indent => $indent,
137 key_padding => hash_key_padding(\%hash));
138 }
139 else
140 {
141 0 return perl_quote_key($self->name) . ' => ' .
142 perl_hashref(hash => \%hash,
143 braces => $braces,
144 inline => $inline,
145 inline_limit => $inline_limit,
146 indent => $indent,
147 key_padding => hash_key_padding(\%hash));
148 }
149 }
150  
151 sub perl_relationship_definition_attributes
152 0 ▶{
Subroutine perl_relationship_definition_attributes: not called CC=18 SCAR=58.3
Pod undocumented
153 0 my($self) = shift;
154  
155 0 my @attrs;
156  
157 0 ATTR: foreach my $attr ('type', sort keys %$self)
158 {
159 0 ▶ if($attr =~ /^(?: id | name | method_name | method_code | auto_method_types |
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ /^(?: id | name | method_name | method_code | auto_method_types | deferred_make_method_args | parent )$/x) 0 0 0
160 deferred_make_method_args | parent )$/x)
161 {
162 0 next ATTR;
163 }
164  
165 0 ▶ my $val = $self->can($attr) ? $self->$attr() : next ATTR;
Branch: 1 branch
BranchTrueFalseTotal
$self->can($attr) ? : 0 0 0
166  
167 0 ▶ if(!defined $val)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 0 0
168 {
169 0 next ATTR;
170 }
171  
172 0 ▶ next ATTR if($attr =~ /^_?share_db$/ && $self->share_db);
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^_?share_db$/ and $self->share_db 0 0 0
Condition0%0/3
$attr =~ /^_?share_db$/ and $self->share_db
!ll&&!rl&&r
000
MC/DC0%0/2
$attr =~ /^_?share_db$/ and $self->share_db
$attr =~ /^_?share_db$/ $self->share_db
Truth table0%0/3
A and B
A= $attr =~ /^_?share_db$/B= $self->share_db
ABresult
0X0
100
111
173  
174 0 ▶ if($attr =~ /^_(share_db|key_columns)$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($attr =~ /^_(share_db|key_columns)$/) { } 0 0 0
elsif ($attr eq 'method_name') { } 0 0 0
175 {
176 0 $attr = $1;
177 }
178 elsif($attr eq 'method_name')
179 {
180 0 ▶ my $names = $self->{$attr} or next ATTR;
Branch: 1 branch
BranchTrueFalseTotal
my $names = $self->{$attr} or next ATTR 0 0 0
181 0 my $custom = 0;
182  
183 0 ▶ while(my($type, $name) = each(%$names))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$names) 0 0 0
184 {
185 0 ▶ if($name ne $self->build_method_name_for_type($type))
Branch: 1 branch
BranchTrueFalseTotal
if ($name ne $self->build_method_name_for_type($type)) 0 0 0
186 {
187 0 $custom = 1;
188 0 last;
189 }
190 }
191  
192 0 ▶ unless($custom)
Branch: 1 branch
BranchTrueFalseTotal
unless ($custom) 0 0 0
193 {
194 0 my $def_types = $self->init_auto_method_types;
195  
196 0 TYPE: foreach my $def_type (@$def_types)
197 {
198 0 my $found = 0;
199  
200 0 foreach my $type ($self->auto_method_types)
201 {
202 0 ▶ if($type eq $def_type)
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $def_type) 0 0 0
203 {
204 0 $found++;
205 0 next TYPE;
206 }
207 }
208  
209 0 ▶ $custom = 1 if($found != @$def_types);
Branch: 1 branch
BranchTrueFalseTotal
if $found != @$def_types 0 0 0
210 }
211 }
212  
213 0 ▶ next ATTR unless($custom);
Branch: 1 branch
BranchTrueFalseTotal
unless $custom 0 0 0
214 }
215  
216 0 push(@attrs, $attr);
217 }
218  
219 0 return @attrs;
220 }
221  
222 sub object_has_related_objects
223 0 ▶{
Subroutine object_has_related_objects: not called CC=5 SCAR=34.0
Pod undocumented
224 0 my($self, $object) = @_;
225  
226 0 ▶ unless($object->isa($self->parent->class))
Branch: 1 branch
BranchTrueFalseTotal
unless ($object->isa($self->parent->class)) 0 0 0
227 {
228 0 my $class = $self->parent->class;
229 0 Carp::croak "Cannot check for items related through the ", $self->name,
230 " relationship. Object does not inherit from $class: $object";
231 }
232  
233 0 my $related_objects = $object->{$self->hash_key};
234 0 my $ref = ref $related_objects;
235  
236 0 ▶ if($ref eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if ($ref eq "ARRAY") 0 0 0
237 {
238 0 ▶ return @{$related_objects} ? $related_objects : 0;
Branch: 1 branch
BranchTrueFalseTotal
@{$related_objects;} ? : 0 0 0
239 }
240  
241 0 ▶ return $ref ? [ $related_objects ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$ref ? : 0 0 0
242 }
243  
244 0 ▶sub hash_keys_used { shift->hash_key }
Subroutine hash_keys_used: not called CC=1 SCAR=6.9
Pod undocumented
245  
246 sub forget_related_objects
247 0 ▶{
Subroutine forget_related_objects: not called CC=2 SCAR=17.9
Pod undocumented
248 0 my($self, $object) = @_;
249  
250 0 foreach my $key ($self->hash_keys_used)
251 {
252 0 $object->{$key} = undef;
253 }
254 }
255  
256 0 ▶sub requires_preexisting_parent_object { } # override in subclass
Subroutine requires_preexisting_parent_object: not called CC=1 SCAR=0.0
Pod undocumented
257  
258 61 1;
259  
260 __END__
« Object/Metadata/Auto/SQLite.pm ↑ Summary Object/MakeMethods/Pg.pm »