MongoDB-Async
view release on metacpan or search on metacpan
lib/MongoDB/Async/Cursor.pm view on Meta::CPAN
isa => 'Bool',
required => 0,
default => 0,
);
has slave_okay => (
is => 'rw',
isa => 'Bool',
required => 0,
default => 0,
);
has _request_id => (
is => 'rw',
isa => 'Int',
default => 0,
);
sub _ensure_special {
my ($self) = @_;
return if ($self->{_grrrr}); # stupid hack for inconsistent database handling of queries
$self->{_grrrr} = 1;
$self->{_query} = {'query' => $self->{_query} };
}
# this does the query if it hasn't been done yet
sub _do_query {
my ($self) = @_;
return if $self->{started_iterating};
my $opts = ($self->{_tailable} << 1) |
(($MongoDB::Async::Cursor::slave_okay | $self->{slave_okay}) << 2) |
($self->{immortal} << 4) |
($self->{partial} << 7);
my ($query, $info) = MongoDB::Async::write_query(
$self->{_ns},
$opts,
$self->{_skip},
$self->{_limit},
$self->{_query},
$self->{_fields});
$self->{_request_id} = $info->{'request_id'};
# $self->{_client}->send($query); # now this in XS too
return $query;
# $self->_client->recv($self);
#Weird shit happens with perl stack if we call perl from XS and try to switch Coro threads in recv.
#I think problem is in macros that used to call perl sub from xs.
#Maybe it's some "static" global(per file) var in one of perl .h files used by those macro, and when coro switches stacks:
# -> Cursor xs uses macros (with global var) [point 1] to call perl do_query sub -> perl sub calls XS recv() sub -> recv() switches coro threads while waiting response -> another coro perl thread calls Cursorxs sub thath calls do_query from XS usin...
#But i'm not sure about it, maybe i'm wrong.
#So call recv from Cursor.xs
# $self->{started_iterating}(1);
# now XS sets this
}
sub fields {
my ($self, $f) = @_;
confess "cannot set fields after querying"
if $self->{started_iterating};
confess 'not a hash reference'
unless ref $f eq 'HASH' || ref $f eq 'Tie::IxHash';
$self->{_fields} = $f;
return $self;
}
sub sort {
my ($self, $order) = @_;
confess "cannot set sort after querying"
if $self->{started_iterating};
confess 'not a hash reference'
unless ref $order eq 'HASH' || ref $order eq 'Tie::IxHash';
$self->_ensure_special;
$self->{_query}->{'orderby'} = $order;
return $self;
}
sub limit {
my ($self, $num) = @_;
confess "cannot set limit after querying"
if $self->{started_iterating};
$self->{_limit} = $num;
return $self;
}
sub tailable {
my($self, $bool) = @_;
confess "Cannot set tailable after querying"
if $self->{started_iterating};
$self->{_tailable} = $bool;
return $self;
}
( run in 0.660 second using v1.01-cache-2.11-cpan-39bf76dae61 )