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=277fc91292bd82b092abd0bce0ece59ebaac8a64;hp=dc24a6a822edb03f54fbc192bb12819e59a048e6;hb=4d33251a9f6d375aaafd8aa274743c68dec8f720;hpb=59aedffcb81ce6f4b2c477673fb58aee32138d7e diff --git a/lib/Devel/REPL/Script.pm b/lib/Devel/REPL/Script.pm index dc24a6a..277fc91 100644 --- a/lib/Devel/REPL/Script.pm +++ b/lib/Devel/REPL/Script.pm @@ -4,6 +4,7 @@ use Moose; use Devel::REPL; use File::HomeDir; use File::Spec; +use vars qw($CURRENT_SCRIPT); use namespace::clean -except => [ qw(meta) ]; with 'MooseX::Getopt'; @@ -12,6 +13,10 @@ has 'rcfile' => ( is => 'ro', isa => 'Str', required => 1, default => sub { 'repl.rc' }, ); +has 'profile' => ( + is => 'ro', isa => 'Str', required => 1, default => sub { 'Default' }, +); + has '_repl' => ( is => 'ro', isa => 'Devel::REPL', required => 1, default => sub { Devel::REPL->new() } @@ -19,13 +24,19 @@ has '_repl' => ( sub BUILD { my ($self) = @_; - $self->load_rcfile; + $self->load_profile($self->profile); + $self->load_rcfile($self->rcfile); } -sub load_rcfile { - my ($self) = @_; +sub load_profile { + my ($self, $profile) = @_; + $profile = "Devel::REPL::Profile::${profile}" unless $profile =~ /::/; + Class::MOP::load_class($profile); + $profile->new->apply_profile($self->_repl); +} - my $rc_file = $self->rcfile; +sub load_rcfile { + my ($self, $rc_file) = @_; # plain name => ~/.re.pl/${rc_file} if ($rc_file !~ m!/!) { @@ -43,8 +54,9 @@ sub load_rcfile { } sub eval_rcdata { - my $_REPL = $_[0]->_repl; - eval $_[1]; + my ($self, $data) = @_; + local $CURRENT_SCRIPT = $self; + $self->_repl->eval($data); } sub run { @@ -58,4 +70,11 @@ sub import { $class->new_with_options->run; } +sub current { + confess "->current should only be called as class method" if ref($_[0]); + confess "No current instance (valid only during rc parse)" + unless $CURRENT_SCRIPT; + return $CURRENT_SCRIPT; +} + 1;