requires 'Term::ReadLine';
# rest
-requires 'Moose' => '0.93';
-requires 'MooseX::Object::Pluggable' => '0.0009';
-requires 'MooseX::Getopt' => '0.18';
-requires 'namespace::autoclean';
+requires 'Moo' => '0';
+requires 'MooX::Types::MooseLike' => '0.19';
+requires 'namespace::sweep';
requires 'File::HomeDir';
requires 'Task::Weaken';
requires 'B::Concise';
requires 'Term::ANSIColor';
requires 'Devel::Peek';
+requires 'Package::Stash';
+requires 'Module::Runtime';
feature 'Completion plugin - extensible tab completion',
-default => 1,
package Devel::REPL;
use Term::ReadLine;
-use Moose;
-use namespace::autoclean;
+use Moo;
+use namespace::sweep;
use 5.008001; # backwards compat, doesn't warn like 5.8.1
our $VERSION = '1.003014';
-with 'MooseX::Object::Pluggable';
-
use Devel::REPL::Error;
+use Scalar::Util qw/blessed/;
+use Module::Runtime ();
+
+sub load_plugin {
+ my ($self, $plugin) = @_;
+ $plugin = "Devel::REPL::Plugin::$plugin";
+ Module::Runtime::use_module("$plugin");
+ if (my $pre = $plugin->can('BEFORE_PLUGIN')) {
+ $pre->($self, $plugin);
+ }
+ Moo::Role->apply_roles_to_package(
+ 'Devel::REPL', $plugin
+ );
+ if (my $pre = $plugin->can('AFTER_PLUGIN')) {
+ $pre->($self, $plugin);
+ }
+}
has 'term' => (
is => 'rw', required => 1,
=item *
-L<MooseX::Object::Pluggable> >= 0.0009
-
-=item *
-
L<MooseX::Getopt> >= 0.18
=item *
-L<namespace::autoclean>
+L<namespace::sweep>
=item *
#!/usr/bin/perl
package Devel::REPL::Error;
-use Moose;
+use Moo;
+use MooX::Types::MooseLike::Base qw(Str Object AnyOf);
# FIXME get nothingmuch to refactor and release his useful error object
has type => (
- isa => "Str",
+ isa => Str,
is => "ro",
required => 1,
);
has message => (
- isa => "Str|Object",
+ isa => AnyOf[Str, Object],
is => "ro",
required => 1,
);
+++ /dev/null
-package Devel::REPL::Meta::Plugin;
-
-use Moose;
-
-extends 'Moose::Meta::Role';
-
-before 'apply' => sub {
- my ($self, $other) = @_;
- return unless $other->isa('Devel::REPL');
- if (my $pre = $self->get_method('BEFORE_PLUGIN')) {
- $pre->body->($other, $self);
- }
-};
-
-after 'apply' => sub {
- my ($self, $other) = @_;
- return unless $other->isa('Devel::REPL');
- if (my $pre = $self->get_method('AFTER_PLUGIN')) {
- $pre->body->($other, $self);
- }
-};
-
-1;
package Devel::REPL::Profile::Default;
- use Moose; ### advanced OOP system for Perl
+ use Moo; ### advanced OOP system for Perl
### keep those exports/imports out of our namespace
- use namespace::autoclean;
+ use namespace::sweep;
with 'Devel::REPL::Profile'; ## seem perldoc Muse
use strict;
use warnings;
-use Devel::REPL::Meta::Plugin;
-use Moose::Role ();
-
-sub import {
- my $target = caller;
- Devel::REPL::Meta::Plugin->initialize($target);
- goto &Moose::Role::import;
-}
+use parent qw/Moo::Role/;
1;
B::Concise::compileOpts(qw(-nobanner));
-use namespace::autoclean;
+use namespace::sweep;
sub BEFORE_PLUGIN {
my $self = shift;
use Devel::REPL::Plugin;
use Term::ANSIColor;
-use namespace::autoclean;
+use namespace::sweep;
has normal_color => (
is => 'rw', lazy => 1,
- default => 'green',
+ default => sub { 'green' },
);
has error_color => (
is => 'rw', lazy => 1,
- default => 'bold red',
+ default => sub { 'bold red' },
);
around format_error => sub {
use Devel::REPL::Plugin;
use Scalar::Util qw(weaken);
-use namespace::autoclean;
+use namespace::sweep;
use vars qw($COMMAND_INSTALLER);
has 'command_set' => (
my ($self) = @_;
$self->load_plugin('Packages');
unless ($self->can('setup_commands')) {
- $self->meta->add_method('setup_commands' => sub {});
+ my $pkg = ref $self || $self;
+ no strict 'refs';
+ *{"${pkg}::setup_commands"} = sub { };
}
}
use Devel::REPL::Plugin;
use Scalar::Util 'weaken';
use PPI;
-use namespace::autoclean;
+use namespace::sweep;
+use MooX::Types::MooseLike::Base qw(ArrayRef Int Bool);
has current_matches => (
is => 'rw',
- isa => 'ArrayRef',
+ isa => ArrayRef,
lazy => 1,
default => sub { [] },
);
has match_index => (
is => 'rw',
- isa => 'Int',
+ isa => Int,
lazy => 1,
default => sub { 0 },
);
has no_term_class_warning => (
- isa => "Bool",
+ isa => Bool,
is => "rw",
- default => 0,
+ default => sub { 0 },
);
has do_readline_filename_completion => ( # so default is no if Completion loaded
- isa => "Bool",
+ isa => Bool,
is => "rw",
lazy => 1,
default => sub { 0 },
package Devel::REPL::Plugin::CompletionDriver::Globals;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
sub BEFORE_PLUGIN {
my $self = shift;
use Devel::REPL::Plugin;
use File::Next;
use File::Spec;
-use namespace::autoclean;
+use namespace::sweep;
sub BEFORE_PLUGIN {
my $self = shift;
package Devel::REPL::Plugin::CompletionDriver::Keywords;
use Devel::REPL::Plugin;
use B::Keywords qw/@Functions @Barewords/;
-use namespace::autoclean;
+use namespace::sweep;
sub BEFORE_PLUGIN {
my $self = shift;
package Devel::REPL::Plugin::CompletionDriver::LexEnv;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
sub BEFORE_PLUGIN {
my $self = shift;
package Devel::REPL::Plugin::CompletionDriver::Methods;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
+use Package::Stash;
+use Scalar::Util qw(blessed);
sub BEFORE_PLUGIN {
my $self = shift;
# now we have $class->$incomplete
- my $metaclass = Class::MOP::Class->initialize($class);
+ my $metaclass = Package::Stash->new($class);
my $re = qr/^\Q$incomplete/;
return $orig->(@_),
grep { $_ =~ $re }
- map { $_->name }
- $metaclass->get_all_methods;
+ $metaclass->list_all_symbols('CODE');
};
1;
package Devel::REPL::Plugin::CompletionDriver::Turtles;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
sub BEFORE_PLUGIN {
my $self = shift;
package Devel::REPL::Plugin::DumpHistory;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
## Seems to be a sequence issue with requires
# requires qw{ history };
package Devel::REPL::Plugin::FancyPrompt;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
has 'fancy_prompt' => (
is => 'rw', lazy => 1,
);
has 'lines_read' => (
- is => 'rw', lazy => 1, default => 0,
+ is => 'rw', lazy => 1, default => sub { 0 },
);
around 'prompt' => sub {
package Devel::REPL::Plugin::FindVariable;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
+use Package::Stash;
sub find_variable {
my ($self, $name) = @_;
: 'main';
my $package = $name =~ s/^(.*)(::|')// ? $1 : $default_package;
- my $meta = Class::MOP::Class->initialize($package);
+ my $meta = Package::Stash->new($package);
- # Class::MOP::Package::has_package_symbol method *requires* a sigil
- return unless length($sigil) and $meta->has_package_symbol("$sigil$name");
- $meta->get_package_symbol("$sigil$name");
+ # Package::Stash::has_symbol method *requires* a sigil
+ return unless length($sigil) and $meta->has_symbol("$sigil$name");
+ $meta->get_symbol("$sigil$name");
}
1;
package Devel::REPL::Plugin::History;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
+use MooX::Types::MooseLike::Base qw(ArrayRef);
has 'history' => (
- isa => 'ArrayRef', is => 'rw', required => 1, lazy => 1,
+ isa => ArrayRef, is => 'rw', required => 1, lazy => 1,
default => sub { [] }
);
use Devel::REPL::Plugin;
use Sys::SigAction qw(set_sig_handler);
-use namespace::autoclean;
+use namespace::sweep;
around 'run' => sub {
my ($orig, $self) = (shift, shift);
package Devel::REPL::Plugin::LexEnv;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
use Lexical::Persistence;
+use MooX::Types::MooseLike::Base qw(InstanceOf ArrayRef);
sub BEFORE_PLUGIN {
my $self = shift;
}
has 'lexical_environment' => (
- isa => 'Lexical::Persistence',
+ isa => InstanceOf('Lexical::Persistence'),
is => 'rw',
required => 1,
lazy => 1,
);
has '_hints' => (
- isa => "ArrayRef",
+ isa => ArrayRef,
is => "rw",
predicate => '_has_hints',
);
use Devel::REPL::Plugin;
use PPI;
-use namespace::autoclean;
+use namespace::sweep;
has 'continuation_prompt' => (
is => 'rw', required => 1, lazy => 1,
package Devel::REPL::Plugin::NewlineHack;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
warn <<EOW;
No longer required, extra newline automatically produced for Gnu readline
package Devel::REPL::Plugin::Nopaste;
use Devel::REPL::Plugin;
-use Moose::Util::TypeConstraints;
-use namespace::autoclean;
+use namespace::sweep;
use Scalar::Util qw(blessed);
+use MooX::Types::MooseLike::Base qw(Str);
sub BEFORE_PLUGIN {
my $self = shift;
}
has complete_session => (
- metaclass => 'String',
is => 'rw',
- isa => 'Str',
+ isa => Str,
lazy => 1,
- default => '',
- handles => {
- add_to_session => 'append',
- },
+ default => sub { '' },
);
+sub add_to_session {
+ my $self = shift;
+ my $session = $self->complete_session;
+ $session .= $_ for @_;
+ $self->complete_session($session);
+}
+
has paste_title => (
is => 'rw',
- isa => 'Str',
+ isa => Str,
lazy => 1,
- default => 'Devel::REPL session',
+ default => sub { 'Devel::REPL session' },
);
has 'nopaste_format' => (
is => 'rw',
- isa => enum( [qw[ comment_code comment_output ]] ),
+ isa => sub { $_[0] =~ qr[^(?:comment_code|comment_output)$] },
lazy => 1,
- default => 'comment_output',
+ default => sub { 'comment_output' },
);
before eval => sub {
package Devel::REPL::Plugin::OutputCache;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
+use MooX::Types::MooseLike::Base qw(ArrayRef Bool);
has output_cache => (
is => 'rw',
- isa => 'ArrayRef',
+ isa => ArrayRef,
default => sub { [] },
lazy => 1,
);
has warned_about_underscore => (
is => 'rw',
- isa => 'Bool',
- default => 0,
+ isa => Bool,
+ default => sub { 0 },
lazy => 1,
);
use PPI;
use PPI::Dumper;
-use namespace::autoclean;
+use namespace::sweep;
sub BEFORE_PLUGIN {
my $self = shift;
package Devel::REPL::Plugin::Packages;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
+use MooX::Types::MooseLike::Base qw(Str);
use vars qw($PKG_SAVE);
has 'current_package' => (
- isa => 'Str',
+ isa => Str,
is => 'rw',
- default => 'Devel::REPL::Plugin::Packages::DefaultScratchpad',
+ default => sub { 'Devel::REPL::Plugin::Packages::DefaultScratchpad' },
lazy => 1
);
use Devel::Peek qw(Dump);
-use namespace::autoclean;
+use namespace::sweep;
sub BEFORE_PLUGIN {
my $self = shift;
package Devel::REPL::Plugin::Refresh;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
use Module::Refresh;
# before evaluating the code, ask Module::Refresh to refresh
package Devel::REPL::Plugin::ShowClass;
use Devel::REPL::Plugin;
-use namespace::autoclean;
+use namespace::sweep;
+use MooX::Types::MooseLike::Base qw(HashRef);
+use Class::MOP;
has 'metaclass_cache' => (
is => 'ro',
- isa => 'HashRef',
+ isa => HashRef,
lazy => 1,
default => sub {{}}
);
use Devel::REPL::Plugin;
use Time::HiRes 'time';
-use namespace::autoclean;
+use namespace::sweep;
around 'eval' => sub {
my $orig = shift;
use Scalar::Util qw(reftype);
-use namespace::autoclean;
+use namespace::sweep;
+use MooX::Types::MooseLike::Base qw(RegexpRef ArrayRef CodeRef AnyOf);
has default_command_prefix => (
- isa => "RegexpRef",
+ isa => RegexpRef,
is => "rw",
+ lazy => 1,
default => sub { qr/\#/ },
);
has turtles_matchers => (
- metaclass => "Collection::Array",
- isa => "ArrayRef[RegexpRef|CodeRef]",
+ isa => ArrayRef[AnyOf[RegexpRef,CodeRef]],
is => "rw",
lazy => 1,
- default => sub { my $prefix = shift->default_command_prefix; [qr/^ $prefix (\w+) \s* (.*) /x] },
- handles => {
- add_turtles_matcher => 'unshift',
+ default => sub {
+ my $prefix = shift->default_command_prefix; [qr/^ $prefix (\w+) \s* (.*) /x]
},
);
+sub add_turtles_matcher {
+ my $self = shift;
+ unshift @{$self->turtles_matchers}, @_;
+}
+
around 'formatted_eval' => sub {
my $next = shift;
my ($self, $line, @args) = @_;
package Devel::REPL::Profile;
-use Moose::Role;
+use Moo::Role;
requires 'apply_profile';
package Devel::REPL::Profile::MyProject;
- use Moose;
- use namespace::autoclean;
+ use Moo;
+ use namespace::sweep;
with 'Devel::REPL::Profile';
package Devel::REPL::Profile::Default;
-use Moose;
-use namespace::autoclean;
+use Moo;
+use namespace::sweep;
with 'Devel::REPL::Profile';
package Devel::REPL::Profile::Minimal;
-use Moose;
-use namespace::autoclean;
+use Moo;
+use namespace::sweep;
with 'Devel::REPL::Profile';
package Devel::REPL::Script;
-use Moose;
+use Moo;
use Devel::REPL;
use File::HomeDir;
use File::Spec;
use vars qw($CURRENT_SCRIPT);
-use namespace::autoclean;
-
-with 'MooseX::Getopt';
+use namespace::sweep;
+use Getopt::Long;
+use MooX::Types::MooseLike::Base qw(Str InstanceOf);
+use Module::Load ();
+use Carp qw(confess);
has 'rcfile' => (
- is => 'ro', isa => 'Str', required => 1, default => sub { 'repl.rc' },
+ is => 'rw',
+ isa => Str,
+ required => 1,
);
has 'profile' => (
- is => 'ro',
- isa => 'Str',
+ is => 'rw',
+ isa => Str,
required => 1,
- default => sub { $ENV{DEVEL_REPL_PROFILE} || 'Default' },
);
has '_repl' => (
- is => 'ro', isa => 'Devel::REPL', required => 1,
+ is => 'ro', isa => InstanceOf('Devel::REPL'), required => 1,
default => sub { Devel::REPL->new() }
);
+sub new_with_options {
+ my ($class) = @_;
+
+ my $rcfile = 'repl.rc';
+ my $profile = $ENV{DEVEL_REPL_PROFILE} || 'Default';
+ GetOptions(
+ 'rcfile=s' => \$rcfile,
+ 'profile=s' => \$profile,
+ );
+ $class->new(profile => $profile, rcfile => $rcfile);
+}
+
sub BUILD {
my ($self) = @_;
$self->load_profile($self->profile);
sub load_profile {
my ($self, $profile) = @_;
$profile = "Devel::REPL::Profile::${profile}" unless $profile =~ /::/;
- Class::MOP::load_class($profile);
+ Module::Load::load($profile);
confess "Profile class ${profile} doesn't do 'Devel::REPL::Profile'"
unless $profile->does('Devel::REPL::Profile');
$profile->new->apply_profile($self->_repl);