EntityModel/Support.pm

filter: Statementstmt 23.6% 9 / 38 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 2 / 4 Podpod 100% 2 / 2 totaltotal 24.0% 13 / 54 CC 7 SCAR 36.8
CC
7
Cov
19%
apply_model
56.0
register
2.0
BEGIN
1.0
CRAP 39.6
« EntityModel/Template.pm ↑ Summary EntityModel/Definition.pm »
1 package EntityModel::Support;
2 {
3 22 $EntityModel::Support::VERSION = '0.102';
4 }
5 22 ▶use EntityModel::Class {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 22 };
7 22 ▶no if $] >= 5.017011, warnings => "experimental::smartmatch";
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 EntityModel::Support - language support for L<EntityModel>
12  
13 =head1 VERSION
14  
15 version 0.102
16  
17 =head1 SYNOPSIS
18  
19 See L<EntityModel>.
20  
21 =head1 DESCRIPTION
22  
23 See L<EntityModel>.
24  
25 =head1 METHODS
26  
27 =cut
28  
29 =head2 register
30  
31 Register with L<EntityModel> so that callbacks trigger when further definitions are loaded/processed.
32  
33 =cut
34  
35 0 ▶sub register {
Subroutine register: not called CC=1 SCAR=6.9
Pod documented
36 0 my $class = shift;
37 }
38  
39 =head2 apply_model
40  
41 Apply the given model.
42  
43 =cut
44  
45 0 ▶sub apply_model {
Subroutine apply_model: not called CC=7 SCAR=40.3
Pod documented
46 0 my $self = shift;
47 0 my $model = shift;
48  
49 0 my @pending = $model->entity->list;
50 0 my @pendingNames = map { $_->name } @pending;
51 0 my @existing;
52 ITEM:
53 0 ▶ while(@pending) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pending) 0 0 0
54 0 my $entity = shift(@pending);
55 0 shift(@pendingNames);
56  
57 0 my @deps = $entity->dependencies;
58  
59 # Include current entity in list of available entries, so that we can allow self-reference
60 DEP:
61 0 foreach my $dep (@deps) {
62 0 ▶ next DEP if $dep->name ~~ $entity->name;
Branch: 1 branch
BranchTrueFalseTotal
if $dep->name ~~ $entity->name 0 0 0
63 0 ▶ next DEP if grep { $dep->name ~~ $_ } @pendingNames;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$dep->name ~~ $_;} @pendingNames 0 0 0
64 0 ▶ unless(grep { $dep->name ~~ $_->name } @existing) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$dep->name ~~ $_->name;} @existing) 0 0 0
65 0 logError("%s unresolved (pending %s, deps %s for %s)", $dep->name, join(',', @pendingNames), join(',', @deps), $entity->name);
66 0 die "Dependency error";
67 }
68 }
69  
70 0 my @unsatisfied = grep { $_->name ~~ \@pendingNames } @deps;
71 0 ▶ if(@unsatisfied) {
Branch: 1 branch
BranchTrueFalseTotal
if (@unsatisfied) 0 0 0
72 0 logInfo("%s has %d unsatisfied deps, postponing: %s", $entity->name, scalar @unsatisfied, join(',',@unsatisfied));
73 0 push @pending, $entity;
74 0 push @pendingNames, $entity->name;
75 0 next ITEM;
76 }
77  
78 0 $self->apply_entity($entity);
79 0 push @existing, $entity;
80 }
81 0 return $self;
82 }
83  
84 22 1;
85  
86 __END__
« EntityModel/Template.pm ↑ Summary EntityModel/Definition.pm »