TestML1/Runtime.pm

filter: Statementstmt 89.6% 278 / 310 Branchbran 73.5% 75 / 102 Conditioncond 70.8% 17 / 24 MC/DCmcdc 35.7% 5 / 14 Subroutinesub 76.9% 50 / 65 Podpod 0.0% 0 / 17 totaltotal 79.8% 425 / 532 CC 70 SCAR 16.9
CC
70
Cov
85%
run_call
16.4
select_blocks
12.7
run_expression
8.2
CRAP 5.4
« TestML1/Compiler/Lite.pm ↑ Summary TestML1/Runtime/TAP.pm »
1 package TestML1::Runtime;
2  
3 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 26 has testml => ();
6 26 has bridge => ();
7 26 has library => ();
8 26 has compiler => ();
9 26 has skip => ();
10  
11 26 has function => ();
12 26 has error => ();
13 26 has global => ();
14 26 has base => ();
15  
16 26 ▶use File::Basename();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 26 ▶use File::Spec();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 24 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=7.6
Pod undocumented
20 24 my ($self) = @_;
21 24 $TestML1::Runtime::Singleton = $self;
22 24 ▶ $self->{base} ||= File::Basename::dirname($0);
Condition33%1/3
$self->{"base"} ||= File::Basename::dirname($0)
l!l&&r!l&&!r
0240
MC/DC0%0/2
$self->{"base"} ||= File::Basename::dirname($0)
$self->{"base"} File::Basename::dirname($0)
Truth table33%1/3
A ||= B
A= $self->{"base"}B= File::Basename::dirname($0)
ABresult
1X1
011
000
23 }
24  
25 24 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
26 24 my ($self) = @_;
27 24 $self->compile_testml;
28 24 $self->initialize_runtime;
29 24 $self->run_function($self->{function}, []);
30 }
31  
32 # TODO Functions should have return values
33 35 ▶sub run_function {
Subroutine run_function: called CC=3 SCAR=11.0
Pod undocumented
34 35 my ($self, $function, $args) = @_;
35  
36 35 $self->apply_signature($function, $args);
37  
38 35 my $parent = $self->function;
39 35 $self->{function} = $function;
40  
41 35 for my $statement (@{$function->statements}) {
42 168 ▶ if (ref($statement) eq 'TestML1::Assignment') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $statement eq 'TestML1::Assignment') { } 56 112 168
43 56 $self->run_assignment($statement);
44 }
45 else {
46 112 $self->run_statement($statement);
47 }
48 }
49 35 $self->{function} = $parent;
50 35 return;
51 }
52  
53 35 ▶sub apply_signature {
Subroutine apply_signature: called CC=5 SCAR=16.4
Pod undocumented
54 35 my ($self, $function, $args) = @_;
55 35 my $signature = $function->signature;
56  
57 35 ▶ die sprintf(
Branch: 1 branch
BranchTrueFalseTotal
if @$signature and @$args != @$signature 0 35 35
Condition66%2/3
@$signature and @$args != @$signature
!ll&&!rl&&r
24110
MC/DC0%0/2
@$signature and @$args != @$signature
@$signature @$args != @$signature
Truth table66%2/3
A and B
A= @$signatureB= @$args != @$signature
ABresult
0X0
100
111
58 "Function received %d args but expected %d",
59 scalar(@$args),
60 scalar(@$signature),
61 ) if @$signature and @$args != @$signature;
62  
63 35 $function->setvar('Self', $function);
64 35 ▶ for (my $i = 0; $i < @$signature; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$signature) 27 35 62
65 27 my $arg = $args->[$i];
66 27 ▶ $arg = $self->run_expression($arg)
Branch: 1 branch
BranchTrueFalseTotal
if ref $arg eq "TestML1::Expression" 0 27 27
67 if ref($arg) eq 'TestML1::Expression';
68 27 $function->setvar($signature->[$i], $arg);
69 }
70 }
71  
72 112 ▶sub run_statement {
Subroutine run_statement: called CC=5 SCAR=16.1
Pod undocumented
73 112 my ($self, $statement) = @_;
74 112 ▶ my $blocks = $self->select_blocks($statement->points || []);
Condition100%2/2
$statement->points || []
l!l
3973
MC/DC100%1/1
$statement->points || []
$statement->points
Truth table100%2/2
A
A= $statement->points
Aresult
11
00
75 112 for my $block (@$blocks) {
76 137 ▶ $self->function->setvar('Block', $block) if $block != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $block != 1 64 73 137
77 137 my $result = $self->run_expression($statement->expr);
78 137 ▶ if (my $assert = $statement->assert) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $assert = $statement->assert) 122 15 137
79 122 $self->run_assertion($result, $assert);
80 }
81 }
82 }
83  
84 56 ▶sub run_assignment {
Subroutine run_assignment: called CC=1 SCAR=0.0
Pod undocumented
85 56 my ($self, $assignment) = @_;
86 56 $self->function->setvar(
87 $assignment->name,
88 $self->run_expression($assignment->expr),
89 );
90 }
91  
92 122 ▶sub run_assertion {
Subroutine run_assertion: called CC=2 SCAR=6.9
Pod undocumented
93 122 my ($self, $left, $assert) = @_;
94 122 my $method = 'assert_' . $assert->name;
95  
96 122 $self->function->getvar('TestNumber')->{value}++;
97  
98 122 ▶ if ($assert->expr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($assert->expr) { } 103 19 122
99 103 $self->$method($left, $self->run_expression($assert->expr));
100 }
101 else {
102 19 $self->$method($left);
103 }
104 }
105  
106 378 ▶sub run_expression {
Subroutine run_expression: called CC=8 SCAR=21.0
Pod undocumented
107 378 my ($self, $expr) = @_;
108  
109 378 my $context = undef;
110 378 $self->{error} = undef;
111 378 ▶ if ($expr->isa('TestML1::Expression')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expr->isa('TestML1::Expression')) { } 85 293 378
112 85 my @calls = @{$expr->calls};
113 85 ▶ die if @calls <= 1;
Branch: 1 branch
BranchTrueFalseTotal
if @calls <= 1 0 85 85
114 85 $context = $self->run_call(shift(@calls));
115 85 for my $call (@calls) {
116 130 ▶ if ($self->error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error) 11 119 130
117 next unless
118 11 ▶ $call->isa('TestML1::Call') and
Branch: 1 branch
BranchTrueFalseTotal
unless $call->isa("TestML1::Call") and $call->name eq "Catch" 4 7 11
Condition66%2/3
$call->isa("TestML1::Call") and $call->name eq "Catch"
!ll&&!rl&&r
047
MC/DC50%1/2
$call->isa("TestML1::Call") and $call->name eq "Catch"
$call->isa("TestML1::Call") $call->name eq "Catch"
Truth table66%2/3
A and B
A= $call->isa("TestML1::Call")B= $call->name eq "Catch"
ABresult
0X0
100
111
119 $call->name eq 'Catch';
120 }
121 126 $context = $self->run_call($call, $context);
122 }
123 }
124 else {
125 293 $context = $self->run_call($expr);
126 }
127 378 ▶ if ($self->error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error) 0 378 378
128 0 die $self->error;
129 }
130 378 return $context;
131 }
132  
133 504 ▶sub run_call {
Subroutine run_call: called CC=16 SCAR=28.0
Pod undocumented
134 504 my ($self, $call, $context) = @_;
135  
136 504 ▶ if ($call->isa('TestML1::Object')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->isa("TestML1::Object")) 129 375 504
137 129 return $call;
138 }
139 375 ▶ if ($call->isa('TestML1::Function')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->isa("TestML1::Function")) 11 364 375
140 11 return $call;
141 }
142 364 ▶ if ($call->isa('TestML1::Point')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->isa("TestML1::Point")) 132 232 364
143 132 return $self->get_point($call->name);
144 }
145 232 ▶ if ($call->isa('TestML1::Call')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->isa("TestML1::Call")) 232 0 232
146 232 my $name = $call->name;
147 232 ▶ my $callable =
Condition60%3/5
$self->function->getvar($name) || $self->lookup_callable($name) || die("Can't locate '${name}' callable")
l!l
2320
$self->function->getvar($name) or $self->lookup_callable($name)
l!l&&r!l&&!r
188440
MC/DC0%0/2
$self->function->getvar($name) || $self->lookup_callable($name) || die("Can't locate '${name}' callable")
$self->function->getvar($name) $self->lookup_callable($name)
Truth table66%2/3
A or B
A= $self->function->getvar($name)B= $self->lookup_callable($name)
ABresult
1X1
011
000
148 $self->function->getvar($name) ||
149 $self->lookup_callable($name) ||
150 die "Can't locate '$name' callable";
151 232 ▶ if ($callable->isa('TestML1::Object')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callable->isa("TestML1::Object")) 66 166 232
152 66 return $callable;
153 }
154 166 ▶ return $callable unless $call->args or defined $context;
Branch: 1 branch
BranchTrueFalseTotal
unless $call->args or defined $context 4 162 166
Condition100%3/3
$call->args or defined $context
l!l&&r!l&&!r
91714
MC/DC100%2/2
$call->args or defined $context
$call->args defined $context
Truth table100%3/3
A or B
A= $call->argsB= defined $context
ABresult
1X1
011
000
155 162 ▶ $call->{args} ||= [];
Condition100%2/2
$call->{"args"} ||= []
l!l
9171
MC/DC100%1/1
$call->{"args"} ||= []
$call->{"args"}
Truth table100%2/2
A
A= $call->{"args"}
Aresult
11
00
156 162 my $args = [map $self->run_expression($_), @{$call->args}];
157 162 ▶ unshift @$args, $context if $context;
Branch: 1 branch
BranchTrueFalseTotal
if $context 126 36 162
158 162 ▶ if ($callable->isa('TestML1::Callable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callable->isa("TestML1::Callable")) 151 11 162
159 151 my $value = eval { $callable->value->(@$args) };
160 151 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 7 144 151
161 7 $self->{error} = $@;
162 7 return TestML1::Error->new(value => $@);
163 }
164 144 ▶ die "'$name' did not return a TestML1::Object object"
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($value, "TestML1::Object") 0 144 144
165 unless UNIVERSAL::isa($value, 'TestML1::Object');
166 144 return $value;
167 }
168 11 ▶ if ($callable->isa('TestML1::Function')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callable->isa("TestML1::Function")) 11 0 11
169 11 return $self->run_function($callable, $args);
170 }
171 0 die;
172 }
173 0 die;
174 }
175  
176 44 ▶sub lookup_callable {
Subroutine lookup_callable: called CC=3 SCAR=11.0
Pod undocumented
177 44 my ($self, $name) = @_;
178 44 for my $library (@{$self->function->getvar('Library')->value}) {
179 76 ▶ if ($library->can($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($library->can($name)) 44 32 76
180 44 ▶ my $function = sub { $library->$name(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
181 44 my $callable = TestML1::Callable->new(value => $function);
182 44 $self->function->setvar($name, $callable);
183 44 return $callable;
184 }
185 }
186 0 return;
187 }
188  
189 132 ▶sub get_point {
Subroutine get_point: called CC=4 SCAR=14.8
Pod undocumented
190 132 my ($self, $name) = @_;
191 132 my $value = $self->function->getvar('Block')->{points}{$name};
192 132 ▶ defined $value or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $value or return 132 0 132
193 132 ▶ if ($value =~ s/\n+\z/\n/ and $value eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ s/\n+\z/\n/ and $value eq "\n") 0 132 132
Condition66%2/3
$value =~ s/\n+\z/\n/ and $value eq "\n"
!ll&&!rl&&r
86460
MC/DC0%0/2
$value =~ s/\n+\z/\n/ and $value eq "\n"
$value =~ s/\n+\z/\n/ $value eq "\n"
Truth table66%2/3
A and B
A= $value =~ s/\n+\z/\n/B= $value eq "\n"
ABresult
0X0
100
111
194 0 $value = '';
195 }
196 132 $value =~ s/^\\//gm;
197 132 return TestML1::Str->new(value => $value);
198 }
199  
200 112 ▶sub select_blocks {
Subroutine select_blocks: called CC=10 SCAR=25.4
Pod undocumented
201 112 my ($self, $wanted) = @_;
202 112 ▶ return [1] unless @$wanted;
Branch: 1 branch
BranchTrueFalseTotal
unless @$wanted 73 39 112
203 39 my $selected = [];
204  
205 39 OUTER: for my $block (@{$self->function->data}) {
206 100 my %points = %{$block->points};
207 100 ▶ next if exists $points{SKIP};
Branch: 1 branch
BranchTrueFalseTotal
if exists $points{"SKIP"} 0 100 100
208 100 ▶ if (exists $points{ONLY}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $points{"ONLY"}) 0 100 100
209 0 for my $point (@$wanted) {
210 0 ▶ return [] unless exists $points{$point};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $points{$point} 0 0 0
211 }
212 0 $selected = [$block];
213 0 last;
214 }
215 100 for my $point (@$wanted) {
216 178 ▶ next OUTER unless exists $points{$point};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $points{$point} 36 142 178
217 }
218 64 push @$selected, $block;
219 64 ▶ last if exists $points{LAST};
Branch: 1 branch
BranchTrueFalseTotal
if exists $points{"LAST"} 0 64 64
220 }
221 39 return $selected;
222 }
223  
224 24 ▶sub compile_testml {
Subroutine compile_testml: called CC=4 SCAR=14.0
Pod undocumented
225 24 my ($self) = @_;
226  
227 24 ▶ die "'testml' document required but not found"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->testml 0 24 24
228 unless $self->testml;
229 24 ▶ if ($self->testml !~ /\n/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->testml =~ /\n/) 20 4 24
230 20 my ($file, $dir) = File::Basename::fileparse($self->testml);
231 20 $self->{testml} = $file;
232 20 $self->{base} = File::Spec->catdir($self->{base}, $dir);
233 20 $self->{testml} = $self->read_testml_file($self->testml);
234 }
235 24 ▶ $self->{function} = $self->compiler->new->compile($self->testml)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"function"} = $self->compiler->new->compile($self->testml) or die "TestML1 document failed to compile" 24 0 24
236 or die "TestML1 document failed to compile";
237 }
238  
239 24 ▶sub initialize_runtime {
Subroutine initialize_runtime: called CC=4 SCAR=13.9
Pod undocumented
240 24 my ($self) = @_;
241  
242 24 $self->{global} = $self->function->outer;
243  
244 24 $self->{global}->setvar(Block => TestML1::Block->new);
245 24 $self->{global}->setvar(Label => TestML1::Str->new(value => '$BlockLabel'));
246 24 $self->{global}->setvar(True => $TestML1::Constant::True);
247 24 $self->{global}->setvar(False => $TestML1::Constant::False);
248 24 $self->{global}->setvar(None => $TestML1::Constant::None);
249 24 $self->{global}->setvar(TestNumber => TestML1::Num->new(value => 0));
250 24 $self->{global}->setvar(Library => TestML1::List->new);
251  
252 24 my $library = $self->function->getvar('Library');
253 24 for my $lib ($self->bridge, $self->library) {
254 48 ▶ if (ref($lib) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $lib eq 'ARRAY') { } 24 24 48
255 24 $library->push($_->new) for @$lib;
256 }
257 else {
258 24 $library->push($lib->new);
259 }
260 }
261 }
262  
263 125 ▶sub get_label {
Subroutine get_label: called CC=3 SCAR=11.2
Pod undocumented
264 125 my ($self) = @_;
265 125 ▶ my $label = $self->function->getvar('Label') or return;
Branch: 1 branch
BranchTrueFalseTotal
my $label = $self->function->getvar("Label") or return 125 0 125
266 125 ▶ $label = $label->value or return;
Branch: 1 branch
BranchTrueFalseTotal
$label = $label->value or return 125 0 125
267 125 $label =~ s/\$(\w+)/$self->replace_label($1)/ge;
268 125 return $label;
269 }
270  
271 116 ▶sub replace_label {
Subroutine replace_label: called CC=4 SCAR=13.9
Pod undocumented
272 116 my ($self, $var) = @_;
273 116 my $block = $self->function->getvar('Block');
274 116 ▶ return $block->label if $var eq 'BlockLabel';
Branch: 1 branch
BranchTrueFalseTotal
if $var eq "BlockLabel" 91 25 116
275 25 ▶ if (my $v = $block->points->{$var}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $v = $block->points->{$var}) 12 13 25
276 12 $v =~ s/\n.*//s;
277 12 $v =~ s/^\s*(.*?)\s*$/$1/;
278 12 return $v;
279 }
280 13 ▶ if (my $v = $self->function->getvar($var)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $v = $self->function->getvar($var)) 13 0 13
281 13 return $v->value;
282 }
283 }
284  
285 22 ▶sub read_testml_file {
Subroutine read_testml_file: called CC=2 SCAR=7.0
Pod undocumented
286 22 my ($self, $file) = @_;
287 22 my $path = File::Spec->catfile($self->base, $file);
288 22 ▶ open my $fh, $path
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $path or die "Can't open '${path}' for input: $!" 22 0 22
289 or die "Can't open '$path' for input: $!";
290 22 local $/;
291 22 return <$fh>;
292 }
293  
294 #-----------------------------------------------------------------------------
295 package TestML1::Function;
296  
297 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
298  
299 26 has type => 'Func'; # Functions are TestML1 typed objects
300 26 has signature => []; # Input variable names
301 26 has namespace => {}; # Lexical scoped variable stash
302 26 has statements => []; # Exexcutable code statements
303 26 has data => []; # Data section scoped to this function
304  
305 26 my $outer = {};
306 573 ▶sub outer { @_ == 1 ? $outer->{$_[0]} : ($outer->{$_[0]} = $_[1]) }
Subroutine outer: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 537 36 573
307  
308 857 ▶sub getvar {
Subroutine getvar: called CC=3 SCAR=11.0
309 857 my ($self, $name) = @_;
310 857 ▶ while ($self) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self) 1296 63 1359
311 1296 ▶ if (my $object = $self->namespace->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $object = $self->namespace->{$name}) 794 502 1296
312 794 return $object;
313 }
314 502 $self = $self->outer;
315 }
316 63 undef;
317 }
318  
319 394 ▶sub setvar {
Subroutine setvar: called CC=1 SCAR=0.0
320 394 my ($self, $name, $value) = @_;
321 394 $self->namespace->{$name} = $value;
322 }
323  
324 0 ▶sub forgetvar {
Subroutine forgetvar: not called CC=1 SCAR=6.9
325 0 my ($self, $name) = @_;
326 0 delete $self->namespace->{$name};
327 }
328  
329 #-----------------------------------------------------------------------------
330 package TestML1::Assignment;
331  
332 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
333  
334 26 has name => ();
335 26 has expr => ();
336  
337 #-----------------------------------------------------------------------------
338 package TestML1::Statement;
339  
340 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
341  
342 26 has expr => ();
343 26 has assert => ();
344 26 has points => ();
345  
346 #-----------------------------------------------------------------------------
347 package TestML1::Expression;
348  
349 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
350  
351 26 has calls => [];
352  
353 #-----------------------------------------------------------------------------
354 package TestML1::Assertion;
355  
356 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
357  
358 26 has name => ();
359 26 has expr => ();
360  
361 #-----------------------------------------------------------------------------
362 package TestML1::Call;
363  
364 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
365  
366 26 has name => ();
367 26 has args => ();
368  
369 #-----------------------------------------------------------------------------
370 package TestML1::Callable;
371  
372 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
373 26 has value => ();
374  
375 #-----------------------------------------------------------------------------
376 package TestML1::Block;
377  
378 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
379  
380 26 has label => '';
381 26 has points => {};
382  
383 #-----------------------------------------------------------------------------
384 package TestML1::Point;
385  
386 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
387  
388 26 has name => ();
389  
390 #-----------------------------------------------------------------------------
391 package TestML1::Object;
392  
393 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
394  
395 26 has value => ();
396  
397 8 ▶sub type {
Subroutine type: called CC=2 SCAR=7.1
398 8 my $type = ref($_[0]);
399 8 ▶ $type =~ s/^TestML1::// or die "Can't find type of '$type'";
Branch: 1 branch
BranchTrueFalseTotal
$type =~ s/^TestML1::// or die "Can't find type of '${type}'" 8 0 8
400 8 return $type;
401 }
402  
403 0 ▶sub str { die "Cast from ${\ $_[0]->type} to Str is not supported" }
Subroutine str: not called CC=1 SCAR=6.9
404 0 ▶sub num { die "Cast from ${\ $_[0]->type} to Num is not supported" }
Subroutine num: not called CC=1 SCAR=6.9
405 0 ▶sub bool { die "Cast from ${\ $_[0]->type} to Bool is not supported" }
Subroutine bool: not called CC=1 SCAR=6.9
406 0 ▶sub list { die "Cast from ${\ $_[0]->type} to List is not supported" }
Subroutine list: not called CC=1 SCAR=6.9
407 0 ▶sub none { $TestML1::Constant::None }
Subroutine none: not called CC=1 SCAR=6.9
408  
409 #-----------------------------------------------------------------------------
410 package TestML1::Str;
411  
412 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
413 26 extends 'TestML1::Object';
414  
415 215 ▶sub str { $_[0] }
Subroutine str: called CC=1 SCAR=0.0
416 0 ▶sub num { TestML1::Num->new(
Subroutine num: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->value =~ /^-?\d+(?:\.\d+)$/ ? : 0 0 0
417 value => ($_[0]->value =~ /^-?\d+(?:\.\d+)$/ ? ($_[0]->value + 0) : 0),
418 )}
419 5 ▶sub bool {
Subroutine bool: called CC=2 SCAR=6.9
420 5 ▶ length($_[0]->value) ? $TestML1::Constant::True : $TestML1::Constant::False
Branch: 1 branch
BranchTrueFalseTotal
length $_[0]->value ? : 4 1 5
421 }
422 0 ▶sub list { TestML1::List->new(value => [split //, $_[0]->value]) }
Subroutine list: not called CC=1 SCAR=6.9
423  
424 #-----------------------------------------------------------------------------
425 package TestML1::Num;
426  
427 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
428 26 extends 'TestML1::Object';
429  
430 12 ▶sub str { TestML1::Str->new(value => $_[0]->value . "") }
Subroutine str: called CC=1 SCAR=0.0
431 0 ▶sub num { $_[0] }
Subroutine num: not called CC=1 SCAR=6.9
432 5 ▶sub bool { ($_[0]->value != 0) ? $TestML1::Constant::True : $TestML1::Constant::False }
Subroutine bool: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->value != 0 ? : 4 1 5
433 0 ▶sub list {
Subroutine list: not called CC=1 SCAR=6.9
434 0 my $list = [];
435 0 $#{$list} = int($_[0]) -1;
436 0 TestML1::List->new(value =>$list);
437 }
438  
439 #-----------------------------------------------------------------------------
440 package TestML1::Bool;
441  
442 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
443 26 extends 'TestML1::Object';
444  
445 0 ▶sub str { TestML1::Str->new(value => $_[0]->value ? "1" : "") }
Subroutine str: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->value ? : 0 0 0
446 0 ▶sub num { TestML1::Num->new(value => $_[0]->value ? 1 : 0) }
Subroutine num: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->value ? : 0 0 0
447 16 ▶sub bool { $_[0] }
Subroutine bool: called CC=1 SCAR=0.0
448  
449 #-----------------------------------------------------------------------------
450 package TestML1::List;
451  
452 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
453 26 extends 'TestML1::Object';
454 26 has value => [];
455 40 ▶sub list { $_[0] }
Subroutine list: called CC=1 SCAR=0.0
456 72 ▶sub push {
Subroutine push: called CC=1 SCAR=0.0
457 72 my ($self, $elem) = @_;
458 72 push @{$self->value}, $elem;
459 }
460  
461 #-----------------------------------------------------------------------------
462 package TestML1::None;
463  
464 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
465 26 extends 'TestML1::Object';
466  
467 0 ▶sub str { TestML1::Str->new(value => '') }
Subroutine str: not called CC=1 SCAR=6.9
468 0 ▶sub num { TestML1::Num->new(value => 0) }
Subroutine num: not called CC=1 SCAR=6.9
469 2 ▶sub bool { $TestML1::Constant::False }
Subroutine bool: called CC=1 SCAR=0.0
470 0 ▶sub list { TestML1::List->new(value => []) }
Subroutine list: not called CC=1 SCAR=6.9
471  
472 #-----------------------------------------------------------------------------
473 package TestML1::Native;
474  
475 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
476 26 extends 'TestML1::Object';
477  
478 #-----------------------------------------------------------------------------
479 package TestML1::Error;
480  
481 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
482 26 extends 'TestML1::Object';
483  
484 #-----------------------------------------------------------------------------
485 package TestML1::Constant;
486  
487 26 our $True = TestML1::Bool->new(value => 1);
488 26 our $False = TestML1::Bool->new(value => 0);
489 26 our $None = TestML1::None->new;
490  
491 26 1;
« TestML1/Compiler/Lite.pm ↑ Summary TestML1/Runtime/TAP.pm »