summaryrefslogtreecommitdiffstats
path: root/lib/App/REPL.pm
blob: 0ec1e63f013a9f9cdc2abd15762052b0e9f1ee89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;