ObjStore
view release on metacpan or search on metacpan
lib/ObjStore/Posh/Cursor.pm view on Meta::CPAN
use ObjStore::notify qw(init);
sub do_init {
my ($o) = @_;
$$o{where} = [[$o->database_of->hash->new_ref($o,'hard')]]; #array of paths
$$o{at} = 0;
}
use ObjStore::notify qw(configure execute);
sub do_configure {
my $o = shift;
# local or remote?
}
sub myeval {
my ($o, $perl) = @_;
# observe care!
my $w = $o->{where}[ $$o{at} ]->HOLD;
my @c;
for my $tmp (@$w) {
my $got = $tmp->focus;
push @c, $got;
}
local($input::db, $input::at, $input::cursor) =
($o->database_of, @c? $c[$#c] : $o->database_of, \@c);
my @r;
my $to_eval = "no strict; package input;\n#line 1 \"input\"\n".$perl;
if (wantarray) { @r = eval $to_eval; }
elsif (defined wantarray) { $r[0] = eval $to_eval; }
else { eval $to_eval; }
if ($@) {
ObjStore::Transaction::get_current()->abort();
()
} else {
if (!defined wantarray) { () } else { wantarray ? @r : $r[0]; }
}
}
sub resolve {
my ($o,$to,$update) = @_;
# $to already stripped of leading & trailing spaces
my $w = $$o{where};
my @at = map { $_->focus } @{ $$w[ $$o{at} ] };
if (!length $to) {
@at = ();
if ($update) {
$w->UNSHIFT([$o->database_of->hash->new_ref($o,'hard')]);
pop @$w if @$w > 5;
$$o{at} = 0;
}
} elsif ($to =~ m/^([+-])$/) {
my $at = $1 eq '-' ? $$o{at}+1 : $$o{at}-1;
if ($at >= 0 and $at < @$w) {
@at = map { $_->focus } @{ $$w[$at] };
if ($update) {
$$o{at} = $at;
}
}
} elsif ($to =~ m,^[\w\/\.\:\-]+$,) {
my @to = split m'/+', $to;
for my $t (@to) {
next if $t eq '.';
if ($t eq '..') {
pop @at if @at;
} else {
my $at = $at[$#at];
if ($at->can('POSH_CD')) {
$at = $at->POSH_CD($t);
$at = $at->POSH_ENTER()
if blessed $at && $at->can('POSH_ENTER');
if (!blessed $at or !$at->isa('ObjStore::UNIVERSAL')) {
$at = 'undef' if !defined $at;
$$o{why} = "resolve($to): failed at $t (got '$at'!)";
last;
}
}
push @at, $at;
}
}
if (!$$o{why} and $update) {
$w->UNSHIFT([map { $_->new_ref($w,'hard') } @at]);
pop @$w if @$w > 5;
$$o{at} = 0;
}
} else {
my $err;
my $warn='';
{
local $SIG{__WARN__} = sub { $warn.=$_[0] };
begin sub {
local $Carp::Verbose = 1;
my $at = $o->myeval($to);
if ($@) {
$err .= $warn.$@;
} else {
$$o{out} = $warn;
push @at, $at;
if ($update) {
$w->UNSHIFT([map { $_->new_ref($w,'hard') } @at]);
pop @$w if @$w > 5;
$$o{at} = 0;
}
}
};
}
warn if $@;
$$o{why} = $err if $err;
}
@at? $at[$#$a] : undef;
}
sub do_execute {
require ObjStore::Peeker;
my ($o, $in) = @_;
$$o{mtime} = time; #make sure the GUI knows!
$in ||= '';
$in =~ s/\s+$//;
$in =~ s/^\s+//;
my $hist = $$o{history} ||= [];
( run in 1.835 second using v1.01-cache-2.11-cpan-71847e10f99 )