our
$VERSION
=
'v0.999.999.4'
;
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
bson_codec
=> (
is
=>
'ro'
,
isa
=> BSONCodec,
required
=> 1,
);
has
read_preference
=> (
is
=>
'rw'
,
isa
=> Maybe( [ReadPreference] ),
);
has
filter
=> (
is
=>
'ro'
,
isa
=> Document,
required
=> 1,
);
has
modifiers
=> (
is
=>
'ro'
,
isa
=> HashRef,
required
=> 1,
);
has
allowPartialResults
=> (
is
=>
'rw'
,
isa
=> Bool,
required
=> 1,
);
has
batchSize
=> (
is
=>
'rw'
,
isa
=> Num,
required
=> 1,
);
has
comment
=> (
is
=>
'rw'
,
isa
=> Str,
required
=> 1,
);
has
cursorType
=> (
is
=>
'rw'
,
isa
=> CursorType,
required
=> 1,
);
has
limit
=> (
is
=>
'rw'
,
isa
=> Num,
required
=> 1,
);
has
maxTimeMS
=> (
is
=>
'rw'
,
isa
=> Num,
required
=> 1,
);
has
noCursorTimeout
=> (
is
=>
'rw'
,
isa
=> Bool,
required
=> 1,
);
has
oplogReplay
=> (
is
=>
'rw'
,
isa
=> Bool,
required
=> 1,
);
has
projection
=> (
is
=>
'rw'
,
isa
=> Maybe( [Document] ),
);
has
skip
=> (
is
=>
'rw'
,
isa
=> Num,
required
=> 1,
);
has
sort
=> (
is
=>
'rw'
,
isa
=> Maybe( [IxHash] ),
);
with
$_
for
qw(
MongoDB::Role::_PrivateConstructor
)
;
sub
as_query_op {
my
(
$self
,
$extra_params
) =
@_
;
my
$query
= {
(
$self
->modifiers ? %{
$self
->modifiers } : () ),
(
$self
->comment ? (
'$comment'
=>
$self
->comment ) : () ),
(
$self
->
sort
? (
'$orderby'
=>
$self
->
sort
) : () ),
(
(
$self
->maxTimeMS &&
$self
->coll_name !~ /\A\
$cmd
/ )
? (
'$maxTimeMS'
=>
$self
->maxTimeMS )
: ()
),
'$query'
=> (
$self
->filter || {}),
};
$query
=
$query
->{
'$query'
}
if
keys
%$query
== 1 && !(
(
ref
(
$query
->{
'$query'
} ) eq
'Tie::IxHash'
)
?
$query
->{
'$query'
}->EXISTS(
'query'
)
:
exists
$query
->{
'$query'
}{query}
);
return
MongoDB::Op::_Query->_new(
db_name
=>
$self
->db_name,
coll_name
=>
$self
->coll_name,
client
=>
$self
->client,
bson_codec
=>
$self
->bson_codec,
query
=>
$query
,
projection
=>
$self
->projection,
batch_size
=>
$self
->batchSize,
limit
=>
$self
->limit,
skip
=>
$self
->skip,
query_flags
=> {
tailable
=> (
$self
->cursorType =~ /^tailable/ ? 1 : 0 ),
await_data
=>
$self
->cursorType eq
'tailable_await'
,
immortal
=>
$self
->noCursorTimeout,
partial
=>
$self
->allowPartialResults,
},
(
$extra_params
?
%$extra_params
: () ),
);
}
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 modifiers projection sort/
) {
my
(
$orig
) =
$args
{
$k
};
next
unless
$orig
;
if
(
ref
(
$orig
) eq
'Tie::IxHash'
) {
$args
{
$k
}= Tie::IxHash->new(
map
{
$_
=>
$orig
->FETCH(
$_
) }
$orig
->Keys );
}
elsif
(
ref
(
$orig
) eq
'ARRAY'
) {
$args
{
$k
}= [
@$orig
];
}
else
{
$args
{
$k
} = {
%$orig
};
}
}
return
ref
(
$self
)->_new(
%args
);
}
1;