[Bps-public-commit] r15412 - Prophet/trunk/lib/Prophet/CLI/Command
jesse at bestpractical.com
jesse at bestpractical.com
Sun Aug 24 12:05:25 EDT 2008
Author: jesse
Date: Sun Aug 24 12:05:25 2008
New Revision: 15412
Modified:
Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm
Log:
* Refactor the prophet shell a bit to move logic out into named subs
Modified: Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm Sun Aug 24 12:05:25 2008
@@ -21,6 +21,13 @@
},
);
+ our $HIST = $ENV{PROPHET_HISTFILE}
+ || (($ENV{HOME} || (getpwuid($<))[7]) . "/.prophetreplhist");
+ our $LEN = $ENV{PROPHET_HISTLEN} || 500;
+
+
+
+
sub prompt {
my $self = shift;
return $self->name . '> ';
@@ -72,32 +79,39 @@
}
# make the REPL history persistent
-# we use eval here because only some Term::ReadLine subclasses support
-# persistent history. it also seems that ->can doesn't work because of AUTOLOAD
-# trickery. :(
around run => sub {
my $orig = shift;
my $self = shift;
+ $self->_read_repl_history();
+ $self->$orig(@_);
+ $self->_write_repl_history();
+};
- my $hist = $ENV{PROPHET_HISTFILE}
- || (($ENV{HOME} || (getpwuid($<))[7]) . "/.prophetreplhist");
- my $len = $ENV{PROPHET_HISTLEN} || 500;
+# we use eval here because only some Term::ReadLine subclasses support
+# persistent history. it also seems that ->can doesn't work because of AUTOLOAD
+# trickery. :(
+
+sub _read_repl_history {
+ my $self = shift;
eval {
local $SIG{__DIE__};
- $self->term->stifle_history($len);
- $self->term->ReadHistory($hist)
- if -f $hist;
+ $self->term->stifle_history($LEN);
+ $self->term->ReadHistory($HIST)
+ if -f $HIST;
};
+}
- $self->$orig(@_);
+sub _write_repl_history {
+ my $self = shift;
eval {
local $SIG{__DIE__};
- $self->term->WriteHistory($hist)
- or warn "Unable to write to shell history file $hist";
+ $self->term->WriteHistory($HIST)
+ or warn "Unable to write to shell history file $HIST";
};
-};
+}
+
__PACKAGE__->meta->make_immutable;
no Moose;
More information about the Bps-public-commit
mailing list