Modified:
trunk/lib/Shell/Perl.pm
Log:
now maintaining history across sessions
Modified: trunk/lib/Shell/Perl.pm
==============================================================================
--- trunk/lib/Shell/Perl.pm (original)
+++ trunk/lib/Shell/Perl.pm Mon Mar 3 10:20:52 2008
@@ -178,7 +178,7 @@
$self->package($package);
no strict 'refs';
- *{ "${package}::quit" } = sub { exit };
+ *{ "${package}::quit" } = sub { $self->quit };
} else {
$self->_warn("bad package name $package");
}
@@ -227,10 +227,34 @@
return $self->term->readline($self->prompt_title);
}
+sub _history_file { # XXX
+ return glob '~/.pirl-history'; # FIXME
+ }
+
+sub _read_history { # XXX belongs to Shell::Perl::ReadLine
+ my $term = shift;
+ if ( $term->Features->{readHistory} ) {
+ $term->ReadHistory( _history_file );
+ }
+# if ( !$self->term->Features->{readHistory} ) {
+# print "Your Readline doesn't support getHistory\n";
+# return;
+# }
+}
+
+sub _write_history { # XXX belongs to Shell::Perl::ReadLine
+ my $term = shift;
+ if ( $term->Features->{writeHistory} ) {
+ $term->WriteHistory( _history_file );
+ }
+}
+
sub _new_term {
my $self = shift;
my $name = shift;
- return Term::ReadLine->new( $name );
+ my $term = Term::ReadLine->new( $name );
+ _read_history( $term );
+ return $term;
}
sub run {
@@ -281,7 +305,7 @@
}
}
- #print "Bye.\n"; # XXX
+ $self->quit;
}
@@ -300,7 +324,13 @@
CHUNK
# XXX gotta save $_, etc.
}
-
+
+sub quit {
+ my $self = shift;
+ _write_history( $self->term );
+ $self->print( "Bye.\n" ); # XXX
+ exit;
+}
sub run_with_args {
my $self = shift;