[Bast-commits] r3184 - in trunk: . Devel-REPL Devel-REPL/lib
Devel-REPL/lib/Devel
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Mon Apr 9 18:20:43 GMT 2007
Author: matthewt
Date: 2007-04-09 18:20:39 +0100 (Mon, 09 Apr 2007)
New Revision: 3184
Added:
trunk/Devel-REPL/
trunk/Devel-REPL/lib/
trunk/Devel-REPL/lib/Devel/
trunk/Devel-REPL/lib/Devel/REPL.pm
Log:
initial Devel::REPL implementation
Added: trunk/Devel-REPL/lib/Devel/REPL.pm
===================================================================
--- trunk/Devel-REPL/lib/Devel/REPL.pm (rev 0)
+++ trunk/Devel-REPL/lib/Devel/REPL.pm 2007-04-09 17:20:39 UTC (rev 3184)
@@ -0,0 +1,58 @@
+package Devel::REPL;
+
+use Term::ReadLine;
+use Moose;
+use namespace::clean;
+
+with 'MooseX::Object::Pluggable';
+
+has 'term' => (
+ is => 'rw', required => 1,
+ default => sub { Term::ReadLine->new('Perl REPL') }
+);
+
+has 'prompt' => (
+ is => 'rw', required => 1,
+ default => sub { '$ ' }
+);
+
+has 'out_fh' => (
+ is => 'rw', required => 1, lazy => 1,
+ default => sub { shift->term->OUT || \*STDOUT; }
+);
+
+sub run {
+ my ($self) = @_;
+ while ($self->run_once) {
+ # keep looping
+ }
+}
+
+sub run_once {
+ my ($self) = @_;
+ my $line = $self->read;
+ return unless defined($line); # undefined value == EOF
+ my @ret = $self->execute($line);
+ $self->print(@ret);
+ return 1;
+}
+
+sub read {
+ my ($self) = @_;
+ return $self->term->readline($self->prompt);
+}
+
+sub execute {
+ my ($self, $to_exec) = @_;
+ my @ret = eval $to_exec;
+ @ret = ("ERROR: $@") if $@;
+ return @ret;
+}
+
+sub print {
+ my ($self, @ret) = @_;
+ my $fh = $self->out_fh;
+ print $fh "@ret";
+}
+
+1;
More information about the Bast-commits
mailing list