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

filter: Statementstmt 86.3% 82 / 95 Branchbran 50.0% 2 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.9% 20 / 22 Podpod 0.0% 0 / 7 totaltotal 79.7% 106 / 133 CC 5 SCAR 3.5
CC
5
Cov
84%
__ANON__
3.2
import_registry
2.0
exec
2.0
CRAP 1.4
« blib/lib/App/RecordStream/Operation/assert.pm ↑ Summary blib/lib/App/RecordStream/Test/UniqConcatHelper.pm »
1 package App::RecordStream::DomainLanguage::Executor;
2  
3 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 30 ▶use App::RecordStream::DomainLanguage::Registry;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use App::RecordStream::Executor;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 30 my $next_id = 0;
10  
11 sub new
12 389 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
13 389 my $class = shift;
14  
15 389 my $id = $next_id++;
16  
17 389 my $this =
18 {
19 'ID' => $id,
20 };
21  
22 389 bless $this, $class;
23  
24 389 return $this;
25 }
26  
27 sub clear_vars
28 0 ▶{
Subroutine clear_vars: not called CC=1 SCAR=0.9
Pod undocumented
29 0 my $this = shift;
30  
31 0 my $id = $this->{'ID'};
32  
33 {
34 0 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.2
35 30 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 0 %{__PACKAGE__ . "::Sandbox" . $id . "::"} = ();
38 }
39 }
40  
41 sub set_scalar
42 302 ▶{
Subroutine set_scalar: called CC=1 SCAR=0.0
Pod undocumented
43 302 my $this = shift;
44 302 my $var = shift;
45 302 my $val = shift;
46  
47 302 my $id = $this->{'ID'};
48  
49 {
50 30 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 30 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 302 *{__PACKAGE__ . "::Sandbox" . $id . "::" . $var} = \$val;
54 }
55 }
56  
57 sub get_scalar
58 0 ▶{
Subroutine get_scalar: not called CC=1 SCAR=1.2
Pod undocumented
59 0 my $this = shift;
60 0 my $var = shift;
61  
62 0 my $id = $this->{'ID'};
63  
64 {
65 0 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.2
66 30 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 0 return ${__PACKAGE__ . "::Sandbox" . $id . "::" . $var};
69 }
70 }
71  
72 sub set_ref
73 59320 ▶{
Subroutine set_ref: called CC=1 SCAR=0.0
Pod undocumented
74 59320 my $this = shift;
75 59320 my $var = shift;
76 59320 my $ref = shift;
77  
78 59320 my $id = $this->{'ID'};
79  
80 {
81 30 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 30 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 59320 *{__PACKAGE__ . "::Sandbox" . $id . "::" . $var} = $ref;
85 }
86 }
87  
88 # TODO: amling, default this?
89 sub import_registry
90 389 ▶{
Subroutine import_registry: called CC=2 SCAR=7.1
Pod undocumented
91 389 my $this = shift;
92  
93 389 for my $token (App::RecordStream::DomainLanguage::Registry::get_tokens())
94 {
95 my $subref = sub
96 343 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.8
97 343 my $value = App::RecordStream::DomainLanguage::Registry::evaluate($token, @_);
98  
99 # this is somewhat terrible...
100 343 my @pp = $value->get_possible_pairs();
101 343 ▶ if(!@_ && !@pp)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_ or @pp) 0 343 343
Condition66%2/3
@_ or @pp
l!l&&r!l&&!r
323200
MC/DC0%0/2
@_ or @pp
@_ @pp
Truth table66%2/3
A or B
A= @_B= @pp
ABresult
1X1
011
000
102 {
103 # The idea is this... if they use a field name that doesn't
104 # conflict with a nullary function then we pretend it was a
105 # barewords scalar.
106  
107 # Unfortunately this means e.g. "rec" is indistinguishable
108 # between the valuation that returns the "rec" field and the
109 # valuation that returns the current record. We allow the
110 # "rec" field possibility via the explicit "valuation" ctor.
111 0 $value->add_possibility('SCALAR', $token);
112 }
113  
114 343 return $value;
115 29642 };
116 29642 $this->set_ref($token, $subref);
117 29642 $this->set_ref("_$token", $subref); # for e.g. "last" which is reserved
118 }
119 }
120  
121 sub exec
122 389 ▶{
Subroutine exec: called CC=2 SCAR=7.0
Pod undocumented
123 389 my $__MY__this = shift;
124 389 my $__MY__code = shift;
125  
126 389 $__MY__code = App::RecordStream::Executor->transform_code($__MY__code);
127  
128 389 my $__MY__id = $__MY__this->{'ID'};
129  
130 389 my $__MY__code_packaged = "package " . __PACKAGE__ . "::Sandbox$__MY__id; $__MY__code";
131 389 my $__MY__ret;
132  
133 {
134 30 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
135 30 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
136  
137 389 $__MY__ret = eval $__MY__code_packaged;
138  
139 389 ▶ if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 389 389
140 {
141 0 die $@;
142 }
143 }
144  
145 389 return $__MY__ret;
146 }
147  
148 30 1;
« blib/lib/App/RecordStream/Operation/assert.pm ↑ Summary blib/lib/App/RecordStream/Test/UniqConcatHelper.pm »