3 package Devel::REPL::Plugin::Commands;
5 our $VERSION = '1.003027';
7 use Devel::REPL::Plugin;
8 use Scalar::Util qw(weaken);
9 use namespace::autoclean;
11 our $COMMAND_INSTALLER;
13 has 'command_set' => (
15 lazy => 1, default => sub { {} }
20 $self->load_plugin('Packages');
21 unless ($self->can('setup_commands')) {
22 $self->meta->add_method('setup_commands' => sub {});
28 $self->setup_commands;
31 after 'setup_commands' => sub {
34 $self->command_set->{load_plugin} = sub {
36 sub { $self->load_plugin(@_); };
40 sub command_installer {
42 my $command_set = $self->command_set;
43 my %command_subs = map {
44 ($_ => $command_set->{$_}->($self));
48 foreach my $command (keys %command_subs) {
50 no warnings 'redefine';
51 *{"${package}::${command}"} = $command_subs{$command};
56 around 'mangle_line' => sub {
57 my ($orig, $self) = (shift, shift);
59 my $name = '$'.__PACKAGE__.'::COMMAND_INSTALLER';
60 return qq{BEGIN { ${name}->(__PACKAGE__) }\n}.$self->$orig(@_);
63 around 'compile' => sub {
64 my ($orig, $self) = (shift, shift);
65 local $COMMAND_INSTALLER = $self->command_installer;
75 Devel::REPL::Plugin::Commands - Generic command creation plugin using injected functions