our
$VERSION
=
'v0.999.998.5'
;
has
db_name
=> (
is
=>
'ro'
,
isa
=> Str,
required
=> 1,
);
has
coll_name
=> (
is
=>
'ro'
,
isa
=> Str,
required
=> 1,
);
has
client
=> (
is
=>
'ro'
,
isa
=> InstanceOf[
'MongoDB::MongoClient'
],
required
=> 1,
);
has
read_preference
=> (
is
=>
'rw'
,
isa
=> ReadPreference,
required
=> 1,
coerce
=> 1,
);
has
filter
=> (
is
=>
'ro'
,
isa
=> IxHash,
required
=> 1,
coerce
=> 1,
);
has
modifiers
=> (
is
=>
'ro'
,
isa
=> HashRef,
default
=>
sub
{ {} },
);
has
allowPartialResults
=> (
is
=>
'rw'
,
isa
=> Bool,
);
has
batchSize
=> (
is
=>
'rw'
,
isa
=> Num,
default
=> 0,
);
has
comment
=> (
is
=>
'rw'
,
isa
=> Str,
default
=>
''
,
);
has
cursorType
=> (
is
=>
'rw'
,
isa
=> CursorType,
default
=>
'non_tailable'
,
);
has
limit
=> (
is
=>
'rw'
,
isa
=> Num,
default
=> 0,
);
has
maxTimeMS
=> (
is
=>
'rw'
,
isa
=> Num,
default
=> 0,
);
has
noCursorTimeout
=> (
is
=>
'rw'
,
isa
=> Bool,
);
has
oplogReplay
=> (
is
=>
'rw'
,
isa
=> Bool,
);
has
projection
=> (
is
=>
'rw'
,
isa
=> IxHash,
coerce
=> 1,
default
=>
sub
{ Tie::IxHash->new },
);
has
skip
=> (
is
=>
'rw'
,
isa
=> Num,
default
=> 0,
);
has
sort
=> (
is
=>
'rw'
,
isa
=> IxHash,
coerce
=> 1,
default
=>
sub
{ Tie::IxHash->new },
);
sub
as_query_op {
my
(
$self
) =
@_
;
my
$query
= Tie::IxHash->new(
'$query'
=>
$self
->filter );
while
(
my
(
$k
,
$v
) =
each
%{
$self
->modifiers } ) {
$query
->STORE(
$k
,
$v
);
}
for
my
$k
(
qw/maxTimeMS comment/
) {
next
unless
my
$v
=
$self
->
$k
;
$query
->STORE(
"\$$k"
,
$v
);
}
$query
->STORE(
'$orderby'
,
$self
->
sort
)
if
$self
->
sort
->Keys;
if
(
$query
->Keys == 1 && !
$query
->FETCH(
'$query'
)->EXISTS(
'query'
) ) {
$query
=
$query
->FETCH(
'$query'
);
}
my
$query_flags
= {
tailable
=> (
$self
->cursorType =~ /^tailable/ ? 1 : 0),
await_data
=>
$self
->cursorType eq
'tailable_await'
,
immortal
=>
$self
->noCursorTimeout,
partial
=>
$self
->allowPartialResults,
};
return
MongoDB::Op::_Query->new(
db_name
=>
$self
->db_name,
coll_name
=>
$self
->coll_name,
client
=>
$self
->client,
bson_codec
=>
$self
->client,
query
=>
$query
,
projection
=>
$self
->projection,
batch_size
=>
$self
->batchSize,
limit
=>
$self
->limit,
skip
=>
$self
->skip,
query_flags
=>
$query_flags
,
);
}
sub
execute {
my
(
$self
) =
@_
;
return
$self
->client->send_read_op(
$self
->as_query_op );
}
sub
clone {
my
(
$self
) =
@_
;
my
%args
=
%$self
;
for
my
$k
(
qw/filter projection sort/
) {
my
$orig
=
$args
{
$k
};
my
$copy
= Tie::IxHash->new(
map
{
$_
=>
$orig
->FETCH(
$_
) }
$orig
->Keys );
$args
{
$k
} =
$copy
;
}
$args
{modifiers} = { %{
$args
{modifiers} } };
return
ref
(
$self
)->new(
%args
);
}
1;