blib/lib/Pugs/Emitter/Grammar/Perl5.pm

filter: Statementstmt 20.3% 11 / 54 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 60.0% 3 / 5 Podpod 100% 1 / 1 totaltotal 12.8% 15 / 117 CC 24 SCAR 51.2
CC
24
Cov
11%
_prune_actions
240.0
emit
110.0
BEGIN
1.0
CRAP 168.0
« blib/lib/Pugs/Emitter/Rule/Perl5/Ratchet.pm ↑ Summary blib/lib/Pugs/Emitter/Rule/Perl6/Ratchet.pm »
1 package Pugs::Emitter::Grammar::Perl5;
2  
3 15 our $VERSION = '0.28';
4  
5 #use Smart::Comments;
6 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Pugs::Emitter::Rule::Perl5::Ratchet;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # for safe mode
11 0 ▶sub _prune_actions {
Subroutine _prune_actions: not called CC=15 SCAR=54.8
12 0 my ($ast) = @_;
13 0 ▶ while (my ($key, $node) = each %$ast) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$ast) 0 0 0
14 0 ▶ next if $key =~ /^_/ or !ref $node;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^_/ or not ref $node 0 0 0
Condition0%0/3
$key =~ /^_/ or not ref $node
l!l&&r!l&&!r
000
MC/DC0%0/2
$key =~ /^_/ or not ref $node
$key =~ /^_/ not ref $node
Truth table0%0/3
A or not(B)
A= $key =~ /^_/B= not ref $node
ABresult
1X1
011
000
15 #warn $key;
16 0 ▶ if ($key eq 'closure') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "closure") 0 0 0
17 #die "Found closures!";
18 0 ▶ next if ref $node ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $node ne "HASH" 0 0 0
19 0 my $code = $node->{closure};
20 0 ▶ if ($code and !ref $code and $code =~ /\w+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code and not ref $code and $code =~ /\w+/) 0 0 0
Condition0%0/6
$code and not ref $code and $code =~ /\w+/
!ll&&!rl&&r
000
$code and not ref $code
!ll&&!rl&&r
000
MC/DC0%0/3
$code and not ref $code and $code =~ /\w+/
$code not ref $code $code =~ /\w+/
Truth table0%0/4
A and not(B) and C
A= $codeB= not ref $codeC= $code =~ /\w+/
ABCresult
0XX0
10X0
1100
1111
21 0 die "ERROR: code blocks not allowed in safe mode: \"$code\"\n";
22 }
23 }
24 0 ▶ if (ref $node) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node) 0 0 0
25 0 my $ref = ref $node;
26 0 ▶ if ($ref eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if ($ref eq 'HASH') { } 0 0 0
elsif ($ref eq 'ARRAY') { } 0 0 0
27 0 _prune_actions($node);
28 } elsif ($ref eq 'ARRAY') {
29 0 for my $child (@$node) {
30 0 ▶ if (ref $child and ref $child eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $child and ref $child eq "HASH") 0 0 0
Condition0%0/3
ref $child and ref $child eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $child and ref $child eq "HASH"
ref $child ref $child eq "HASH"
Truth table0%0/3
A and B
A= ref $childB= ref $child eq "HASH"
ABresult
0X0
100
111
31 0 _prune_actions($child);
32 }
33 }
34 }
35 }
36 }
37 }
38  
39 0 ▶sub emit {
Subroutine emit: not called CC=10 SCAR=47.0
Pod documented
40 0 my $ast = shift;
41 0 my $opts = shift;
42 0 ▶ $opts ||= {};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
43 ## $ast
44 0 my ($name, $stmts) = each %$ast;
45 0 my $p5_methods = '';
46 ### $name
47 0 for my $stmt (@$stmts) {
48 0 my $regex = $stmt->();
49 0 my $type = $regex->{type};
50 ## $regex
51 0 ▶ if ($type eq 'block') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "block") 0 0 0
52 0 my $code = $regex->{value};
53 0 ▶ if ($opts->{safe_mode} && $code =~ /\w+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"safe_mode"} and $code =~ /\w+/) 0 0 0
Condition0%0/3
$opts->{"safe_mode"} and $code =~ /\w+/
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"safe_mode"} and $code =~ /\w+/
$opts->{"safe_mode"} $code =~ /\w+/
Truth table0%0/3
A and B
A= $opts->{"safe_mode"}B= $code =~ /\w+/
ABresult
0X0
100
111
54 0 die "ERROR: verbatim Perl 5 blocks not allowed in safe mode: \"$code\"\n";
55 }
56 0 $p5_methods .= <<"_EOC_";
57 # Code block from grammar spec
58 $code
59  
60 _EOC_
61 0 next;
62 }
63 ### struct: $regex->{name}
64 ## regex AST: $regex->{ast}
65 0 my $params = {};
66 0 ▶ if ($type eq 'rule') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "rule") 0 0 0
67 0 $params->{sigspace} = 1;
68 }
69 0 my $body;
70  
71 0 my $ast = $regex->{ast};
72 0 ▶ if ($opts->{safe_mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"safe_mode"}) 0 0 0
73 0 _prune_actions($ast);
74 }
75  
76 0 ▶ if ($type eq 'regex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'regex') { } 0 0 0
77 0 $body = Pugs::Emitter::Rule::Perl5::emit(
78 'Pugs::Grammar::Rule',
79 $ast,
80 )
81 } else {
82 0 $body = Pugs::Emitter::Rule::Perl5::Ratchet::emit(
83 'Pugs::Grammar::Rule',
84 $ast,
85 $params,
86 );
87 }
88 0 $body =~ s/^/ /gm;
89 0 $p5_methods .= <<_EOC_;
90 # $regex->{type} $regex->{name}
91 *$regex->{name} =
92 $body;
93  
94 _EOC_
95 }
96 # bootstrap the regex parser itself:
97 0 ▶ my $prefix = $name eq 'Pugs::Grammar::Rule' ?
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'Pugs::Grammar::Rule' ? : 0 0 0
98 "#" : '';
99 0 return <<"_EOC_";
100 package $name;
101  
102 ${prefix}use base 'Pugs::Grammar::Base';
103  
104 use Pugs::Runtime::Match;
105 use Pugs::Runtime::Regex;
106 use Pugs::Runtime::Tracer ();
107  
108 $p5_methods
109  
110 1;
111 _EOC_
112 }
113  
114 15 1;
115 __END__
« blib/lib/Pugs/Emitter/Rule/Perl5/Ratchet.pm ↑ Summary blib/lib/Pugs/Emitter/Rule/Perl6/Ratchet.pm »