summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-05-29 02:28:58 -0500
committerJesse Luehrs <doy@tozt.net>2013-05-29 02:50:30 -0500
commit5b9c3c3f7bab2a1b02faf8fcf0f4e804f621891a (patch)
tree240b22cf6010c43c059aeba0160abe1955a3eaf4
parent04dfe92390c4f80db3c6672f75c233476affe847 (diff)
downloadreply-5b9c3c3f7bab2a1b02faf8fcf0f4e804f621891a.tar.gz
reply-5b9c3c3f7bab2a1b02faf8fcf0f4e804f621891a.zip
use eval::closure instead
-rw-r--r--lib/App/REPL.pm11
-rw-r--r--lib/App/REPL/Plugin/Defaults.pm21
2 files changed, 23 insertions, 9 deletions
diff --git a/lib/App/REPL.pm b/lib/App/REPL.pm
index 4c8110a..916e60c 100644
--- a/lib/App/REPL.pm
+++ b/lib/App/REPL.pm
@@ -6,6 +6,7 @@ use App::REPL::Plugin::Defaults;
use Module::Runtime qw(compose_module_name use_package_optimistically);
use Scalar::Util qw(blessed);
+use Try::Tiny;
sub new {
bless {
@@ -44,13 +45,13 @@ sub run {
my $self = shift;
while (defined(my $line = $self->_read)) {
- my @result = $self->_eval($line);
- if ($@) {
- $self->_print_error($@);
- }
- else {
+ try {
+ my @result = $self->_eval($line);
$self->_print_result(@result);
}
+ catch {
+ $self->_print_error($_);
+ }
}
print "\n";
}
diff --git a/lib/App/REPL/Plugin/Defaults.pm b/lib/App/REPL/Plugin/Defaults.pm
index ecc221b..b226dfd 100644
--- a/lib/App/REPL/Plugin/Defaults.pm
+++ b/lib/App/REPL/Plugin/Defaults.pm
@@ -1,13 +1,20 @@
package App::REPL::Plugin::Defaults;
-# don't pollute with strict and warnings for this module
-sub _eval { eval($_[0]) }
+# XXX Eval::Closure imposes its own hints on things that are eval'ed at the
+# moment, but this may be fixed in the future
+BEGIN {
+ our $default_hints = $^H;
+ our $default_hinthash = { %^H };
+ our $default_warning_bits = ${^WARNING_BITS};
+}
use strict;
use warnings;
use base 'App::REPL::Plugin';
+use Eval::Closure;
+
sub display_prompt {
my $self = shift;
@@ -20,11 +27,17 @@ sub read_line {
return scalar <>;
}
+my $PREFIX = "BEGIN { \$^H = \$" . __PACKAGE__ . "::default_hints; \%^H = \%\$" . __PACKAGE__ . "::default_hinthash; \${^WARNING_BITS} = \$" . __PACKAGE__ . "::default_warning_bits }";
+
sub evaluate {
my $self = shift;
- my ($next, $line) = @_;
+ my ($next, $line, %args) = @_;
- return _eval($line);
+ return eval_closure(
+ source => "$PREFIX; $line",
+ terse_error => 1,
+ %args,
+ );
}
sub print_error {