diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-05-29 01:34:06 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-05-29 01:34:06 -0500 |
commit | 1ce2f2c8f0c44f345fe83a43de91fc094e5a8260 (patch) | |
tree | 7188b1de783c5c175eba0080b95ff5eecc64f51b /lib | |
parent | 3b4c8e20ecc690836ff7f7ea7889bbcd43b3d3e8 (diff) | |
download | reply-1ce2f2c8f0c44f345fe83a43de91fc094e5a8260.tar.gz reply-1ce2f2c8f0c44f345fe83a43de91fc094e5a8260.zip |
handle exceptions
Diffstat (limited to 'lib')
-rw-r--r-- | lib/App/REPL.pm | 17 | ||||
-rw-r--r-- | lib/App/REPL/Plugin/Defaults.pm | 8 |
2 files changed, 23 insertions, 2 deletions
diff --git a/lib/App/REPL.pm b/lib/App/REPL.pm index 6f74385..4c8110a 100644 --- a/lib/App/REPL.pm +++ b/lib/App/REPL.pm @@ -45,7 +45,12 @@ sub run { while (defined(my $line = $self->_read)) { my @result = $self->_eval($line); - $self->_print(@result); + if ($@) { + $self->_print_error($@); + } + else { + $self->_print_result(@result); + } } print "\n"; } @@ -67,7 +72,15 @@ sub _eval { return $self->_wrapped_plugin('evaluate', $line); } -sub _print { +sub _print_error { + my $self = shift; + my ($error) = @_; + + ($error) = $self->_chained_plugin('munge_error', $error); + $self->_wrapped_plugin('print_error', $error); +} + +sub _print_result { my $self = shift; my (@result) = @_; diff --git a/lib/App/REPL/Plugin/Defaults.pm b/lib/App/REPL/Plugin/Defaults.pm index f2b4705..28eb346 100644 --- a/lib/App/REPL/Plugin/Defaults.pm +++ b/lib/App/REPL/Plugin/Defaults.pm @@ -23,6 +23,14 @@ sub evaluate { return eval $line; } +sub print_error { + my $self = shift; + my ($next, $error) = @_; + + print $error, "\n" + if defined $error; +} + sub print_result { my $self = shift; my ($next, $result) = @_; |