1package Reply::Plugin::Packages; 2our $AUTHORITY = 'cpan:DOY'; 3$Reply::Plugin::Packages::VERSION = '0.42'; 4use strict; 5use warnings; 6# ABSTRACT: persist the current package between lines 7 8use base 'Reply::Plugin'; 9 10 11sub new { 12 my $class = shift; 13 my %opts = @_; 14 15 my $self = $class->SUPER::new(@_); 16 $self->{package} = $opts{default_package} || 'main'; 17 18 return $self; 19} 20 21sub mangle_line { 22 my $self = shift; 23 my ($line) = @_; 24 25 my $package = __PACKAGE__; 26 return <<LINE; 27$line 28; 29BEGIN { 30 \$${package}::package = __PACKAGE__; 31} 32LINE 33} 34 35sub compile { 36 my $self = shift; 37 my ($next, $line, %args) = @_; 38 39 my @result = $next->($line, %args); 40 41 # XXX it'd be nice to avoid using globals here, but we can't use 42 # eval_closure's environment parameter since we need to access the 43 # information in a BEGIN block 44 $self->{package} = our $package; 45 46 return @result; 47} 48 49sub package { 50 my $self = shift; 51 return $self->{package}; 52} 53 541; 55 56__END__ 57 58=pod 59 60=encoding UTF-8 61 62=head1 NAME 63 64Reply::Plugin::Packages - persist the current package between lines 65 66=head1 VERSION 67 68version 0.42 69 70=head1 SYNOPSIS 71 72 ; .replyrc 73 [Packages] 74 default_package = My::Scratchpad 75 76=head1 DESCRIPTION 77 78This plugin persists the state of the current package between lines. This 79allows lines such as C<package Foo;> in the Reply shell to do what you'd 80expect. The C<default_package> configuration option can also be used to set the 81initial package to use when Reply starts up. 82 83=head1 AUTHOR 84 85Jesse Luehrs <doy@tozt.net> 86 87=head1 COPYRIGHT AND LICENSE 88 89This software is Copyright (c) 2016 by Jesse Luehrs. 90 91This is free software, licensed under: 92 93 The MIT (X11) License 94 95=cut 96