From: tokuhirom Date: Sun, 17 Feb 2013 10:23:46 +0000 (+0900) Subject: Move to Moo for fast bootstrapping. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-REPL.git;a=commitdiff_plain;h=moo Move to Moo for fast bootstrapping. --- diff --git a/Makefile.PL b/Makefile.PL index 3713ac4..0191678 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -19,15 +19,16 @@ requires 'File::Spec'; 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, diff --git a/lib/Devel/REPL.pm b/lib/Devel/REPL.pm index 73a0feb..b0fce4e 100644 --- a/lib/Devel/REPL.pm +++ b/lib/Devel/REPL.pm @@ -1,15 +1,30 @@ 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, @@ -366,15 +381,11 @@ L >= 0.74 =item * -L >= 0.0009 - -=item * - L >= 0.18 =item * -L +L =item * diff --git a/lib/Devel/REPL/Error.pm b/lib/Devel/REPL/Error.pm index ac7bc05..69c975f 100644 --- a/lib/Devel/REPL/Error.pm +++ b/lib/Devel/REPL/Error.pm @@ -1,18 +1,19 @@ #!/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, ); diff --git a/lib/Devel/REPL/Meta/Plugin.pm b/lib/Devel/REPL/Meta/Plugin.pm deleted file mode 100644 index cd544c7..0000000 --- a/lib/Devel/REPL/Meta/Plugin.pm +++ /dev/null @@ -1,23 +0,0 @@ -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; diff --git a/lib/Devel/REPL/Overview.pod b/lib/Devel/REPL/Overview.pod index 2e643bf..8b68f4d 100644 --- a/lib/Devel/REPL/Overview.pod +++ b/lib/Devel/REPL/Overview.pod @@ -231,10 +231,10 @@ take a look at it: 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 diff --git a/lib/Devel/REPL/Plugin.pm b/lib/Devel/REPL/Plugin.pm index 6ef18e5..69927c0 100644 --- a/lib/Devel/REPL/Plugin.pm +++ b/lib/Devel/REPL/Plugin.pm @@ -2,13 +2,6 @@ package Devel::REPL::Plugin; 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; diff --git a/lib/Devel/REPL/Plugin/B/Concise.pm b/lib/Devel/REPL/Plugin/B/Concise.pm index 71b97be..fe2fc37 100644 --- a/lib/Devel/REPL/Plugin/B/Concise.pm +++ b/lib/Devel/REPL/Plugin/B/Concise.pm @@ -7,7 +7,7 @@ use B::Concise (); B::Concise::compileOpts(qw(-nobanner)); -use namespace::autoclean; +use namespace::sweep; sub BEFORE_PLUGIN { my $self = shift; diff --git a/lib/Devel/REPL/Plugin/Colors.pm b/lib/Devel/REPL/Plugin/Colors.pm index 46b30bb..bdc5e94 100644 --- a/lib/Devel/REPL/Plugin/Colors.pm +++ b/lib/Devel/REPL/Plugin/Colors.pm @@ -2,16 +2,16 @@ package Devel::REPL::Plugin::Colors; 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 { diff --git a/lib/Devel/REPL/Plugin/Commands.pm b/lib/Devel/REPL/Plugin/Commands.pm index 04aa22e..689e656 100644 --- a/lib/Devel/REPL/Plugin/Commands.pm +++ b/lib/Devel/REPL/Plugin/Commands.pm @@ -3,7 +3,7 @@ package Devel::REPL::Plugin::Commands; use Devel::REPL::Plugin; use Scalar::Util qw(weaken); -use namespace::autoclean; +use namespace::sweep; use vars qw($COMMAND_INSTALLER); has 'command_set' => ( @@ -15,7 +15,9 @@ sub BEFORE_PLUGIN { 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 { }; } } diff --git a/lib/Devel/REPL/Plugin/Completion.pm b/lib/Devel/REPL/Plugin/Completion.pm index dcc1837..e87521c 100644 --- a/lib/Devel/REPL/Plugin/Completion.pm +++ b/lib/Devel/REPL/Plugin/Completion.pm @@ -2,30 +2,31 @@ package Devel::REPL::Plugin::Completion; 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 }, diff --git a/lib/Devel/REPL/Plugin/CompletionDriver/Globals.pm b/lib/Devel/REPL/Plugin/CompletionDriver/Globals.pm index 5dbed24..3133a29 100644 --- a/lib/Devel/REPL/Plugin/CompletionDriver/Globals.pm +++ b/lib/Devel/REPL/Plugin/CompletionDriver/Globals.pm @@ -1,6 +1,6 @@ package Devel::REPL::Plugin::CompletionDriver::Globals; use Devel::REPL::Plugin; -use namespace::autoclean; +use namespace::sweep; sub BEFORE_PLUGIN { my $self = shift; diff --git a/lib/Devel/REPL/Plugin/CompletionDriver/INC.pm b/lib/Devel/REPL/Plugin/CompletionDriver/INC.pm index 40f147a..99f4105 100644 --- a/lib/Devel/REPL/Plugin/CompletionDriver/INC.pm +++ b/lib/Devel/REPL/Plugin/CompletionDriver/INC.pm @@ -2,7 +2,7 @@ package Devel::REPL::Plugin::CompletionDriver::INC; use Devel::REPL::Plugin; use File::Next; use File::Spec; -use namespace::autoclean; +use namespace::sweep; sub BEFORE_PLUGIN { my $self = shift; diff --git a/lib/Devel/REPL/Plugin/CompletionDriver/Keywords.pm b/lib/Devel/REPL/Plugin/CompletionDriver/Keywords.pm index 5078a14..b4ca656 100644 --- a/lib/Devel/REPL/Plugin/CompletionDriver/Keywords.pm +++ b/lib/Devel/REPL/Plugin/CompletionDriver/Keywords.pm @@ -1,7 +1,7 @@ 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; diff --git a/lib/Devel/REPL/Plugin/CompletionDriver/LexEnv.pm b/lib/Devel/REPL/Plugin/CompletionDriver/LexEnv.pm index 827efb9..2142be3 100644 --- a/lib/Devel/REPL/Plugin/CompletionDriver/LexEnv.pm +++ b/lib/Devel/REPL/Plugin/CompletionDriver/LexEnv.pm @@ -1,6 +1,6 @@ package Devel::REPL::Plugin::CompletionDriver::LexEnv; use Devel::REPL::Plugin; -use namespace::autoclean; +use namespace::sweep; sub BEFORE_PLUGIN { my $self = shift; diff --git a/lib/Devel/REPL/Plugin/CompletionDriver/Methods.pm b/lib/Devel/REPL/Plugin/CompletionDriver/Methods.pm index 88afd5e..bbbb0f4 100644 --- a/lib/Devel/REPL/Plugin/CompletionDriver/Methods.pm +++ b/lib/Devel/REPL/Plugin/CompletionDriver/Methods.pm @@ -1,6 +1,8 @@ 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; @@ -51,14 +53,13 @@ around complete => sub { # 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; diff --git a/lib/Devel/REPL/Plugin/CompletionDriver/Turtles.pm b/lib/Devel/REPL/Plugin/CompletionDriver/Turtles.pm index 1472e37..e447c98 100644 --- a/lib/Devel/REPL/Plugin/CompletionDriver/Turtles.pm +++ b/lib/Devel/REPL/Plugin/CompletionDriver/Turtles.pm @@ -1,6 +1,6 @@ package Devel::REPL::Plugin::CompletionDriver::Turtles; use Devel::REPL::Plugin; -use namespace::autoclean; +use namespace::sweep; sub BEFORE_PLUGIN { my $self = shift; diff --git a/lib/Devel/REPL/Plugin/DumpHistory.pm b/lib/Devel/REPL/Plugin/DumpHistory.pm index 3983e77..e9b8ff8 100644 --- a/lib/Devel/REPL/Plugin/DumpHistory.pm +++ b/lib/Devel/REPL/Plugin/DumpHistory.pm @@ -1,7 +1,7 @@ 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 }; diff --git a/lib/Devel/REPL/Plugin/FancyPrompt.pm b/lib/Devel/REPL/Plugin/FancyPrompt.pm index ce0225a..25f322d 100644 --- a/lib/Devel/REPL/Plugin/FancyPrompt.pm +++ b/lib/Devel/REPL/Plugin/FancyPrompt.pm @@ -1,7 +1,7 @@ package Devel::REPL::Plugin::FancyPrompt; use Devel::REPL::Plugin; -use namespace::autoclean; +use namespace::sweep; has 'fancy_prompt' => ( is => 'rw', lazy => 1, @@ -34,7 +34,7 @@ has 'fancy_continuation_prompt' => ( ); has 'lines_read' => ( - is => 'rw', lazy => 1, default => 0, + is => 'rw', lazy => 1, default => sub { 0 }, ); around 'prompt' => sub { diff --git a/lib/Devel/REPL/Plugin/FindVariable.pm b/lib/Devel/REPL/Plugin/FindVariable.pm index cf2fd77..66eb920 100644 --- a/lib/Devel/REPL/Plugin/FindVariable.pm +++ b/lib/Devel/REPL/Plugin/FindVariable.pm @@ -1,7 +1,8 @@ package Devel::REPL::Plugin::FindVariable; use Devel::REPL::Plugin; -use namespace::autoclean; +use namespace::sweep; +use Package::Stash; sub find_variable { my ($self, $name) = @_; @@ -21,11 +22,11 @@ sub find_variable { : '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; diff --git a/lib/Devel/REPL/Plugin/History.pm b/lib/Devel/REPL/Plugin/History.pm index 8d77d05..4f68a5b 100644 --- a/lib/Devel/REPL/Plugin/History.pm +++ b/lib/Devel/REPL/Plugin/History.pm @@ -1,10 +1,11 @@ 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 { [] } ); diff --git a/lib/Devel/REPL/Plugin/Interrupt.pm b/lib/Devel/REPL/Plugin/Interrupt.pm index 7d64611..efd5e77 100644 --- a/lib/Devel/REPL/Plugin/Interrupt.pm +++ b/lib/Devel/REPL/Plugin/Interrupt.pm @@ -2,7 +2,7 @@ package Devel::REPL::Plugin::Interrupt; 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); diff --git a/lib/Devel/REPL/Plugin/LexEnv.pm b/lib/Devel/REPL/Plugin/LexEnv.pm index e9a297f..8d9d370 100644 --- a/lib/Devel/REPL/Plugin/LexEnv.pm +++ b/lib/Devel/REPL/Plugin/LexEnv.pm @@ -1,8 +1,9 @@ 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; @@ -10,7 +11,7 @@ sub BEFORE_PLUGIN { } has 'lexical_environment' => ( - isa => 'Lexical::Persistence', + isa => InstanceOf('Lexical::Persistence'), is => 'rw', required => 1, lazy => 1, @@ -18,7 +19,7 @@ has 'lexical_environment' => ( ); has '_hints' => ( - isa => "ArrayRef", + isa => ArrayRef, is => "rw", predicate => '_has_hints', ); diff --git a/lib/Devel/REPL/Plugin/MultiLine/PPI.pm b/lib/Devel/REPL/Plugin/MultiLine/PPI.pm index e9a2c2d..a224421 100644 --- a/lib/Devel/REPL/Plugin/MultiLine/PPI.pm +++ b/lib/Devel/REPL/Plugin/MultiLine/PPI.pm @@ -2,7 +2,7 @@ package Devel::REPL::Plugin::MultiLine::PPI; use Devel::REPL::Plugin; use PPI; -use namespace::autoclean; +use namespace::sweep; has 'continuation_prompt' => ( is => 'rw', required => 1, lazy => 1, diff --git a/lib/Devel/REPL/Plugin/NewlineHack.pm b/lib/Devel/REPL/Plugin/NewlineHack.pm index 03421cf..d7efbb6 100644 --- a/lib/Devel/REPL/Plugin/NewlineHack.pm +++ b/lib/Devel/REPL/Plugin/NewlineHack.pm @@ -7,7 +7,7 @@ package Devel::REPL::Plugin::NewlineHack; use Devel::REPL::Plugin; -use namespace::autoclean; +use namespace::sweep; warn < ( - 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 { diff --git a/lib/Devel/REPL/Plugin/OutputCache.pm b/lib/Devel/REPL/Plugin/OutputCache.pm index 404c0b6..924f089 100644 --- a/lib/Devel/REPL/Plugin/OutputCache.pm +++ b/lib/Devel/REPL/Plugin/OutputCache.pm @@ -1,19 +1,20 @@ 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, ); diff --git a/lib/Devel/REPL/Plugin/PPI.pm b/lib/Devel/REPL/Plugin/PPI.pm index a53c767..18b2322 100644 --- a/lib/Devel/REPL/Plugin/PPI.pm +++ b/lib/Devel/REPL/Plugin/PPI.pm @@ -6,7 +6,7 @@ use Devel::REPL::Plugin; use PPI; use PPI::Dumper; -use namespace::autoclean; +use namespace::sweep; sub BEFORE_PLUGIN { my $self = shift; diff --git a/lib/Devel/REPL/Plugin/Packages.pm b/lib/Devel/REPL/Plugin/Packages.pm index 616d320..060ce65 100644 --- a/lib/Devel/REPL/Plugin/Packages.pm +++ b/lib/Devel/REPL/Plugin/Packages.pm @@ -1,14 +1,15 @@ 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 ); diff --git a/lib/Devel/REPL/Plugin/Peek.pm b/lib/Devel/REPL/Plugin/Peek.pm index c8a871f..5988b15 100644 --- a/lib/Devel/REPL/Plugin/Peek.pm +++ b/lib/Devel/REPL/Plugin/Peek.pm @@ -5,7 +5,7 @@ use Devel::REPL::Plugin; use Devel::Peek qw(Dump); -use namespace::autoclean; +use namespace::sweep; sub BEFORE_PLUGIN { my $self = shift; diff --git a/lib/Devel/REPL/Plugin/Refresh.pm b/lib/Devel/REPL/Plugin/Refresh.pm index f89f5d7..5dfd4da 100644 --- a/lib/Devel/REPL/Plugin/Refresh.pm +++ b/lib/Devel/REPL/Plugin/Refresh.pm @@ -1,7 +1,7 @@ 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 diff --git a/lib/Devel/REPL/Plugin/ShowClass.pm b/lib/Devel/REPL/Plugin/ShowClass.pm index 9f79853..0cd5238 100644 --- a/lib/Devel/REPL/Plugin/ShowClass.pm +++ b/lib/Devel/REPL/Plugin/ShowClass.pm @@ -1,10 +1,12 @@ 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 {{}} ); diff --git a/lib/Devel/REPL/Plugin/Timing.pm b/lib/Devel/REPL/Plugin/Timing.pm index c9248b7..8715839 100644 --- a/lib/Devel/REPL/Plugin/Timing.pm +++ b/lib/Devel/REPL/Plugin/Timing.pm @@ -2,7 +2,7 @@ package Devel::REPL::Plugin::Timing; use Devel::REPL::Plugin; use Time::HiRes 'time'; -use namespace::autoclean; +use namespace::sweep; around 'eval' => sub { my $orig = shift; diff --git a/lib/Devel/REPL/Plugin/Turtles.pm b/lib/Devel/REPL/Plugin/Turtles.pm index a8fd9df..9781cc2 100644 --- a/lib/Devel/REPL/Plugin/Turtles.pm +++ b/lib/Devel/REPL/Plugin/Turtles.pm @@ -3,25 +3,30 @@ use Devel::REPL::Plugin; 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) = @_; diff --git a/lib/Devel/REPL/Profile.pm b/lib/Devel/REPL/Profile.pm index c86b2ed..91d6927 100644 --- a/lib/Devel/REPL/Profile.pm +++ b/lib/Devel/REPL/Profile.pm @@ -1,6 +1,6 @@ package Devel::REPL::Profile; -use Moose::Role; +use Moo::Role; requires 'apply_profile'; @@ -12,8 +12,8 @@ Devel::REPL::Profile package Devel::REPL::Profile::MyProject; - use Moose; - use namespace::autoclean; + use Moo; + use namespace::sweep; with 'Devel::REPL::Profile'; diff --git a/lib/Devel/REPL/Profile/Default.pm b/lib/Devel/REPL/Profile/Default.pm index dc00876..b9ec1b1 100644 --- a/lib/Devel/REPL/Profile/Default.pm +++ b/lib/Devel/REPL/Profile/Default.pm @@ -1,7 +1,7 @@ package Devel::REPL::Profile::Default; -use Moose; -use namespace::autoclean; +use Moo; +use namespace::sweep; with 'Devel::REPL::Profile'; diff --git a/lib/Devel/REPL/Profile/Minimal.pm b/lib/Devel/REPL/Profile/Minimal.pm index 6740fbe..febb5ee 100644 --- a/lib/Devel/REPL/Profile/Minimal.pm +++ b/lib/Devel/REPL/Profile/Minimal.pm @@ -1,7 +1,7 @@ package Devel::REPL::Profile::Minimal; -use Moose; -use namespace::autoclean; +use Moo; +use namespace::sweep; with 'Devel::REPL::Profile'; diff --git a/lib/Devel/REPL/Script.pm b/lib/Devel/REPL/Script.pm index fec8e7d..dcc6245 100644 --- a/lib/Devel/REPL/Script.pm +++ b/lib/Devel/REPL/Script.pm @@ -1,30 +1,45 @@ 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); @@ -34,7 +49,7 @@ sub BUILD { 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);