diff options
-rw-r--r-- | bin/repl | 7 | ||||
-rw-r--r-- | lib/App/REPL.pm | 41 |
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; |