summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-06-08 14:59:15 -0500
committerJesse Luehrs <doy@tozt.net>2013-06-08 14:59:15 -0500
commitf14ee8d21ab99bdb3fecc2908b7c7398eeea1252 (patch)
treeecf33d8a1bf178623e22257360a9a52b674bd2de
parent6c4b97722ea6f8158e43b49bb8133e7385e1c0cc (diff)
downloadreply-f14ee8d21ab99bdb3fecc2908b7c7398eeea1252.tar.gz
reply-f14ee8d21ab99bdb3fecc2908b7c7398eeea1252.zip
a few cleanups
-rw-r--r--lib/Reply.pm29
1 files changed, 13 insertions, 16 deletions
diff --git a/lib/Reply.pm b/lib/Reply.pm
index 4826b25..0e079d9 100644
--- a/lib/Reply.pm
+++ b/lib/Reply.pm
@@ -109,11 +109,14 @@ undef or the C<loop> callback returns false.
sub run {
my $self = shift;
- while ($self->run_one) { }
+ while (1) {
+ my $continue = $self->step;
+ last unless $continue;
+ }
print "\n";
}
-=method run_one($line)
+=method step($line)
Runs a single iteration of the repl. If C<$line> is given, it will be used as
the string to evaluate (and the C<prompt> and C<read_line> callbacks will not
@@ -122,19 +125,16 @@ requested to quit.
=cut
-sub run_one {
+sub step {
my $self = shift;
my ($line) = @_;
- if (defined $line) {
- $line = $self->_premangle_line($line);
- }
- else {
- $line = $self->_read;
- }
+ $line = $self->_read unless defined $line;
return unless defined $line;
+ $line = $self->_preprocess_line($line);
+
try {
my @result = $self->_eval($line);
$self->_print_result(@result);
@@ -163,7 +163,7 @@ sub _load_config {
}
for my $line (sort grep { /^script_line/ } keys %$root_config) {
- $self->run_one($root_config->{$line});
+ $self->step($root_config->{$line});
}
if (defined(my $file = $root_config->{script_file})) {
@@ -172,7 +172,7 @@ sub _load_config {
local $/ = undef;
<$fh>
};
- $self->run_one($contents);
+ $self->step($contents);
}
}
@@ -204,13 +204,10 @@ sub _read {
my $self = shift;
my $prompt = $self->_wrapped_plugin('prompt');
- my ($line) = $self->_wrapped_plugin('read_line', $prompt);
- return if !defined $line;
-
- return $self->_premangle_line($line);
+ return $self->_wrapped_plugin('read_line', $prompt);
}
-sub _premangle_line {
+sub _preprocess_line {
my $self = shift;
my ($line) = @_;