| 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
| |||||||||||||||||||||||||||||
| 43 | 337 | ▶ | return unless ref($op->gv) eq 'B::PV'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 55 | 88 | ▶ | if (substr($linestr, 0, $offset) =~ m/sub\s\S+\s*\z/x ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 57 | ▶ | if (index($line, "{$code") < 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if (index($line, "{$code") < 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 79 | 2 | my $pos = index($linestr, $1); | |||||||||||||||||||||||||||
| 80 | 2 | ▶ | if ($pos + length($1) - 1 == $offset) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
not defined $c[3] or $c[3] eq "(eval)"
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)"
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||