blib/lib/App/RecordStream/DomainLanguage/Registry.pm

filter: Statementstmt 79.6% 94 / 118 Branchbran 67.6% 23 / 34 Conditioncond 58.5% 24 / 41 MC/DCmcdc 18.5% 5 / 27 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 7 totaltotal 66.2% 159 / 240 CC 40 SCAR 34.0
CC
40
Cov
73%
evaluate
51.8
register_fn
10.7
evaluate_aux
8.4
CRAP 29.8
« blib/lib/App/RecordStream/Operation/togdgraph.pm ↑ Summary blib/lib/App/RecordStream/DomainLanguage/Value.pm »
1 package App::RecordStream::DomainLanguage::Registry;
2  
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 29 ▶use App::RecordStream::DomainLanguage::Value;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 29 ▶use Scalar::Util ('blessed');
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 29 my $registry =
10 {
11 };
12  
13 sub new_node
14 {
15 return
16 {
17 1403 ▶ 'SUBREF' => undef,
Subroutine new_node: called CC=1 SCAR=0.0
Pod undocumented
18 'EPSILONS' => {},
19 'NORMALS' => {},
20 'REPEATABLE' => undef,
21 };
22 }
23  
24 sub register_ctor
25 {
26 52 ▶ my $pkg = shift;
Subroutine register_ctor: called CC=1 SCAR=0.0
Pod undocumented
27 52 my $token = shift;
28 52 my @types = @_;
29  
30 52 ▶ return register_fn(sub { return $pkg->new(@_) }, $token, @types);
Subroutine __ANON__: called CC=1 SCAR=0.0
31 }
32  
33 sub register_vfn
34 {
35 384 ▶ my $tgt = shift;
Subroutine register_vfn: called CC=1 SCAR=0.0
Pod undocumented
36 384 my $meth = shift;
37 384 my $token = shift;
38 384 my @types = @_;
39  
40 384 ▶ return register_fn(sub { return $tgt->$meth(@_) }, $token, @types);
Subroutine __ANON__: called CC=1 SCAR=0.0
41 }
42  
43 sub register_fn
44 {
45 652 ▶ my $subref = shift;
Subroutine register_fn: called CC=7 SCAR=23.7
Pod undocumented
46 652 my $token = shift;
47 652 my @types = @_;
48  
49 652 ▶ my $p = ($registry->{$token} ||= new_node());
Condition66%2/3
$registry->{$token} ||= new_node()
l!l&&r!l&&!r
835690
MC/DC0%0/2
$registry->{$token} ||= new_node()
$registry->{$token} new_node()
Truth table66%2/3
A ||= B
A= $registry->{$token}B= new_node()
ABresult
1X1
011
000
50  
51 652 for my $type (@types)
52 {
53 978 ▶ if($type =~ /^(.*)\*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^(.*)\*$/) { } 0 978 978
54 {
55 0 my $raw_type = $1;
56 0 ▶ $p = ($p->{'EPSILONS'}->{$raw_type} ||= new_node());
Condition0%0/3
$p->{"EPSILONS"}{$raw_type} ||= new_node()
l!l&&r!l&&!r
000
MC/DC0%0/2
$p->{"EPSILONS"}{$raw_type} ||= new_node()
$p->{"EPSILONS"}{$raw_type} new_node()
Truth table0%0/3
A ||= B
A= $p->{"EPSILONS"}{$raw_type}B= new_node()
ABresult
1X1
011
000
57 0 $p->{'REPEATABLE'} = $raw_type;
58 }
59 else
60 {
61 978 ▶ $p = ($p->{'NORMALS'}->{$type} ||= new_node());
Condition66%2/3
$p->{"NORMALS"}{$type} ||= new_node()
l!l&&r!l&&!r
1448340
MC/DC0%0/2
$p->{"NORMALS"}{$type} ||= new_node()
$p->{"NORMALS"}{$type} new_node()
Truth table66%2/3
A ||= B
A= $p->{"NORMALS"}{$type}B= new_node()
ABresult
1X1
011
000
62 }
63 }
64  
65 652 ▶ if($p->{'SUBREF'})
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"SUBREF"}) 0 652 652
66 {
67 0 die "Collision in type registry at $token(" . join(", ", @types) . ")";
68 }
69  
70 652 $p->{'SUBREF'} = $subref;
71 }
72  
73 sub get_tokens
74 {
75 378 ▶ return keys(%$registry);
Subroutine get_tokens: called CC=1 SCAR=0.0
Pod undocumented
76 }
77  
78 sub evaluate
79 {
80 343 ▶ my $token = shift;
Subroutine evaluate: called CC=27 SCAR=39.5
Pod undocumented
81 343 my @raw_args = @_;
82  
83 343 my @value_args;
84 343 for my $arg (@raw_args)
85 {
86 512 ▶ if(blessed($arg) && $arg->isa('App::RecordStream::DomainLanguage::Value'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($arg) and $arg->isa("App::RecordStream::DomainLanguage::Value")) 160 352 512
Condition100%3/3
builtin::blessed($arg) and $arg->isa("App::RecordStream::DomainLanguage::Value")
!ll&&!rl&&r
184168160
MC/DC100%2/2
builtin::blessed($arg) and $arg->isa("App::RecordStream::DomainLanguage::Value")
builtin::blessed($arg) $arg->isa("App::RecordStream::DomainLanguage::Value")
Truth table100%3/3
A and B
A= builtin::blessed($arg)B= $arg->isa("App::RecordStream::DomainLanguage::Value")
ABresult
0X0
100
111
87 {
88 160 push @value_args, $arg;
89 160 next;
90 }
91 352 my $value = App::RecordStream::DomainLanguage::Value->new("<raw object>");
92 352 my $done = 0;
93 352 ▶ if(blessed($arg) && $arg->isa('App::RecordStream::DomainLanguage::Valuation'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($arg) and $arg->isa("App::RecordStream::DomainLanguage::Valuation")) 0 352 352
Condition66%2/3
builtin::blessed($arg) and $arg->isa("App::RecordStream::DomainLanguage::Valuation")
!ll&&!rl&&r
1841680
MC/DC0%0/2
builtin::blessed($arg) and $arg->isa("App::RecordStream::DomainLanguage::Valuation")
builtin::blessed($arg) $arg->isa("App::RecordStream::DomainLanguage::Valuation")
Truth table66%2/3
A and B
A= builtin::blessed($arg)B= $arg->isa("App::RecordStream::DomainLanguage::Valuation")
ABresult
0X0
100
111
94 {
95 0 $value->add_possibility('VALUATION', $arg);
96 0 $done = 1;
97 }
98 352 ▶ if(blessed($arg) && $arg->isa('App::RecordStream::Aggregator::Aggregation'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($arg) and $arg->isa("App::RecordStream::Aggregator::Aggregation")) 0 352 352
Condition66%2/3
builtin::blessed($arg) and $arg->isa("App::RecordStream::Aggregator::Aggregation")
!ll&&!rl&&r
1841680
MC/DC0%0/2
builtin::blessed($arg) and $arg->isa("App::RecordStream::Aggregator::Aggregation")
builtin::blessed($arg) $arg->isa("App::RecordStream::Aggregator::Aggregation")
Truth table66%2/3
A and B
A= builtin::blessed($arg)B= $arg->isa("App::RecordStream::Aggregator::Aggregation")
ABresult
0X0
100
111
99 {
100 0 $value->add_possibility('AGGREGATOR', $arg);
101 0 $done = 1;
102 }
103 352 ▶ if(blessed($arg) && $arg->isa('App::RecordStream::Deaggregator::Base'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($arg) and $arg->isa("App::RecordStream::Deaggregator::Base")) 0 352 352
Condition66%2/3
builtin::blessed($arg) and $arg->isa("App::RecordStream::Deaggregator::Base")
!ll&&!rl&&r
1841680
MC/DC0%0/2
builtin::blessed($arg) and $arg->isa("App::RecordStream::Deaggregator::Base")
builtin::blessed($arg) $arg->isa("App::RecordStream::Deaggregator::Base")
Truth table66%2/3
A and B
A= builtin::blessed($arg)B= $arg->isa("App::RecordStream::Deaggregator::Base")
ABresult
0X0
100
111
104 {
105 0 $value->add_possibility('DEAGGREGATOR', $arg);
106 0 $done = 1;
107 }
108 352 ▶ if(blessed($arg) && $arg->isa('App::RecordStream::Clumper::Base'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($arg) and $arg->isa("App::RecordStream::Clumper::Base")) 0 352 352
Condition66%2/3
builtin::blessed($arg) and $arg->isa("App::RecordStream::Clumper::Base")
!ll&&!rl&&r
1841680
MC/DC0%0/2
builtin::blessed($arg) and $arg->isa("App::RecordStream::Clumper::Base")
builtin::blessed($arg) $arg->isa("App::RecordStream::Clumper::Base")
Truth table66%2/3
A and B
A= builtin::blessed($arg)B= $arg->isa("App::RecordStream::Clumper::Base")
ABresult
0X0
100
111
109 {
110 0 $value->add_possibility('CLUMPER', $arg);
111 0 $done = 1;
112 }
113 352 ▶ if($done)
Branch: 1 branch
BranchTrueFalseTotal
if ($done) 0 352 352
114 {
115 0 push @value_args, $value;
116 0 next;
117 }
118  
119 # uh, no clue, must be a scalar
120 352 push @value_args, App::RecordStream::DomainLanguage::Value->new_from_scalar($arg);
121 }
122  
123 # now all of @value_args is Value objects
124 343 my @results;
125 343 ▶ evaluate_aux(\@results, ($registry->{$token} || {}), [], @value_args);
Condition50%1/2
$registry->{$token} || {}
l!l
3430
MC/DC0%0/1
$registry->{$token} || {}
$registry->{$token}
Truth table50%1/2
A
A= $registry->{$token}
Aresult
11
00
126  
127 343 my $ret = App::RecordStream::DomainLanguage::Value->new($token . "(" . join(", ", map { $_->get_description() } @value_args) . ")");
128  
129 343 for my $result (@results)
130 {
131 340 ▶ if(blessed($result) && $result->isa('App::RecordStream::DomainLanguage::Value'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($result) and $result->isa("App::RecordStream::DomainLanguage::Value")) 147 193 340
Condition66%2/3
builtin::blessed($result) and $result->isa("App::RecordStream::DomainLanguage::Value")
!ll&&!rl&&r
0193147
MC/DC50%1/2
builtin::blessed($result) and $result->isa("App::RecordStream::DomainLanguage::Value")
builtin::blessed($result) $result->isa("App::RecordStream::DomainLanguage::Value")
Truth table66%2/3
A and B
A= builtin::blessed($result)B= $result->isa("App::RecordStream::DomainLanguage::Value")
ABresult
0X0
100
111
132 {
133 147 for my $pair ($result->get_possible_pairs())
134 {
135 294 my ($type, $value) = @$pair;
136 294 $ret->add_possibility($type, $value);
137 }
138 147 next;
139 }
140 193 my $done = 0;
141 193 ▶ if(blessed($result) && $result->isa('App::RecordStream::DomainLanguage::Valuation'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($result) and $result->isa("App::RecordStream::DomainLanguage::Valuation")) 4 189 193
Condition66%2/3
builtin::blessed($result) and $result->isa("App::RecordStream::DomainLanguage::Valuation")
!ll&&!rl&&r
01894
MC/DC50%1/2
builtin::blessed($result) and $result->isa("App::RecordStream::DomainLanguage::Valuation")
builtin::blessed($result) $result->isa("App::RecordStream::DomainLanguage::Valuation")
Truth table66%2/3
A and B
A= builtin::blessed($result)B= $result->isa("App::RecordStream::DomainLanguage::Valuation")
ABresult
0X0
100
111
142 {
143 4 $ret->add_possibility('VALUATION', $result);
144 4 $done = 1;
145 }
146 193 ▶ if(blessed($result) && $result->isa('App::RecordStream::Aggregator::Aggregation'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($result) and $result->isa("App::RecordStream::Aggregator::Aggregation")) 189 4 193
Condition66%2/3
builtin::blessed($result) and $result->isa("App::RecordStream::Aggregator::Aggregation")
!ll&&!rl&&r
04189
MC/DC50%1/2
builtin::blessed($result) and $result->isa("App::RecordStream::Aggregator::Aggregation")
builtin::blessed($result) $result->isa("App::RecordStream::Aggregator::Aggregation")
Truth table66%2/3
A and B
A= builtin::blessed($result)B= $result->isa("App::RecordStream::Aggregator::Aggregation")
ABresult
0X0
100
111
147 {
148 189 $ret->add_possibility('AGGREGATOR', $result);
149 189 $done = 1;
150 }
151 193 ▶ if(blessed($result) && $result->isa('App::RecordStream::Deaggregator::Base'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($result) and $result->isa("App::RecordStream::Deaggregator::Base")) 0 193 193
Condition33%1/3
builtin::blessed($result) and $result->isa("App::RecordStream::Deaggregator::Base")
!ll&&!rl&&r
01930
MC/DC0%0/2
builtin::blessed($result) and $result->isa("App::RecordStream::Deaggregator::Base")
builtin::blessed($result) $result->isa("App::RecordStream::Deaggregator::Base")
Truth table33%1/3
A and B
A= builtin::blessed($result)B= $result->isa("App::RecordStream::Deaggregator::Base")
ABresult
0X0
100
111
152 {
153 0 $ret->add_possibility('DEAGGREGATOR', $result);
154 0 $done = 1;
155 }
156 193 ▶ if(blessed($result) && $result->isa('App::RecordStream::Clumper::Base'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($result) and $result->isa("App::RecordStream::Clumper::Base")) 0 193 193
Condition33%1/3
builtin::blessed($result) and $result->isa("App::RecordStream::Clumper::Base")
!ll&&!rl&&r
01930
MC/DC0%0/2
builtin::blessed($result) and $result->isa("App::RecordStream::Clumper::Base")
builtin::blessed($result) $result->isa("App::RecordStream::Clumper::Base")
Truth table33%1/3
A and B
A= builtin::blessed($result)B= $result->isa("App::RecordStream::Clumper::Base")
ABresult
0X0
100
111
157 {
158 0 $ret->add_possibility('CLUMPER', $result);
159 0 $done = 1;
160 }
161 193 ▶ if($done)
Branch: 1 branch
BranchTrueFalseTotal
if ($done) 193 0 193
162 {
163 193 next;
164 }
165  
166 0 $ret->add_possibility('SCALAR', $result);
167 }
168  
169 343 return $ret;
170 }
171  
172 sub evaluate_aux
173 {
174 867 ▶ my $results_ref = shift;
Subroutine evaluate_aux: called CC=8 SCAR=21.3
Pod undocumented
175 867 my $registry_pos = shift;
176 867 my $built_args = shift;
177 867 my @values_left = @_;
178  
179 867 for my $type (keys(%{$registry_pos->{'EPSILONS'}}))
180 {
181 0 evaluate_aux($results_ref, $registry_pos->{'EPSILONS'}->{$type}, $built_args, @values_left);
182 }
183  
184 867 ▶ if(!@values_left)
Branch: 1 branch
BranchTrueFalseTotal
unless (@values_left) 343 524 867
185 {
186 # this is our stop
187 343 my $subref = $registry_pos->{'SUBREF'};
188 343 ▶ if($subref)
Branch: 1 branch
BranchTrueFalseTotal
if ($subref) 340 3 343
189 {
190 340 push @$results_ref, $subref->(@$built_args);
191 }
192 343 return;
193 }
194  
195 524 my $next_value = shift @values_left;
196  
197 524 my $repeatable_type = $registry_pos->{'REPEATABLE'};
198 524 ▶ if($repeatable_type)
Branch: 1 branch
BranchTrueFalseTotal
if ($repeatable_type) 0 524 524
199 {
200 0 for my $arg ($next_value->get_possibilities($repeatable_type))
201 {
202 0 push @$built_args, $arg;
203 0 evaluate_aux($results_ref, $registry_pos, $built_args, @values_left);
204 0 pop @$built_args;
205 }
206 }
207  
208 524 for my $type (keys(%{$registry_pos->{'NORMALS'}}))
209 {
210 530 my $registry_pos_next = $registry_pos->{'NORMALS'}->{$type};
211 530 for my $arg ($next_value->get_possibilities($type))
212 {
213 524 push @$built_args, $arg;
214 524 evaluate_aux($results_ref, $registry_pos_next, $built_args, @values_left);
215 524 pop @$built_args;
216 }
217 }
218 }
219  
220 29 1;
« blib/lib/App/RecordStream/Operation/togdgraph.pm ↑ Summary blib/lib/App/RecordStream/DomainLanguage/Value.pm »