X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-REPL.git;a=blobdiff_plain;f=lib%2FDevel%2FREPL%2FScript.pm;h=dcc62454218448fc34989d0cf9937aa1d1ed3715;hp=fec8e7df02d7d027f470e75240a6fafa428dff21;hb=moo;hpb=9b7bfb6ac233dca407f12db47aa8dda7c9c1d338 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);