More before/after

package Interpreter::Terminal;
use Moose;
extends 'Interpreter';
use Term::ReadLine;

has depth => (
    isa       => 'Int',
    is        => 'rw',
    default   => -1,
);

has term => (
    is      => 'ro',
    isa     => 'Term::ReadLine',
    default => sub {
        Term::ReadLine->new;
    },
);

sub read {
    my ($self, $prompt) = @_;
    $self->term->readline("$prompt> ");
}

sub say {
    shift;
    say @_;
}

# show tree structure
before qw/read say/ => sub {
    my $self = shift;
    print " "x(4*$self->depth);
};

# update depth when we recurse
before interpret => sub {
    my $self = shift;
    $self->depth($self->depth + 1);
};

after interpret => sub {
    my $self = shift;
    $self->depth($self->depth - 1);
};