ObjStore
view release on metacpan or search on metacpan
$col += 1+length;
}
print "\n";
} else {
print "No methods found.\n"
}
}
package Posh::FakeTerm;
sub new {
my ($class) = @_;
bless [], $class;
}
sub readline {
my ($o, $pr) = @_;
$|=1;
print($pr);
$|=0;
scalar(<>);
}
sub addhistory {}
package Posh::History;
use ObjStore;
use base 'ObjStore::AV';
use vars qw($VERSION);
$VERSION='0.01';
sub addhistory {
my $o = shift;
return if $] <= 5.00458;
for my $input (@_) {
for (my $x=0; $x < @$o; $x++) {
$$o[$x] = undef if $$o[$x] && $$o[$x] eq $input;
}
push @$o, $input;
}
do { shift @$o } while (@$o > 100);
}
package Posh;
use strict;
use Carp;
use IO::Handle;
use ObjStore ':ADV';
use ObjStore::AppInstance;
use vars qw($term @ORINC @HistoryBuf $Unloaded);
@ORINC = @INC;
$Unloaded = 0;
sub new {
my ($class) = @_;
my $o = bless {}, $class;
# my $o = $class->SUPER::new('posh', pvars => [qw(ttype view)]);
$o->{user} ||= scalar(getpwuid($>));
$o->{app} = ObjStore::AppInstance->new('posh', $o->{user});
$o->{ttype} = $open_mode eq 'mvcc'? 'read' : 'update';
# ObjStore::set_max_retries(0);
$ObjStore::TRANSACTION_PRIORITY = 0x100; #don't conflict with real jobs
begin('update', sub {
my $t = $o->{app}->top();
$t->{view} ||= new Posh::View($t);
$o->{prompt} = $t->{view}->enter($o->{app}->get_pathname());
if ($] >= 5.00458) {
for my $typo (@{$t->{history}}) {
next if !$typo;
$term->addhistory($typo);
}
}
});
die if $@;
$o;
}
sub run {
my ($o) = @_;
print("posh $ObjStore::VERSION (Perl $], ".ObjStore::release_name.")\n");
my $rc = "$ENV{HOME}/.poshrc";
if (-e $rc) {
print "[reading $rc...]\n";
do $rc;
}
print "[set for \U$o->{ttype}]\n";
while (1) {
my $input;
eval {
if ($o->{prompt} =~ m/^(.*\n)(.*)$/s) {
print $1;
$input = $term->readline("$2% ");
} else {
$input = $term->readline("$o->{prompt}% ");
}
};
if ($@) {
warn if $@ !~ /ABORT/;
next;
}
last if (!defined $input or $input =~ m/^\s*exit\s*$/);
$input =~ s/^\s*//;
if ($input =~ s/^\!// and $shell_escape) {
my $st = system($input);
print "(status=$st)\n" if $st;
next;
}
my $ttype;
if ($input =~ m/^cd/) {
$ttype = 'update';
} elsif ($input =~ m/^(read|update|abort_only)\s*$/) {
my $mode = $1;
if ($open_mode eq 'mvcc') {
( run in 1.156 second using v1.01-cache-2.11-cpan-39bf76dae61 )