EntityModel/Support/Perl.pm

filter: Statementstmt 18.6% 51 / 273 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 37.2% 16 / 43 Podpod 80.0% 12 / 15 totaltotal 18.8% 79 / 419 CC 43 SCAR 32.2
CC
43
Cov
14%
__ANON__
90.0
load_package
60.4
apply_entity
42.0
CRAP 24.9
« EntityModel/Support/Perl/Base.pm ↑ Summary EntityModel/Storage/Perl.pm »
1 package EntityModel::Support::Perl;
2 {
3 1 $EntityModel::Support::Perl::VERSION = '0.102';
4 }
5 1 ▶use EntityModel::Class {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 _isa => [qw{EntityModel::Support}],
7 namespace => { type => 'string' },
8 baseclass => { type => 'string' },
9 model => { type => 'EntityModel::Model' },
10 1 };
11 1 ▶no if $] >= 5.017011, warnings => "experimental::smartmatch";
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 EntityModel::Support::Perl - language support for L<EntityModel>
16  
17 =head1 VERSION
18  
19 version 0.102
20  
21 =head1 SYNOPSIS
22  
23 See L<EntityModel>.
24  
25 =head1 DESCRIPTION
26  
27 Generate Perl packages and methods based on an entity model definition.
28 See L<EntityModel>.
29  
30 =head1 ASYNCHRONOUS MODE
31  
32 See L<EntityModel::Support::PerlAsync>.
33  
34 =head1 METHODS
35  
36 =cut
37  
38 1 ▶use Symbol ();
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use Module::Load ();
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 =head2 setup
44  
45 =cut
46  
47 0 ▶sub setup {
Subroutine setup: not called CC=3 SCAR=24.8
Pod documented
48 0 my $self = shift;
49 0 my $def = shift;
50 0 logDebug("Trying [%s] with [%s]", $self, $def);
51 0 ▶ $self->namespace(exists $def->{namespace} ? delete $def->{namespace} : 'Entity');
Branch: 1 branch
BranchTrueFalseTotal
exists $def->{'namespace'} ? : 0 0 0
52 0 ▶ $self->baseclass(exists $def->{baseclass} ? delete $def->{baseclass} : 'EntityModel::Support::Perl::Base');
Branch: 1 branch
BranchTrueFalseTotal
exists $def->{'baseclass'} ? : 0 0 0
53  
54 0 $self->ensure_loaded($self->baseclass);
55 0 return $self;
56 }
57  
58 0 ▶sub apply_model {
Subroutine apply_model: not called CC=1 SCAR=6.9
Pod documented
59 0 my $self = shift;
60 0 my $model = shift;
61 0 $self->model($model);
62 # FIXME Need a better way to link storage instances to entities.
63 0 return $self->SUPER::apply_model($model);
64 }
65  
66 =head2 apply_entity
67  
68 =cut
69  
70 0 ▶sub apply_entity {
Subroutine apply_entity: not called CC=6 SCAR=37.4
Pod documented
71 0 my $self = shift;
72 0 my $entity = shift;
73  
74 0 logDebug("Create table " . $entity->name);
75 0 $self->load_package($self->package_name($entity) => $entity);
76 0 $self->create_field($entity, $_) foreach $entity->field->list;
77  
78 # With 3 references, we currently don't really know what to do, so bail out for now
79 0 my @ref = grep { $_->refer } $entity->field->list;
80 0 ▶ die qq{Too many references to handle\nThis module currently only handles 1:1, 1:N and N:M,\nso an entity with more than 3 external references\nneeds to have the relationships specified explicitly.} if @ref > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @ref > 2 0 0 0
81  
82 # Create a back collection for each reference
83 0 foreach my $ref (@ref) {
84 0 my $r = $ref->refer->entity;
85 0 ▶ my $f = $r->field_map->{$ref->refer->field} or die "no field found";
Branch: 1 branch
BranchTrueFalseTotal
my $f = $r->field_map->{$ref->refer->field} or die "no field found" 0 0 0
86 0 $self->back_link(
87 src => {
88 entity => $r,
89 field => $f
90 },
91 dst => {
92 entity => $entity,
93 field => $ref
94 }
95 );
96 }
97  
98 # 2 references usually means we have an N:M relationship, so create 2-way collections
99 0 ▶ if(@ref == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ref == 2) 0 0 0
100 my $src = {
101 entity => $ref[0]->refer->entity,
102 0 field => $ref[0]->refer->entity->field_map->{$ref[0]->refer->field},
103 };
104 my $dst = {
105 entity => $ref[1]->refer->entity,
106 0 field => $ref[1]->refer->entity->field_map->{$ref[1]->refer->field},
107 };
108 0 $self->cross_link(join_table => $entity, src => $src, dst => $dst);
109 0 $self->cross_link(join_table => $entity, src => $dst, dst => $src);
110 }
111  
112 0 return $self;
113 }
114  
115 0 ▶sub back_link {
Subroutine back_link: not called CC=3 SCAR=21.9
Pod undocumented
116 0 my $self = shift;
117 0 my %args = @_;
118  
119 # Need to make method on the source entity which does a ->find on the destination
120 0 my $pkg = $self->package_name($args{src}->{entity});
121 0 my $method = $args{dst}->{entity}->name;
122 0 my $target = $self->package_name($args{dst}->{entity});
123 0 my $search_field = $args{dst}->{field}->name;
124 0 ▶ my $code = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
125 0 my $self = shift;
126 0 EntityModel::Array->new([ $target->find({ $search_field => $self->id }) ]);
127 0 };
128 0 my $sym = join('::', $pkg, $method);
129 0 my $exists = eval { $pkg->can($sym) };
130 0 ▶ { no strict 'refs'; *$sym = $code unless $exists; }
Subroutine BEGIN: called CC=1 SCAR=1.7
Branch: 1 branch
BranchTrueFalseTotal
unless $exists 0 0 0
131 0 ▶ logDebug("Created [%s] for [%s] as a back link, previous [%s]", $sym, $pkg, $exists // 'not found');
Condition0%0/2
$exists // "not found"
l!l
00
MC/DC0%0/1
$exists // "not found"
$exists
Truth table0%0/2
A
A= $exists
Aresult
11
00
132 0 return $self;
133 }
134  
135 0 ▶sub cross_link {
Subroutine cross_link: not called CC=2 SCAR=15.2
Pod undocumented
136 0 my $self = shift;
137 0 my %args = @_;
138  
139 # Need to make method on the source entity which does a ->find on the destination
140 0 my $pkg = $self->package_name($args{src}->{entity});
141 0 my $method = $args{dst}->{entity}->name;
142 0 my $target = $self->package_name($args{dst}->{entity});
143 0 my $search_field = $args{src}->{field}->name;
144 0 my $pri = $args{dst}->{field}->name;
145 0 my $join = $self->package_name($args{join_table});
146 0 ▶ my $code = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
147 0 my $self = shift;
148 EntityModel::Array->new([
149 0 map { $target->new($_->$pri) } $join->find({ $search_field => $self->id })
150 ]);
151 0 };
152 0 my $sym = join('::', $pkg, $method);
153 0 ▶ { no strict 'refs'; *$sym = $code unless eval { $pkg->can($sym) }; }
Subroutine BEGIN: called CC=1 SCAR=2.2
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $pkg->can($sym) } } 0 0 0
154 0 return $self;
155 }
156  
157 =head2 ensure_loaded
158  
159 =cut
160  
161 0 ▶sub ensure_loaded {
Subroutine ensure_loaded: not called CC=2 SCAR=17.9
Pod documented
162 0 my $self = shift;
163 0 my $class = shift;
164 0 ▶ Module::Load::load($class) unless eval { $class->can('new') };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $class->can("new") } } 0 0 0
165 0 return $self;
166 }
167  
168 =head2 package_name
169  
170 Generate the package name string from the given entity.
171  
172 =cut
173  
174 0 ▶sub package_name {
Subroutine package_name: not called CC=4 SCAR=30.0
Pod documented
175 0 my ($self, $entity) = @_;
176 0 ▶ logStack("No entity?") unless $entity; # don't think this should ever happen but if it's really a fault other stuff will break anyway!
Branch: 1 branch
BranchTrueFalseTotal
unless $entity 0 0 0
177 0 ▶ my $name = ref($entity) ? $entity->name : $entity;
Branch: 1 branch
BranchTrueFalseTotal
ref $entity ? : 0 0 0
178  
179 0 logDebug("Get package name for [%s] with namespace [%s]", $name, $self->namespace);
180 0 ▶ return $self->namespace unless $entity;
Branch: 1 branch
BranchTrueFalseTotal
unless $entity 0 0 0
181  
182 return join('::', $self->namespace, map {
183 0 ucfirst($_)
184 } split('_', $name));
185 }
186  
187 =head2 entity_name
188  
189 Generate the entity name string from the given package name.
190  
191 =cut
192  
193 0 ▶sub entity_name {
Subroutine entity_name: not called CC=1 SCAR=6.9
Pod documented
194 0 my ($self, $pkg) = @_;
195 0 $pkg =~ s/^\Q$self->namespace\E:://;
196  
197 return join('_', map {
198 0 lc($_)
199 } split(/::/, $pkg));
200 }
201  
202 =head2 create_field
203  
204 Create new field for the given entity.
205  
206 =cut
207  
208 0 ▶sub create_field {
Subroutine create_field: not called CC=1 SCAR=2.9
Pod documented
209 0 my ($self, $entity, $field) = @_;
210  
211 0 my $pkg = $self->package_name($entity);
212 0 my $k = join('::', $pkg, $field->name);
213 0 logDebug("Create accessor [%s] on [%s]", $field->name, $pkg);
214  
215 0 given($field) {
216 0 when($_->type eq 'timestamp') {
217 # Timestamp has some formatting / validation additions
218 0 my $accessor = $self->accessor('timestamp', $entity, $field);
219 0 ▶ { no strict 'refs'; *{$k} = $accessor; }
Subroutine BEGIN: called CC=1 SCAR=1.2
220 }
221 0 when($_->refer) {
222 # Regular ID column access
223 0 my $accessor = $self->accessor('default', $entity, $field);
224 0 ▶ { no strict 'refs'; *{$k} = $accessor; }
Subroutine BEGIN: called CC=1 SCAR=1.2
225  
226 # And also provide an accessor which instantiates the object, with the id prefix removed from the fieldname
227 0 $accessor = $self->accessor('ref', $entity, $field);
228 0 $k =~ s/::\Kid([^:]+)$/$1/;
229 0 ▶ { no strict 'refs'; *{$k} = $accessor; }
Subroutine BEGIN: called CC=1 SCAR=1.2
230 0 logDebug("Accessor for %s on %s hits %s", $k, $entity->name, $field->name);
231 }
232 0 default {
233 0 my $accessor = $self->accessor('default', $entity, $field);
234 0 ▶ { no strict 'refs'; *{$k} = $accessor; }
Subroutine BEGIN: called CC=1 SCAR=1.2
235 }
236 }
237  
238 0 return $self;
239 }
240  
241 =head2 recurse_packages
242  
243 EntityModel::ObjectBase::Test -> test
244 EntityModel::ObjectBase::Test::One -> test_one
245 EntityModel::ObjectBase::Test::Two -> test_two
246  
247 =cut
248  
249 0 ▶sub recurse_packages {
Subroutine recurse_packages: not called CC=5 SCAR=30.5
Pod documented
250 0 my ($self, $prefix, $sub) = @_;
251 0 my $pkg = $self->package_name($prefix);
252  
253 0 my @pkgKeys;
254 0 ▶ { no strict 'refs'; @pkgKeys = keys %{$pkg . '::'}; }
Subroutine BEGIN: called CC=1 SCAR=1.2
255  
256 0 logInfo("Recurse for [%s]", $prefix);
257 0 foreach my $k (@pkgKeys) {
258 0 logInfo("Got [%s]", $k);
259 0 ▶ if($k =~ /^(.*)::$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^(.*)::$/) 0 0 0
260 0 ▶ my $tbl = $self->entity_name($prefix ? $prefix . '_' . $1 : $1);
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 0 0
261 0 ▶ $sub->($tbl) if $tbl;
Branch: 1 branch
BranchTrueFalseTotal
if $tbl 0 0 0
262 0 $self->recurse_packages($tbl, $sub);
263 }
264 }
265 }
266  
267 =head2 load_package
268  
269 =cut
270  
271 0 ▶sub load_package {
Subroutine load_package: not called CC=9 SCAR=41.0
Pod documented
272 0 my $self = shift;
273 0 my $pkg = shift;
274 0 my $entity = shift;
275  
276 0 my @primaryKeys = 'id';
277 0 my $entity_name = $entity->name;
278 0 logInfo("Load package for [%s]", $pkg);
279  
280 0 my ($storage) = $self->model->storage->list;
281 0 ▶ die "no storage?" unless $storage;
Branch: 1 branch
BranchTrueFalseTotal
unless $storage 0 0 0
282  
283 try {
284 0 local $SIG{__DIE__};
285 0 Module::Load::load($pkg);
286  
287 0 ▶ unless(eval { $pkg->isa($self->baseclass); }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $pkg->isa($self->baseclass) } }) 0 0 0
288 # Doesn't inherit as expected, add the base module anyway
289 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
290 0 push @{$pkg . '::ISA'}, $self->baseclass;
291 }
292 0 } catch {
293 0 ▶ logWarning("Failed: [%s]", $_) unless /^Can't locate /;
Branch: 1 branch
BranchTrueFalseTotal
unless /^Can't locate / 0 0 0
294  
295 # Couldn't read the module - either invalid, or missing. Create it.
296 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
297 0 push @{$pkg . '::ISA'}, $self->baseclass;
298 };
299  
300 {
301 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
302 0 ▶ *{$pkg . '::()'} = sub () { } unless *{ $pkg . '::()' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless *{$pkg . '::()';} 0 0 0
303  
304 # Apply default string representation
305 0 ▶ *{ $pkg . '::(""' } = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
306 0 my $self = shift;
307 0 ref($self) . '(' . $self->id . ')';
308 0 ▶ } unless *{ $pkg . '::(""' };
Branch: 1 branch
BranchTrueFalseTotal
unless *{$pkg . '::(""';} 0 0 0
309  
310 # List of primary keys
311 0 ▶ *{ $pkg . '::_primary' } = sub () { @primaryKeys; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
312 0 ▶ unless eval { $pkg->can('_primary') };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $pkg->can("_primary") } } 0 0 0
313 # Table
314 0 ▶ *{ $pkg . '::_entity' } = sub () { $entity; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
315 0 ▶ unless eval { $pkg->can('_entity') };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $pkg->can("_entity") } } 0 0 0
316  
317 0 ▶ *{ $pkg . '::_storage' } = sub () { $storage; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
318 0 ▶ unless eval { $pkg->can('_storage') };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $pkg->can("_storage") } } 0 0 0
319 }
320 }
321  
322 0 ▶sub accessor {
Subroutine accessor: not called CC=3 SCAR=24.8
Pod undocumented
323 0 my $self = shift;
324 0 my $type = shift;
325 0 ▶ return $self->timestamp_accessor(@_) if $type eq 'timestamp';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "timestamp" 0 0 0
326 0 ▶ return $self->ref_accessor(@_) if $type eq 'ref';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "ref" 0 0 0
327 0 return $self->default_accessor(@_);
328 }
329  
330 =head2 default_accessor
331  
332 Regular accessor.
333  
334 =over 4
335  
336 =item * $entity - L<EntityModel::Entity>
337  
338 =item * $field - L<EntityModel::Field>
339  
340 =back
341  
342 Returns a coderef which can act as an accessor, e.g. $ref->($self, $value).
343  
344 =cut
345  
346 0 ▶sub default_accessor {
Subroutine default_accessor: not called CC=1 SCAR=6.9
Pod documented
347 0 my $self = shift;
348 0 my ($entity, $field) = @_;
349  
350 0 my $keyName = $field->name;
351  
352 0 ▶ return sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
353 0 my $self = shift;
354  
355 0 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
356 0 my $v = shift;
357 0 $self->{ $keyName } = $v;
358 0 $self->{ _update_required } = 1;
359 0 $self->commit;
360 0 return $self;
361 }
362  
363 # Populate where required
364 0 ▶ $self->_select(key => $keyName) if $self->{_incomplete} && !exists($self->{ $keyName });
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_incomplete"} and not exists $self->{$keyName} 0 0 0
Condition0%0/3
$self->{"_incomplete"} and not exists $self->{$keyName}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_incomplete"} and not exists $self->{$keyName}
$self->{"_incomplete"} not exists $self->{$keyName}
Truth table0%0/3
A and not(B)
A= $self->{"_incomplete"}B= not exists $self->{$keyName}
ABresult
0X0
100
111
365  
366 0 return $self->{ $keyName };
367 0 };
368 }
369  
370 =head2 timestamp_accessor
371  
372 Accessor for timestamp values.
373  
374 =over 4
375  
376 =item * $entity - L<EntityModel::Entity>
377  
378 =item * $field - L<EntityModel::Field>
379  
380 =back
381  
382 Returns a coderef which can act as an accessor, e.g. $ref->($self, $value).
383  
384 Accessor accepts the following input formats:
385  
386 =over 4
387  
388 =item * DateTime - a L<DateTime> object (or subclassed variant)
389  
390 =item * Epoch time - numeric value containing seconds since epoch
391  
392 =item * String - standard date/time string in ISO8601 format.
393  
394 =back
395  
396  
397 =cut
398  
399 0 ▶sub timestamp_accessor {
Subroutine timestamp_accessor: not called CC=1 SCAR=6.9
Pod documented
400 0 my $self = shift;
401 0 my ($entity, $field) = @_;
402  
403 0 my $field_name = $field->name;
404 0 my $keyName = $field->name;
405 0 my $fieldType = $field->type;
406 0 my $fieldRefer = undef;
407  
408 0 ▶ return sub {
Subroutine __ANON__: not called CC=9 SCAR=45.0
409 0 my $self = shift;
410  
411 0 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
412 0 my $v = shift;
413 0 ▶ if(defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) 0 0 0
414 0 ▶ if(Scalar::Util::blessed($v) && $v->isa('DateTime')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($v) and $v->isa('DateTime')) { } 0 0 0
Condition0%0/3
builtin::blessed($v) and $v->isa("DateTime")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($v) and $v->isa("DateTime")
builtin::blessed($v) $v->isa("DateTime")
Truth table0%0/3
A and B
A= builtin::blessed($v)B= $v->isa("DateTime")
ABresult
0X0
100
111
415 0 $v = sprintf "%s.%09d", $v->iso8601, $v->nanosecond;
416 } else {
417 0 ▶ $v = POSIX::strftime('%Y-%m-%dT%H:%M:%S', gmtime $v) if $v =~ /^\d+(\.\d*)?$/;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /^\d+(\.\d*)?$/ 0 0 0
418 0 ▶ $v .= substr sprintf('%11.9f', $1), 1 if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 0 0
419 }
420 }
421 0 $self->{ $keyName } = $v;
422 0 $self->{ _update_required } = 1;
423 0 $self->commit;
424 0 return $self;
425 }
426  
427 # Populate where required
428 0 ▶ $self->_select(key => $keyName) if $self->{_incomplete} && !exists($self->{ $keyName });
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_incomplete"} and not exists $self->{$keyName} 0 0 0
Condition0%0/3
$self->{"_incomplete"} and not exists $self->{$keyName}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_incomplete"} and not exists $self->{$keyName}
$self->{"_incomplete"} not exists $self->{$keyName}
Truth table0%0/3
A and not(B)
A= $self->{"_incomplete"}B= not exists $self->{$keyName}
ABresult
0X0
100
111
429  
430 0 return $self->_timeStamp($field_name);
431 0 };
432 }
433  
434 =head2 ref_accessor
435  
436 Accessor for reference fields.
437  
438 =over 4
439  
440 =item * $entity - L<EntityModel::Entity>
441  
442 =item * $field - L<EntityModel::Field>
443  
444 =back
445  
446 Returns a coderef which can act as an accessor, e.g. $ref->($self, $value).
447  
448 =cut
449  
450 0 ▶sub ref_accessor {
Subroutine ref_accessor: not called CC=1 SCAR=6.9
Pod documented
451 0 my $self = shift;
452 0 my ($entity, $field) = @_;
453  
454 0 my $field_name = $field->name;
455 0 my $keyName = $field_name;
456 0 my $fieldType = $field->type;
457 0 my $refEntity = $field->refer->entity;
458 0 my $refpkg = $self->package_name($refEntity->name);
459 0 my $rf = $field->refer->field;
460  
461 # Return an accessor which instantiates this class if set
462 0 ▶ return sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
463 0 my $self = shift;
464  
465 0 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
466 0 my $v = shift;
467 0 $self->{ $keyName } = $v->id;
468 0 $self->{ _update_required } = 1;
469 0 return $self;
470 }
471  
472 # First check whether we're complete and so have some value for the ID (could be undef)
473 0 my $target;
474 0 ▶ if(exists $self->{$keyName}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$keyName}) { } 0 0 0
475 # Return a NULL version of the target class if we know that we're dealing with NULL in the
476 # foreign key. We don't just pass back undef, since we want to support chained methods.
477 0 ▶ return $refpkg->new({ }, null => 1) unless defined $self->{$keyName};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$keyName} 0 0 0
478  
479 # We have an ID, so we'll use this to instantiate the object. With luck, we have it cached
480 # or readily available so this instantiation should be relatively cheap. If not, we'll queue
481 # a storage pull request.
482 0 $target = $refpkg->new($self->{ $keyName });
483 } else {
484 # If we're incomplete and don't have the ID for this, we'll queue a completion request on $self,
485 # and instantiate the target class in a way that allows us to populate with ID when we have it.
486 0 $target = $refpkg->new({
487 }, pending => 1);
488  
489 $self->_request_load(
490 0 ▶ on_complete => $self->sap(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
491 0 my $self = shift;
492 0 $target->id($self->{ $keyName });
493 0 $target->_request_load;
494 }),
495 0 ▶ on_error => sub { die "some error occurred and we are not sure what to do about it"; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
496 0 );
497 }
498 0 return $target;
499 0 };
500 }
501  
502  
503 1 1;
504  
505 __END__
« EntityModel/Support/Perl/Base.pm ↑ Summary EntityModel/Storage/Perl.pm »