1 package Devel::REPL::Script;
7 use vars qw($CURRENT_SCRIPT);
8 use namespace::clean -except => [ qw(meta) ];
10 with 'MooseX::Getopt';
13 is => 'ro', isa => 'Str', required => 1, default => sub { 'repl.rc' },
17 is => 'ro', isa => 'Str', required => 1, default => sub { 'Default' },
21 is => 'ro', isa => 'Devel::REPL', required => 1,
22 default => sub { Devel::REPL->new() }
27 $self->load_profile($self->profile);
28 $self->load_rcfile($self->rcfile);
32 my ($self, $profile) = @_;
33 $profile = "Devel::REPL::Profile::${profile}" unless $profile =~ /::/;
34 Class::MOP::load_class($profile);
35 confess "Profile class ${profile} doesn't do 'Devel::REPL::Profile'"
36 unless $profile->does('Devel::REPL::Profile');
37 $profile->new->apply_profile($self->_repl);
41 my ($self, $rc_file) = @_;
43 # plain name => ~/.re.pl/${rc_file}
44 if ($rc_file !~ m!/!) {
45 $rc_file = File::Spec->catfile(File::HomeDir->my_home, '.re.pl', $rc_file);
49 open RCFILE, '<', $rc_file || die "Couldn't open ${rc_file}: $!";
51 { local $/; $rc_data = <RCFILE>; }
52 close RCFILE; # Don't care if this fails
53 $self->eval_rcdata($rc_data);
54 warn "Error executing rc file ${rc_file}: $@\n" if $@;
59 my ($self, $data) = @_;
60 local $CURRENT_SCRIPT = $self;
61 $self->_repl->eval($data);
70 my ($class, @opts) = @_;
71 return unless (@opts == 1 && $opts[0] eq 'run');
72 $class->new_with_options->run;
76 confess "->current should only be called as class method" if ref($_[0]);
77 confess "No current instance (valid only during rc parse)"
78 unless $CURRENT_SCRIPT;
79 return $CURRENT_SCRIPT;