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 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::Registry;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 29 ▶use App::RecordStream::Executor;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 29 my $next_id = 0;
10  
11 sub new
12 {
13 378 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14  
15 378 my $id = $next_id++;
16  
17 378 my $this =
18 {
19 'ID' => $id,
20 };
21  
22 378 bless $this, $class;
23  
24 378 return $this;
25 }
26  
27 sub clear_vars
28 {
29 0 ▶ my $this = shift;
Subroutine clear_vars: not called CC=1 SCAR=0.9
Pod undocumented
30  
31 0 my $id = $this->{'ID'};
32  
33 {
34 29 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.2
35 29 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 0 %{__PACKAGE__ . "::Sandbox" . $id . "::"} = ();
38 }
39 }
40  
41 sub set_scalar
42 {
43 287 ▶ my $this = shift;
Subroutine set_scalar: called CC=1 SCAR=0.0
Pod undocumented
44 287 my $var = shift;
45 287 my $val = shift;
46  
47 287 my $id = $this->{'ID'};
48  
49 {
50 29 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 29 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 287 *{__PACKAGE__ . "::Sandbox" . $id . "::" . $var} = \$val;
54 }
55 }
56  
57 sub get_scalar
58 {
59 0 ▶ my $this = shift;
Subroutine get_scalar: not called CC=1 SCAR=1.2
Pod undocumented
60 0 my $var = shift;
61  
62 0 my $id = $this->{'ID'};
63  
64 {
65 29 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.2
66 29 ▶ 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 {
74 57516 ▶ my $this = shift;
Subroutine set_ref: called CC=1 SCAR=0.0
Pod undocumented
75 57516 my $var = shift;
76 57516 my $ref = shift;
77  
78 57516 my $id = $this->{'ID'};
79  
80 {
81 29 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 29 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 57516 *{__PACKAGE__ . "::Sandbox" . $id . "::" . $var} = $ref;
85 }
86 }
87  
88 # TODO: amling, default this?
89 sub import_registry
90 {
91 378 ▶ my $this = shift;
Subroutine import_registry: called CC=2 SCAR=7.1
Pod undocumented
92  
93 378 for my $token (App::RecordStream::DomainLanguage::Registry::get_tokens())
94 {
95 my $subref = sub
96 {
97 343 ▶ my $value = App::RecordStream::DomainLanguage::Registry::evaluate($token, @_);
Subroutine __ANON__: called CC=3 SCAR=11.8
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 28740 };
116 28740 $this->set_ref($token, $subref);
117 28740 $this->set_ref("_$token", $subref); # for e.g. "last" which is reserved
118 }
119 }
120  
121 sub exec
122 {
123 378 ▶ my $__MY__this = shift;
Subroutine exec: called CC=2 SCAR=7.0
Pod undocumented
124 378 my $__MY__code = shift;
125  
126 378 $__MY__code = App::RecordStream::Executor->transform_code($__MY__code);
127  
128 378 my $__MY__id = $__MY__this->{'ID'};
129  
130 378 my $__MY__code_packaged = "package " . __PACKAGE__ . "::Sandbox$__MY__id; $__MY__code";
131 378 my $__MY__ret;
132  
133 {
134 29 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
135 29 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
136  
137 378 $__MY__ret = eval $__MY__code_packaged;
138  
139 378 ▶ if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 378 378
140 {
141 0 die $@;
142 }
143 }
144  
145 378 return $__MY__ret;
146 }
147  
148 29 1;
« blib/lib/App/RecordStream/Operation/assert.pm ↑ Summary blib/lib/App/RecordStream/Test/UniqConcatHelper.pm »