blib/lib/self.pm

filter: Statementstmt 89.8% 53 / 59 Branchbran 75.0% 18 / 24 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 88.1% 89 / 101 CC 14 SCAR 20.9
CC
14
Cov
86%
_check
14.7
_args
3.0
BEGIN
1.0
CRAP 8.1
↑ Summary
1 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package self;
5 17 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 17 our $VERSION = '0.36';
8 17 ▶use Sub::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 17 ▶use B::Hooks::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 17 my $NO_SELF;
13  
14 18 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
15 18 my ($class) = @_;
16 18 my $caller = caller;
17  
18 18 B::Hooks::Parser::setup();
19  
20 18 my $linestr = B::Hooks::Parser::get_linestr();
21 18 my $offset = B::Hooks::Parser::get_linestr_offset();
22 18 substr($linestr, $offset, 0) = 'use B::OPCheck const => check => \&self::_check;';
23 18 B::Hooks::Parser::set_linestr($linestr);
24  
25 18 my $exporter = Sub::Exporter::build_exporter({
26 into_level => 1,
27 exports => [qw(self args)],
28 groups => { default => [ -all ] }
29 });
30 18 $exporter->(@_);
31 }
32  
33 1 ▶sub unimport {
Subroutine unimport: called CC=1 SCAR=0.0
34 1 my ($class) = @_;
35 1 my $caller = caller;
36 1 $NO_SELF = 1;
37 }
38  
39 351 ▶sub _check {
Subroutine _check: called CC=12 SCAR=26.9
40 351 my $op = shift;
41 351 my $caller = caller;
42 351 ▶ return if $NO_SELF;
Branch: 1 branch
BranchTrueFalseTotal
if $NO_SELF 14 337 351
43 337 ▶ return unless ref($op->gv) eq 'B::PV';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $op->gv eq "B::PV" 34 303 337
44  
45 303 my $linestr = B::Hooks::Parser::get_linestr;
46 303 my $offset = B::Hooks::Parser::get_linestr_offset;
47 303 my $line = substr($linestr, $offset);
48  
49 303 my $code = 'my($self,@args)=@_;';
50  
51 # This cover cases like:
52 # sub foo { ... }
53 # Offset is at the first '{' because subroutine name is also a "const"
54 303 ▶ if (substr($linestr, $offset, 1) eq '{') {
Branch: 3 branches
BranchTrueFalseTotal
if (substr($linestr, $offset, 1) eq '{') { } 88 215 303
elsif (substr($linestr, $offset, 3) eq 'sub') { } 0 215 215
elsif (index($linestr, 'sub') != -1) { } 57 158 215
55 88 ▶ if (substr($linestr, 0, $offset) =~ m/sub\s\S+\s*\z/x ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($linestr, 0, $offset) =~ /sub\s\S+\s*\z/x) 57 31 88
56 57 ▶ if (index($line, "{$code") < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($line, "{$code") == -1) 49 8 57
57 49 substr($linestr, $offset + 1, 0) = $code;
58 49 B::Hooks::Parser::set_linestr($linestr);
59 }
60 }
61 }
62 elsif (substr($linestr, $offset, 3) eq 'sub') {
63 0 ▶ if ($line =~ m/^sub\s.*{ /x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^sub\s.*{ /x) 0 0 0
64 0 ▶ if (index($line, "{$code") < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($line, "{$code") == -1) 0 0 0
65 0 substr($linestr, $offset + index($line, '{') + 1, 0) = $code;
66 0 B::Hooks::Parser::set_linestr($linestr);
67 }
68 }
69 }
70  
71 # This elsif block handles:
72 # sub foo
73 # {
74 # ...
75 # }
76 elsif (index($linestr, 'sub') >= 0) {
77 57 $offset += B::Hooks::Toke::skipspace($offset);
78 57 ▶ if ($linestr =~ /(sub.*?\n\s*{)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($linestr =~ /(sub.*?\n\s*{)/) 2 55 57
79 2 my $pos = index($linestr, $1);
80 2 ▶ if ($pos + length($1) - 1 == $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos + length($1) - 1 == $offset) 0 2 2
81 0 substr($linestr, $offset + 1, 0) = $code;
82 0 B::Hooks::Parser::set_linestr($linestr);
83 }
84 }
85 }
86 }
87  
88 78 ▶sub _args {
Subroutine _args: called CC=3 SCAR=11.0
89 78 my $level = 2;
90 78 my @c = ();
91 package DB;
92 78 ▶ @c = caller($level++)
Branch: 1 branch
BranchTrueFalseTotal
!defined($c[3]) || $c[3] eq "(eval)" and do { @c = caller $level++ } 109 78 187
Condition100%3/3
not defined $c[3] or $c[3] eq "(eval)"
l!l&&r!l&&!r
783178
MC/DC100%2/2
not defined $c[3] or $c[3] eq "(eval)"
not defined $c[3] $c[3] eq "(eval)"
Truth table100%3/3
not(A) or B
A= not defined $c[3]B= $c[3] eq "(eval)"
ABresult
1X1
011
000
93 while !defined($c[3]) || $c[3] eq '(eval)';
94 78 return @DB::args;
95 }
96  
97 67 ▶sub self {
Subroutine self: called CC=1 SCAR=0.0
Pod documented
98 67 (_args)[0];
99 }
100  
101 11 ▶sub args {
Subroutine args: called CC=1 SCAR=0.0
Pod documented
102 11 my @a = _args;
103 11 return @a[1..$#a];
104 }
105  
106 17 1;
107  
108 __END__
↑ Summary