1 package Devel::REPL::Plugin::Commands;
3 use Devel::REPL::Plugin;
4 use Scalar::Util qw(weaken);
6 use namespace::autoclean;
7 our $COMMAND_INSTALLER;
11 lazy => 1, default => sub { {} }
16 $self->load_plugin('Packages');
17 unless ($self->can('setup_commands')) {
18 $self->meta->add_method('setup_commands' => sub {});
24 $self->setup_commands;
27 after 'setup_commands' => sub {
30 $self->command_set->{load_plugin} = sub {
32 sub { $self->load_plugin(@_); };
36 sub command_installer {
38 my $command_set = $self->command_set;
39 my %command_subs = map {
40 ($_ => $command_set->{$_}->($self));
44 foreach my $command (keys %command_subs) {
46 no warnings 'redefine';
47 *{"${package}::${command}"} = $command_subs{$command};
52 around 'mangle_line' => sub {
53 my ($orig, $self) = (shift, shift);
55 my $name = '$'.__PACKAGE__.'::COMMAND_INSTALLER';
56 return qq{BEGIN { ${name}->(__PACKAGE__) }\n}.$self->$orig(@_);
59 around 'compile' => sub {
60 my ($orig, $self) = (shift, shift);
61 local $COMMAND_INSTALLER = $self->command_installer;
71 Devel::REPL::Plugin::Commands - Generic command creation plugin using injected functions