3 package Devel::REPL::Plugin::Commands;
5 use Devel::REPL::Plugin;
6 use Scalar::Util qw(weaken);
8 use namespace::autoclean;
9 our $COMMAND_INSTALLER;
11 has 'command_set' => (
13 lazy => 1, default => sub { {} }
18 $self->load_plugin('Packages');
19 unless ($self->can('setup_commands')) {
20 $self->meta->add_method('setup_commands' => sub {});
26 $self->setup_commands;
29 after 'setup_commands' => sub {
32 $self->command_set->{load_plugin} = sub {
34 sub { $self->load_plugin(@_); };
38 sub command_installer {
40 my $command_set = $self->command_set;
41 my %command_subs = map {
42 ($_ => $command_set->{$_}->($self));
46 foreach my $command (keys %command_subs) {
48 no warnings 'redefine';
49 *{"${package}::${command}"} = $command_subs{$command};
54 around 'mangle_line' => sub {
55 my ($orig, $self) = (shift, shift);
57 my $name = '$'.__PACKAGE__.'::COMMAND_INSTALLER';
58 return qq{BEGIN { ${name}->(__PACKAGE__) }\n}.$self->$orig(@_);
61 around 'compile' => sub {
62 my ($orig, $self) = (shift, shift);
63 local $COMMAND_INSTALLER = $self->command_installer;
73 Devel::REPL::Plugin::Commands - Generic command creation plugin using injected functions