1 package Devel::REPL::Script;
3 our $VERSION = '1.003030';
8 use Module::Runtime 'use_module';
9 use namespace::autoclean;
13 with 'MooseX::Getopt';
16 is => 'ro', isa => 'Str',
17 default => sub { 'repl.rc' },
23 default => sub { $ENV{DEVEL_REPL_PROFILE} || 'Minimal' },
27 is => 'ro', isa => 'Devel::REPL',
28 default => sub { Devel::REPL->new() }
33 $self->load_profile($self->profile);
34 $self->load_rcfile($self->rcfile);
38 my ($self, $profile) = @_;
39 $profile = "Devel::REPL::Profile::${profile}" unless $profile =~ /::/;
41 confess "Profile class ${profile} doesn't do 'Devel::REPL::Profile'"
42 unless $profile->does('Devel::REPL::Profile');
43 $profile->new->apply_profile($self->_repl);
47 my ($self, $rc_file) = @_;
49 # plain name => ~/.re.pl/${rc_file}
50 if ($rc_file !~ m!/!) {
51 $rc_file = File::Spec->catfile(($^O eq 'MSWin32' && "$]" < 5.016 ? $ENV{HOME} || $ENV{USERPROFILE} : (<~>)[0]), '.re.pl', $rc_file);
54 $self->apply_script($rc_file);
58 my ($self, $script, $warn_on_unreadable) = @_;
61 warn "File '$script' does not exist" if $warn_on_unreadable;
65 warn "File '$script' is unreadable" if $warn_on_unreadable;
69 open RCFILE, '<', $script or die "Couldn't open ${script}: $!";
71 { local $/; $rc_data = <RCFILE>; }
72 close RCFILE; # Don't care if this fails
73 $self->eval_script($rc_data);
74 warn "Error executing script ${script}: $@\n" if $@;
78 my ($self, $data) = @_;
79 local $CURRENT_SCRIPT = $self;
80 $self->_repl->eval($data);
89 my ($class, @opts) = @_;
90 return unless (@opts == 1 && $opts[0] eq 'run');
91 $class->new_with_options->run;
95 confess "->current should only be called as class method" if ref($_[0]);
96 confess "No current instance (valid only during rc parse)"
97 unless $CURRENT_SCRIPT;
98 return $CURRENT_SCRIPT;