summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-05-29 00:42:55 -0500
committerJesse Luehrs <doy@tozt.net>2013-05-29 00:42:55 -0500
commitf57cbd571049fcff4656a8c8b4f1ea6344ef4626 (patch)
treef174c3d6922ad9985c04c46693b4b47b0854be86
parent92eaf461fe65022cf0b97cc295c997cd135a5857 (diff)
downloadreply-f57cbd571049fcff4656a8c8b4f1ea6344ef4626.tar.gz
reply-f57cbd571049fcff4656a8c8b4f1ea6344ef4626.zip
basic outline
-rw-r--r--bin/repl7
-rw-r--r--lib/App/REPL.pm41
2 files changed, 48 insertions, 0 deletions
diff --git a/bin/repl b/bin/repl
new file mode 100644
index 0000000..b61c670
--- /dev/null
+++ b/bin/repl
@@ -0,0 +1,7 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use App::REPL;
+
+App::REPL->new->run;
diff --git a/lib/App/REPL.pm b/lib/App/REPL.pm
index e69de29..0ec1e63 100644
--- a/lib/App/REPL.pm
+++ b/lib/App/REPL.pm
@@ -0,0 +1,41 @@
+package App::REPL;
+use strict;
+use warnings;
+
+sub new {
+ bless {}, shift;
+}
+
+sub run {
+ my $self = shift;
+
+ while (defined(my $line = $self->_read)) {
+ my $result = $self->_eval($line);
+ $self->_print($result);
+ }
+ print "\n";
+}
+
+sub _read {
+ my $self = shift;
+
+ print "> ";
+ return <>;
+}
+
+sub _eval {
+ my $self = shift;
+ my ($line) = @_;
+
+ return eval $line;
+}
+
+sub _print {
+ my $self = shift;
+ my ($result) = @_;
+
+ print $result, "\n"
+ if defined $result;
+}
+
+1;