1 package Devel::REPL::Script;
3 our $VERSION = '1.003029';
9 use Module::Runtime 'use_module';
10 use namespace::autoclean;
14 with 'MooseX::Getopt';
17 is => 'ro', isa => 'Str',
18 default => sub { 'repl.rc' },
24 default => sub { $ENV{DEVEL_REPL_PROFILE} || 'Minimal' },
28 is => 'ro', isa => 'Devel::REPL',
29 default => sub { Devel::REPL->new() }
34 $self->load_profile($self->profile);
35 $self->load_rcfile($self->rcfile);
39 my ($self, $profile) = @_;
40 $profile = "Devel::REPL::Profile::${profile}" unless $profile =~ /::/;
42 confess "Profile class ${profile} doesn't do 'Devel::REPL::Profile'"
43 unless $profile->does('Devel::REPL::Profile');
44 $profile->new->apply_profile($self->_repl);
48 my ($self, $rc_file) = @_;
50 # plain name => ~/.re.pl/${rc_file}
51 if ($rc_file !~ m!/!) {
52 $rc_file = File::Spec->catfile(File::HomeDir->my_home, '.re.pl', $rc_file);
55 $self->apply_script($rc_file);
59 my ($self, $script, $warn_on_unreadable) = @_;
62 warn "File '$script' does not exist" if $warn_on_unreadable;
66 warn "File '$script' is unreadable" if $warn_on_unreadable;
70 open RCFILE, '<', $script or die "Couldn't open ${script}: $!";
72 { local $/; $rc_data = <RCFILE>; }
73 close RCFILE; # Don't care if this fails
74 $self->eval_script($rc_data);
75 warn "Error executing script ${script}: $@\n" if $@;
79 my ($self, $data) = @_;
80 local $CURRENT_SCRIPT = $self;
81 $self->_repl->eval($data);
90 my ($class, @opts) = @_;
91 return unless (@opts == 1 && $opts[0] eq 'run');
92 $class->new_with_options->run;
96 confess "->current should only be called as class method" if ref($_[0]);
97 confess "No current instance (valid only during rc parse)"
98 unless $CURRENT_SCRIPT;
99 return $CURRENT_SCRIPT;