1 package Devel::REPL::Plugin::Commands;
3 use Devel::REPL::Plugin;
4 use Scalar::Util qw(weaken);
6 use namespace::clean -except => [ 'meta' ];
7 use vars qw($COMMAND_INSTALLER);
10 is => 'ro', required => 1,
11 lazy => 1, default => sub { {} }
16 unless ($self->can('setup_commands')) {
17 $self->meta->add_method('setup_commands' => sub {});
23 $self->setup_commands;
26 after 'setup_commands' => sub {
29 $self->command_set->{load_plugin} = sub { $self->load_plugin(@_); };
32 sub command_installer {
34 my %command_set = %{$self->command_set};
37 foreach my $command (keys %command_set) {
39 no warnings 'redefine';
40 *{"${package}::${command}"} = $command_set{$command};
45 around 'mangle_line' => sub {
46 my ($orig, $self) = (shift, shift);
48 my $name = '$'.__PACKAGE__.'::COMMAND_INSTALLER';
49 return qq{BEGIN { ${name}->(__PACKAGE__) }\n}.$self->$orig(@_);
52 around 'compile' => sub {
53 my ($orig, $self) = (shift, shift);
54 local $COMMAND_INSTALLER = $self->command_installer;