| 1 | package Devel::REPL::Plugin::InProcess; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Devel::REPL::Plugin; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use PadWalker (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use namespace::clean -except => [ 'meta' ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | has '_caller_depth' => ( | |||||||||||||||||||||||||||
| 8 | isa => 'Int', | ||||||||||||||||||||||||||||
| 9 | is => 'rw', | ||||||||||||||||||||||||||||
| 10 | ); | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | has '_package' => ( | |||||||||||||||||||||||||||
| 13 | isa => 'Str', | ||||||||||||||||||||||||||||
| 14 | is => 'rw', | ||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | has '_my_scalars' => ( | |||||||||||||||||||||||||||
| 18 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 19 | is => 'rw', | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | has '_our_scalars' => ( | |||||||||||||||||||||||||||
| 23 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 24 | is => 'rw', | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | has '_lexical_hints' => ( | |||||||||||||||||||||||||||
| 28 | isa => "ArrayRef", | ||||||||||||||||||||||||||||
| 29 | is => "rw", | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 2 | has 'skip_levels' => ( | |||||||||||||||||||||||||||
| 33 | isa => "Int", | ||||||||||||||||||||||||||||
| 34 | is => "rw", | ||||||||||||||||||||||||||||
| 35 | default => 0, | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 1 | ▶ | sub BEFORE_PLUGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEFORE_PLUGIN: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 40 | 1 | $self->load_plugin('LexEnv'); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | around 'execute' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 2 | my ($orig, $_REPL, @args) = @_; | |||||||||||||||||||||||||||
| 45 | 2 | $_REPL->_sync_to_lexenv; | |||||||||||||||||||||||||||
| 46 | 2 | my @res = $_REPL->$orig(@args); | |||||||||||||||||||||||||||
| 47 | 2 | $_REPL->_sync_from_lexenv; | |||||||||||||||||||||||||||
| 48 | 2 | return @res; | |||||||||||||||||||||||||||
| 49 | 2 | }; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # stolen from Devel::REPL::Plugin::Package | ||||||||||||||||||||||||||||
| 52 | 2 | ▶ | around 'wrap_as_sub' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 53 | 2 | my ($orig, $_REPL, @args) = @_; | |||||||||||||||||||||||||||
| 54 | 2 | ▶ | $_REPL->_find_level_and_initialize unless $_REPL->_caller_depth; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 2 | my $line = $_REPL->$orig(@args); | |||||||||||||||||||||||||||
| 56 | 2 | return sprintf "package %s;\n%s", $_REPL->_package, $line; | |||||||||||||||||||||||||||
| 57 | 2 | }; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | ▶ | sub _sync_to_lexenv { | ||||||||||||||||||||||||||
|
Subroutine
_sync_to_lexenv: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 60 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 61 | 2 | my $cxt = $self->lexical_environment->get_context('_'); | |||||||||||||||||||||||||||
| 62 | 2 | my $my = $self->_my_scalars; | |||||||||||||||||||||||||||
| 63 | 2 | my $our = $self->_our_scalars; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | $cxt->{$_} = ${$my->{$_}} for keys %$my; | |||||||||||||||||||||||||||
| 66 | 0 | $cxt->{$_} = ${$our->{$_}} for keys %$our; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 2 | ▶ | sub _sync_from_lexenv { | ||||||||||||||||||||||||||
|
Subroutine
_sync_from_lexenv: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 70 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 71 | 2 | my $cxt = $self->lexical_environment->get_context('_'); | |||||||||||||||||||||||||||
| 72 | 2 | my $my = $self->_my_scalars; | |||||||||||||||||||||||||||
| 73 | 2 | my $our = $self->_our_scalars; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | ${$my->{$_}} = $cxt->{$_} for keys %$my; | |||||||||||||||||||||||||||
| 76 | 0 | ${$our->{$_}} = $cxt->{$_} for keys %$our; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | ▶ | sub _find_level_and_initialize { | ||||||||||||||||||||||||||
|
Subroutine
_find_level_and_initialize: called CC=13 SCAR=28.2
| |||||||||||||||||||||||||||||
| 80 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 81 | 1 | my ($level, $evals, @found_level, @found_eval) = (0, 0); | |||||||||||||||||||||||||||
| 82 | 1 | my $skip = $self->skip_levels; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 1 | for (;; ++$level) { | |||||||||||||||||||||||||||
| 85 | 7 | my ($package, $filename, $line, $subroutine, $hasargs, | |||||||||||||||||||||||||||
| 86 | $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash) = | ||||||||||||||||||||||||||||
| 87 | caller $level; | ||||||||||||||||||||||||||||
| 88 | 7 | ▶ | last if !defined $package; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 6 | ▶ | ++$evals if $subroutine && $subroutine eq '(eval)'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$subroutine and $subroutine eq "(eval)"
MC/DC0%0/2
$subroutine and $subroutine eq "(eval)"
$subroutine
$subroutine eq "(eval)"
Truth table33%1/3
A and B
A= $subroutineB= $subroutine eq "(eval)"
| |||||||||||||||||||||||||||||
| 90 | 6 | ▶ | if ($package =~ /^Devel::REPL\b/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 91 | 3 | @found_level = @found_eval = (); | |||||||||||||||||||||||||||
| 92 | } elsif ($package =~ /^DB\b/) { | ||||||||||||||||||||||||||||
| 93 | # just ignore DB frames | ||||||||||||||||||||||||||||
| 94 | } else { | ||||||||||||||||||||||||||||
| 95 | 3 | push @found_level, $level; | |||||||||||||||||||||||||||
| 96 | 3 | push @found_eval, $evals; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | ▶ | die "Could not find package outside REPL/debugger" unless @found_level; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 1 | ▶ | die "Asked to skip more packages than have been forund" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$skip and $skip >= @found_level
MC/DC0%0/2
$skip and $skip >= @found_level
$skip
$skip >= @found_level
Truth table33%1/3
A and B
A= $skipB= $skip >= @found_level
| |||||||||||||||||||||||||||||
| 102 | if $skip && $skip >= @found_level; | ||||||||||||||||||||||||||||
| 103 | 1 | my ($found_level, $found_eval) = ($found_level[$skip], $found_eval[$skip]); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 1 | my ($package, $filename, $line, $subroutine, $hasargs, | |||||||||||||||||||||||||||
| 106 | $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash) = | ||||||||||||||||||||||||||||
| 107 | caller $found_level; | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | # (+ 1) because caller(0) is the caller package while peek_my(0) are | ||||||||||||||||||||||||||||
| 110 | # the lexicals in the current scope, (- $found_evals) because peek_my | ||||||||||||||||||||||||||||
| 111 | # skips eval frames but caller counts them | ||||||||||||||||||||||||||||
| 112 | 1 | my $my = PadWalker::peek_my($found_level + 1 - $found_eval); | |||||||||||||||||||||||||||
| 113 | 1 | my $our = PadWalker::peek_our($found_level + 1 - $found_eval); | |||||||||||||||||||||||||||
| 114 | 1 | my $lexenv = $self->lexical_environment; | |||||||||||||||||||||||||||
| 115 | 1 | my $cxt; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1 | for my $key (keys %$my) { | |||||||||||||||||||||||||||
| 118 | 3 | ▶ | if ($key =~ /^\$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 3 | $cxt->{$key} = ${$my->{$key}}; | |||||||||||||||||||||||||||
| 120 | } else { | ||||||||||||||||||||||||||||
| 121 | 0 | $cxt->{$key} = $my->{$key}; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | 1 | for my $key (keys %$our) { | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ($key =~ /^\$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | $cxt->{$key} = ${$our->{$key}}; | |||||||||||||||||||||||||||
| 127 | } else { | ||||||||||||||||||||||||||||
| 128 | 0 | $cxt->{$key} = $our->{$key}; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 1 | $lexenv->set_context('_' => $cxt); | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 1 | $self->_caller_depth($found_level); | |||||||||||||||||||||||||||
| 135 | 1 | $self->_package($package); | |||||||||||||||||||||||||||
| 136 | 1 | $self->_lexical_hints([$hints, $hinthash]); | |||||||||||||||||||||||||||
| 137 | $self->_my_scalars({ | ||||||||||||||||||||||||||||
| 138 | 1 | map +($_ => $my->{$_}), grep /^\$/, keys %$my | |||||||||||||||||||||||||||
| 139 | }); | ||||||||||||||||||||||||||||
| 140 | $self->_our_scalars({ | ||||||||||||||||||||||||||||
| 141 | 1 | map +($_ => $our->{$_}), grep /^\$/, keys %$our | |||||||||||||||||||||||||||
| 142 | }); | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 2 | 1; | |||||||||||||||||||||||||||