[Bast-commits] r3776 - trunk/Devel-REPL/lib/Devel/REPL
Sartak at dev.catalyst.perl.org
Sartak at dev.catalyst.perl.org
Sat Sep 22 02:07:55 GMT 2007
Author: Sartak
Date: 2007-09-22 02:07:54 +0100 (Sat, 22 Sep 2007)
New Revision: 3776
Modified:
trunk/Devel-REPL/lib/Devel/REPL/Script.pm
Log:
Remove -e switch, but refactor load_rcfile to make it easy to use the "do FILE" like behavior
Modified: trunk/Devel-REPL/lib/Devel/REPL/Script.pm
===================================================================
--- trunk/Devel-REPL/lib/Devel/REPL/Script.pm 2007-09-21 21:12:12 UTC (rev 3775)
+++ trunk/Devel-REPL/lib/Devel/REPL/Script.pm 2007-09-22 01:07:54 UTC (rev 3776)
@@ -17,10 +17,6 @@
is => 'ro', isa => 'Str', required => 1, default => sub { 'Default' },
);
-has 'e' => (
- is => 'ro', isa => 'ArrayRef', default => sub { [] },
-);
-
has '_repl' => (
is => 'ro', isa => 'Devel::REPL', required => 1,
default => sub { Devel::REPL->new() }
@@ -30,7 +26,6 @@
my ($self) = @_;
$self->load_profile($self->profile);
$self->load_rcfile($self->rcfile);
- $self->load_scripts($self->e);
}
sub load_profile {
@@ -50,25 +45,30 @@
$rc_file = File::Spec->catfile(File::HomeDir->my_home, '.re.pl', $rc_file);
}
- if (-r $rc_file) {
- open RCFILE, '<', $rc_file || die "Couldn't open ${rc_file}: $!";
- my $rc_data;
- { local $/; $rc_data = <RCFILE>; }
- close RCFILE; # Don't care if this fails
- $self->eval_rcdata($rc_data);
- warn "Error executing rc file ${rc_file}: $@\n" if $@;
- }
+ $self->apply_script($rc_file);
}
-sub load_scripts {
- my ($self, $scripts) = @_;
+sub apply_script {
+ my ($self, $script, $warn_on_unreadable) = @_;
- for (@$scripts) {
- do $_;
+ if (!-e $script) {
+ warn "File '$script' does not exist" if $warn_on_unreadable;
+ return;
}
+ elsif (!-r _) {
+ warn "File '$script' is unreadable" if $warn_on_unreadable;
+ return;
+ }
+
+ open RCFILE, '<', $script or die "Couldn't open ${script}: $!";
+ my $rc_data;
+ { local $/; $rc_data = <RCFILE>; }
+ close RCFILE; # Don't care if this fails
+ $self->eval_script($rc_data);
+ warn "Error executing script ${script}: $@\n" if $@;
}
-sub eval_rcdata {
+sub eval_script {
my ($self, $data) = @_;
local $CURRENT_SCRIPT = $self;
$self->_repl->eval($data);
More information about the Bast-commits
mailing list