blib/lib/B/CodeLines.pm

filter: Statementstmt 19.6% 12 / 61 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 25.0% 3 / 12 Podpod 0.0% 0 / 4 totaltotal 11.7% 15 / 128 CC 22 SCAR 47.7
CC
22
Cov
11%
sequence
240.0
walk_topdown
42.0
main
6.0
CRAP 117.8
↑ Summary examples/dolines.pl »
1 package B::CodeLines;
2 # Copyright (C) 2012 Rocky Bernstein. All rights reserved.
3 # This program is free software; you can redistribute and/or modify it
4 # under the same terms as Perl itself.
5  
6 # B::Concise was used as a guide for how to write this.
7  
8 1 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.1';
11  
12 1 ▶use B qw(class main_start main_root main_cv OPf_KIDS walksymtable);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 my $current_file;
15  
16 # use Enbugger;
17 0 ▶sub main {
Subroutine main: not called CC=2 SCAR=17.9
Pod undocumented
18 0 sequence(main_start);
19 # Enbugger->stop;
20 0 ▶ return if class(main_root) eq "NULL";
Branch: 1 branch
BranchTrueFalseTotal
if B::CodeLines::class(main_root()) eq "NULL" 0 0 0
21 walk_topdown(main_root,
22 0 ▶ sub { $_[0]->codelines($_[1]) }, 0);
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 # print "+++1 $current_file\n";
24 # walksymtable(\%main::, 'print_subs', 1, 'B::Lines::');
25  
26 }
27  
28 0 ▶sub compile {
Subroutine compile: not called CC=1 SCAR=6.9
Pod undocumented
29 0 ▶ return sub { main(); }
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 }
31  
32 0 ▶sub walk_topdown {
Subroutine walk_topdown: not called CC=6 SCAR=37.4
Pod undocumented
33 0 my($op, $sub, $level) = @_;
34 0 $sub->($op, $level);
35 0 ▶ if ($op->flags & OPf_KIDS) {
Branch: 2 branches
BranchTrueFalseTotal
if ($op->flags & 4) { } 0 0 0
elsif (B::CodeLines::class($op) eq 'PMOP') { } 0 0 0
36 0 ▶ for (my $kid = $op->first; $$kid; $kid = $kid->sibling) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$kid) 0 0 0
37 0 walk_topdown($kid, $sub, $level + 1);
38 }
39 }
40 elsif (class($op) eq "PMOP") {
41 0 my $maybe_root = $op->pmreplroot;
42 0 ▶ if (ref($maybe_root) and $maybe_root->isa("B::OP")) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $maybe_root and $maybe_root->isa("B::OP")) 0 0 0
Condition0%0/3
ref $maybe_root and $maybe_root->isa("B::OP")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $maybe_root and $maybe_root->isa("B::OP")
ref $maybe_root $maybe_root->isa("B::OP")
Truth table0%0/3
A and B
A= ref $maybe_rootB= $maybe_root->isa("B::OP")
ABresult
0X0
100
111
43 # It really is the root of the replacement, not something
44 # else stored here for lack of space elsewhere
45 0 walk_topdown($maybe_root, $sub, $level + 1);
46 }
47 }
48 }
49  
50 # The structure of this routine is purposely modeled after op.c's peep()
51 0 ▶sub sequence {
Subroutine sequence: not called CC=15 SCAR=54.8
Pod undocumented
52 0 my($op) = @_;
53 0 my $oldop = 0;
54 0 ▶ return if class($op) eq "NULL";
Branch: 1 branch
BranchTrueFalseTotal
if B::CodeLines::class($op) eq "NULL" 0 0 0
55 0 ▶ for (; $$op; $op = $op->next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$op) 0 0 0
56 0 my $name = $op->name;
57 0 ▶ if ($name =~ /^(null|scalar|lineseq|scope)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^(null|scalar|lineseq|scope)$/) { } 0 0 0
58 0 ▶ next if $oldop and $ {$op->next};
Branch: 1 branch
BranchTrueFalseTotal
if $oldop and ${$op->next;} 0 0 0
Condition0%0/3
$oldop and ${$op->next;}
!ll&&!rl&&r
000
MC/DC0%0/2
$oldop and ${$op->next;}
$oldop ${$op->next;}
Truth table0%0/3
A and B
A= $oldopB= ${$op->next;}
ABresult
0X0
100
111
59 } else {
60 0 ▶ if (class($op) eq "LOGOP") {
Branch: 3 branches
BranchTrueFalseTotal
if (B::CodeLines::class($op) eq 'LOGOP') { } 0 0 0
elsif (B::CodeLines::class($op) eq 'LOOP') { } 0 0 0
elsif ($name eq 'subst' and ${$op->pmreplstart;}) { } 0 0 0
61 0 my $other = $op->other;
62 0 ▶ $other = $other->next while $other->name eq "null";
Branch: 1 branch
BranchTrueFalseTotal
$other->name eq "null" and do { $other = $other->next } 0 0 0
63 0 sequence($other);
64 } elsif (class($op) eq "LOOP") {
65 0 my $redoop = $op->redoop;
66 0 ▶ $redoop = $redoop->next while $redoop->name eq "null";
Branch: 1 branch
BranchTrueFalseTotal
$redoop->name eq "null" and do { $redoop = $redoop->next } 0 0 0
67 0 sequence($redoop);
68 0 my $nextop = $op->nextop;
69 0 ▶ $nextop = $nextop->next while $nextop->name eq "null";
Branch: 1 branch
BranchTrueFalseTotal
$nextop->name eq "null" and do { $nextop = $nextop->next } 0 0 0
70 0 sequence($nextop);
71 0 my $lastop = $op->lastop;
72 0 ▶ $lastop = $lastop->next while $lastop->name eq "null";
Branch: 1 branch
BranchTrueFalseTotal
$lastop->name eq "null" and do { $lastop = $lastop->next } 0 0 0
73 0 sequence($lastop);
74 0 ▶ } elsif ($name eq "subst" and $ {$op->pmreplstart}) {
Condition0%0/3
$name eq "subst" and ${$op->pmreplstart;}
!ll&&!rl&&r
000
MC/DC0%0/2
$name eq "subst" and ${$op->pmreplstart;}
$name eq "subst" ${$op->pmreplstart;}
Truth table0%0/3
A and B
A= $name eq "subst"B= ${$op->pmreplstart;}
ABresult
0X0
100
111
75 0 my $replstart = $op->pmreplstart;
76 0 ▶ $replstart = $replstart->next while $replstart->name eq "null";
Branch: 1 branch
BranchTrueFalseTotal
$replstart->name eq "null" and do { $replstart = $replstart->next } 0 0 0
77 0 sequence($replstart);
78 }
79 }
80 0 $oldop = $op;
81 }
82 }
83  
84 0 ▶sub B::OP::codelines {
Subroutine codelines: not called CC=2 SCAR=17.9
85 0 my($op) = @_;
86 0 ▶ if ('COP' eq class($op)) {
Branch: 1 branch
BranchTrueFalseTotal
if ("COP" eq B::CodeLines::class($op)) 0 0 0
87 0 $current_file = $op->file;
88 0 printf "%s\n", $op->line;
89 }
90 }
91  
92 sub B::GV::print_subs
93 0 ▶ {
Subroutine print_subs: not called CC=1 SCAR=6.9
94 0 my($gv) = @_;
95 # Should bail if $gv->FILE ne $B::Lines::current_file.
96 0 print $gv->NAME(), " ", $gv->FILE(), "\n";
97 0 eval {
98 walk_topdown($gv->CV->START,
99 0 ▶ sub { $_[0]->codelines($_[1]) }, 0)
Subroutine __ANON__: not called CC=1 SCAR=6.9
100 };
101 };
102  
103  
104 1 1;
↑ Summary examples/dolines.pl »