blib/lib/Pugs/Runtime/Tracer.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 90.0% 18 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 4 totaltotal 88.1% 67 / 76 CC 12 SCAR 18.3
CC
12
Cov
94%
expand_tracing_code
10.0
trace
2.3
trace_end
2.0
CRAP 6.3
« blib/lib/Pugs/Grammar/Base.pm ↑ Summary blib/lib/Pugs/Compiler/Grammar.pm »
1 package Pugs::Runtime::Tracer;
2  
3 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 36 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 #use Smart::Comments;
7  
8 36 our @EXPORT = qw(
9 trace_begin trace_end trace
10 expand_tracing_code
11 );
12  
13 1 ▶sub trace_begin ($$$$) {
Subroutine trace_begin: called CC=1 SCAR=0.0
Pod undocumented
14 1 my ($name, $from, $to, $pos) = @_;
15 1 trace(">>BEGIN $name<< $from..$to at $pos\n");
16 }
17  
18 2 ▶sub trace_end ($$$) {
Subroutine trace_end: called CC=2 SCAR=6.9
Pod undocumented
19 2 my ($name, $res, $pos) = @_;
20 2 ▶ trace(">>END $name<< ", $res ? 'success' : 'fail', " at $pos\n");
Branch: 1 branch
BranchTrueFalseTotal
$res ? : 1 1 2
21 }
22  
23 5 ▶sub trace ($@) {
Subroutine trace: called CC=2 SCAR=8.1
Pod undocumented
24 5 ▶ if (!defined $::PCR_TRACE_FH) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $main::PCR_TRACE_FH) 0 5 5
25 0 $::PCR_TRACE_FH = \*STDOUT;
26 }
27 5 print $::PCR_TRACE_FH @_;
28 }
29  
30 3 ▶sub expand_tracing_code {
Subroutine expand_tracing_code: called CC=10 SCAR=23.0
Pod undocumented
31 3 my $s = shift;
32 3 ▶ open my $in, '<', \$s or die;
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<", \$s or die 3 0 3
33 3 my (@names, $name, $new, @has_pos);
34 3 ▶ while (<$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $in)) 15 2 17
35 15 chomp;
36 15 ▶ if (/\s+## <(\w+)>$/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/\s+## <(\w+)>$/) { } 7 8 15
elsif (/(\s+)## pos: (\d+) (\d+)$/) { } 1 7 8
elsif (m[(\s+)## </(\w+)>$]) { } 6 1 7
37 7 $name = $1;
38 7 push @names, $name;
39 7 push @has_pos, 0;
40 ### begin: $name
41 7 $new .= $_ . "\n";
42 } elsif (/(\s+)## pos: (\d+) (\d+)$/) {
43 1 my ($tab, $from, $to) = ($1, $2, $3);
44 1 $has_pos[-1] = 1;
45 1 $new .= <<"_EOC_";
46 $_
47 $tab do {
48 $tab Pugs::Runtime::Tracer::trace_begin('$name', $from, $to, \$pos);
49 $tab my \$retval =
50 _EOC_
51 } elsif (/(\s+)## <\/(\w+)>$/) {
52 6 my ($tab, $n) = ($1, $2);
53 6 $name = pop @names;
54 6 my $has_pos = pop @has_pos;
55 ### end: $n . "<=>" . $name
56 6 ▶ if (!defined $name || $n ne $name) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $name or $n ne $name) { } 1 5 6
elsif ($has_pos) { } 1 4 5
Condition66%2/3
not defined $name or $n ne $name
l!l&&r!l&&!r
015
MC/DC50%1/2
not defined $name or $n ne $name
not defined $name $n ne $name
Truth table66%2/3
not(A) or B
A= not defined $nameB= $n ne $name
ABresult
1X1
011
000
57 1 die "ERROR: unexpected closing tag </$n>";
58 } elsif ($has_pos) {
59 1 $new .= <<"_EOC_";
60 $_
61 $tab ;
62 $tab Pugs::Runtime::Tracer::trace_end('$name', \$retval, \$pos);
63 $tab \$retval;
64 $tab }
65 _EOC_
66 }
67 5 ▶ if (!$has_pos) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_pos) 4 1 5
68 #warn "No pos info found for <$n>";
69 }
70 } else {
71 1 $new .= $_ . "\n";
72 }
73 }
74 2 return $new;
75 }
76  
77 36 1;
78 __END__
« blib/lib/Pugs/Grammar/Base.pm ↑ Summary blib/lib/Pugs/Compiler/Grammar.pm »