diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-06-08 12:03:31 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-06-08 12:06:41 -0500 |
commit | f4775be782ef0cd1003190169b539b3ba2367292 (patch) | |
tree | fc70528bd046cd197fe6e4dbf96b476255deb663 /lib/Reply.pm | |
parent | ca4d93af889b6086deabcdf1825181f46e17957a (diff) | |
download | reply-f4775be782ef0cd1003190169b539b3ba2367292.tar.gz reply-f4775be782ef0cd1003190169b539b3ba2367292.zip |
allow running single commands through the repl
Diffstat (limited to 'lib/Reply.pm')
-rw-r--r-- | lib/Reply.pm | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/lib/Reply.pm b/lib/Reply.pm index 22f14d5..dbb9b24 100644 --- a/lib/Reply.pm +++ b/lib/Reply.pm @@ -107,19 +107,33 @@ undef. sub run { my $self = shift; - while (defined(my $line = $self->_read)) { - try { - my @result = $self->_eval($line); - $self->_print_result(@result); - } - catch { - $self->_print_error($_); - }; - $self->_loop; - } + while ($self->run_one) { } print "\n"; } +sub run_one { + my $self = shift; + my ($line) = @_; + + if (defined $line) { + $line = $self->_premangle_line($line); + } + else { + $line = $self->_read; + } + + return unless defined $line; + + try { + my @result = $self->_eval($line); + $self->_print_result(@result); + } + catch { + $self->_print_error($_); + }; + $self->_loop; +} + sub _load_config { my $self = shift; my ($file) = @_; @@ -182,6 +196,13 @@ sub _read { my ($line) = $self->_wrapped_plugin('read_line', $prompt); return if !defined $line; + return $self->_premangle_line($line); +} + +sub _premangle_line { + my $self = shift; + my ($line) = @_; + if ($line =~ s/^#(\w+)(?:\s+|$)//) { ($line) = $self->_chained_plugin("command_\L$1", $line); } @@ -219,7 +240,7 @@ sub _print_result { sub _loop { my $self = shift; - $self->_chained_plugin('loop'); + $self->_chained_plugin('loop', 1); } sub _wrapped_plugin { |