TestML1/Compiler.pm

filter: Statementstmt 93.8% 61 / 65 Branchbran 63.1% 24 / 38 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 77.3% 92 / 119 CC 23 SCAR 31.5
CC
23
Cov
81%
preprocess
27.2
compile
2.0
BEGIN
1.0
CRAP 23.3
« TestML1/Setup.pm ↑ Summary TestML1/Compiler/Lite.pm »
1 26 ▶use TestML1::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package TestML1::Compiler;
4  
5 26 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 26 has code => ();
8 26 has data => ();
9 26 has text => ();
10 26 has directives => ();
11 26 has function => ();
12  
13 25 ▶sub compile {
Subroutine compile: called CC=2 SCAR=7.1
Pod undocumented
14 25 my ($self, $input) = @_;
15  
16 25 $self->preprocess($input, 'top');
17 25 $self->compile_code;
18 25 $self->compile_data;
19  
20 25 ▶ if ($self->directives->{DumpAST}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->directives->{"DumpAST"}) 0 25 25
21 0 XXX($self->function);
22 }
23  
24 25 $self->function->namespace->{TestML} = $self->directives->{TestML};
25  
26 25 $self->function->outer(TestML1::Function->new);
27 25 return $self->function;
28 }
29  
30 27 ▶sub preprocess {
Subroutine preprocess: called CC=22 SCAR=33.0
Pod undocumented
31 27 my ($self, $input, $top) = @_;
32  
33 27 my @parts = split /^((?:\%\w+.*|\#.*|\ *)\n)/m, $input;
34 27 $input = '';
35  
36 $self->{directives} = {
37 27 TestML => '',
38 DataMarker => '',
39 BlockMarker => '===',
40 PointMarker => '---',
41 };
42  
43 27 my $order_error = 0;
44 27 for my $part (@parts) {
45 437 ▶ next unless length($part);
Branch: 1 branch
BranchTrueFalseTotal
unless length $part 98 339 437
46 339 ▶ if ($part =~ /^(\#.*|\ *)\n/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part =~ /^(\#.*|\ *)\n/) 179 160 339
47 179 $input .= "\n";
48 179 next;
49 }
50 160 ▶ if ($part =~ /^%(\w+)\s*(.*?)\s*\n/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part =~ /^%(\w+)\s*(.*?)\s*\n/) { } 29 131 160
51 29 my ($directive, $value) = ($1, $2);
52 29 $input .= "\n";
53 29 ▶ if ($directive eq 'TestML') {
Branch: 1 branch
BranchTrueFalseTotal
if ($directive eq "TestML") 25 4 29
54 25 ▶ die "Invalid TestML directive"
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^\d+\.\d+\.\d+$/ 0 25 25
55 unless $value =~ /^\d+\.\d+\.\d+$/;
56 die "More than one TestML directive found"
57 25 ▶ if $self->directives->{TestML};
Branch: 1 branch
BranchTrueFalseTotal
if $self->directives->{"TestML"} 0 25 25
58 $self->directives->{TestML} =
59 25 TestML1::Str->new(value => $value);
60 25 next;
61 }
62 4 ▶ $order_error = 1 unless $self->directives->{TestML};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->directives->{"TestML"} 0 4 4
63 4 ▶ if ($directive eq 'Include') {
Branch: 3 branches
BranchTrueFalseTotal
if ($directive eq 'Include') { } 2 2 4
elsif ($directive =~ /^(DataMarker|BlockMarker|PointMarker)$/) { } 2 0 2
elsif ($directive =~ /^(DebugPegex|DumpAST)$/) { } 0 0 0
64 2 ▶ my $runtime = $TestML1::Runtime::Singleton
Branch: 1 branch
BranchTrueFalseTotal
my $runtime = $TestML1::Runtime::Singleton or die "Can't process Include. No runtime available" 2 0 2
65 or die "Can't process Include. No runtime available";
66 2 my $include = ref($self)->new;
67 2 $include->preprocess($runtime->read_testml_file($value));
68 2 $input .= $include->text;
69 $self->directives->{DataMarker} =
70 2 $include->directives->{DataMarker};
71 $self->directives->{BlockMarker} =
72 2 $include->directives->{BlockMarker};
73 $self->directives->{PointMarker} =
74 2 $include->directives->{PointMarker};
75 die "Can't define %TestML in an Included file"
76 2 ▶ if $include->directives->{TestML};
Branch: 1 branch
BranchTrueFalseTotal
if $include->directives->{"TestML"} 0 2 2
77 }
78 elsif ($directive =~ /^(DataMarker|BlockMarker|PointMarker)$/) {
79 2 $self->directives->{$directive} = $value;
80 }
81 elsif ($directive =~ /^(DebugPegex|DumpAST)$/) {
82 0 ▶ $value = 1 unless length($value);
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 0 0 0
83 0 $self->directives->{$directive} = $value;
84 }
85 else {
86 0 die "Unknown TestML directive '$directive'";
87 }
88 }
89 else {
90 131 ▶ $order_error = 1 if $input and not $self->directives->{TestML};
Branch: 1 branch
BranchTrueFalseTotal
if $input and not $self->directives->{"TestML"} 0 131 131
Condition66%2/3
$input and not $self->directives->{"TestML"}
!ll&&!rl&&r
21290
MC/DC0%0/2
$input and not $self->directives->{"TestML"}
$input not $self->directives->{"TestML"}
Truth table66%2/3
A and not(B)
A= $inputB= not $self->directives->{"TestML"}
ABresult
0X0
100
111
91 131 $input .= $part;
92 }
93 }
94  
95 27 ▶ if ($top) {
Branch: 1 branch
BranchTrueFalseTotal
if ($top) { } 25 2 27
96 die "No TestML directive found"
97 25 ▶ unless $self->directives->{TestML};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->directives->{"TestML"} 0 25 25
98 25 ▶ die "%TestML directive must be the first (non-comment) statement"
Branch: 1 branch
BranchTrueFalseTotal
if $order_error 0 25 25
99 if $order_error;
100  
101 my $DataMarker =
102 $self->directives->{DataMarker} ||=
103 25 ▶ $self->directives->{BlockMarker};
Condition33%1/3
$self->directives->{"DataMarker"} ||= $self->directives->{"BlockMarker"}
l!l&&r!l&&!r
0250
MC/DC0%0/2
$self->directives->{"DataMarker"} ||= $self->directives->{"BlockMarker"}
$self->directives->{"DataMarker"} $self->directives->{"BlockMarker"}
Truth table33%1/3
A ||= B
A= $self->directives->{"DataMarker"}B= $self->directives->{"BlockMarker"}
ABresult
1X1
011
000
104 25 ▶ if ((my $split = index($input, "\n$DataMarker")) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $split = index($input, "\n$DataMarker")) >= 0) { } 17 8 25
105 17 $self->{code} = substr($input, 0, $split + 1);
106 17 $self->{data} = substr($input, $split + 1);
107 }
108 else {
109 8 $self->{code} = $input;
110 8 $self->{data} = '';
111 }
112 }
113 else {
114 2 $self->{text} = $input;
115 }
116 }
117  
118 26 1;
« TestML1/Setup.pm ↑ Summary TestML1/Compiler/Lite.pm »