3 package Devel::REPL::Plugin::Packages;
5 our $VERSION = '1.003027';
7 use Devel::REPL::Plugin;
8 use namespace::autoclean;
12 has 'current_package' => (
15 default => 'Devel::REPL::Plugin::Packages::DefaultScratchpad',
19 around 'wrap_as_sub' => sub {
21 my ($self, @args) = @_;
22 my $line = $self->$orig(@args);
23 # prepend package def before sub { ... }
24 return q!package !.$self->current_package.qq!;\n${line}!;
27 around 'mangle_line' => sub {
29 my ($self, @args) = @_;
30 my $line = $self->$orig(@args);
31 # add a BEGIN block to set the package around at the end of the sub
32 # without mangling the return value (we save it off into a global)
34 ; BEGIN { $Devel::REPL::Plugin::Packages::PKG_SAVE = __PACKAGE__; }';
38 after 'execute' => sub {
40 # if we survived execution successfully, save the new package out the global
41 $self->current_package($PKG_SAVE) if defined $PKG_SAVE;
44 around 'eval' => sub {
46 my ($self, @args) = @_;
47 # localise the $PKG_SAVE global in case of nested evals
49 return $self->$orig(@args);
52 package Devel::REPL::Plugin::Packages::DefaultScratchpad;
54 # declare empty scratchpad package for cleanliness
62 Devel::REPL::Plugin::Packages - Keep track of which package the user is in