diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/App/REPL.pm | 41 |
1 files changed, 41 insertions, 0 deletions
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; |