our
$VERSION
=
'v1.1.1'
;
-base,
-declare
=>
qw(
ArrayOfHashRef
AuthMechanism
Booleanpm
BSONCodec
ConnectType
CursorType
DBRefColl
DBRefDB
Document
ErrorStr
HashLike
HostAddress
HostAddressList
IndexModel
IndexModelList
IxHash
MongoDBCollection
MongoDBDatabase
MongoDBQuery
NonEmptyStr
NonNegNum
OID
OrderedDoc
PairArrayRef
ReadPrefMode
ReadConcern
ReadPreference
ServerDesc
ServerType
SingleChar
SingleKeyHash
TopologyType
WriteConcern
)
;
Any
ArrayRef
Dict
HashRef
Maybe
Num
Optional
Ref
Str
Undef
)
;
declare ArrayOfHashRef, as ArrayRef [HashRef];
enum AuthMechanism,
[
qw/NONE DEFAULT MONGODB-CR MONGODB-X509 GSSAPI PLAIN SCRAM-SHA-1/
];
class_type Booleanpm, {
class
=>
'boolean'
};
duck_type BSONCodec, [
qw/encode_one decode_one/
];
enum ConnectType, [
qw/replicaSet direct none/
];
enum CursorType, [
qw/non_tailable tailable tailable_await/
];
declare ErrorStr, as Str, where {
$_
};
declare HashLike, as Ref, where { reftype(
$_
) eq
'HASH'
};
declare HostAddress, as Str,
where {
$_
=~ /^[^:]+:[0-9]+$/ and
lc
(
$_
) eq
$_
}, message {
"Address '$_' not formatted as 'hostname:port'"
};
declare HostAddressList, as ArrayRef [HostAddress], message {
"Address list <@$_> is not all hostname:port pairs"
};
class_type IxHash, {
class
=>
'Tie::IxHash'
};
declare MaybeHashRef, as Maybe[ HashRef ];
class_type MongoDBCollection, {
class
=>
'MongoDB::Collection'
};
class_type MongoDBDatabase, {
class
=>
'MongoDB::Database'
};
class_type MongoDBQuery, {
class
=>
'MongoDB::_Query'
};
declare NonEmptyStr, as Str, where {
defined
$_
&&
length
$_
};
declare NonNegNum, as Num,
where {
defined
(
$_
) &&
$_
>= 0 },
message {
"value must be a non-negative number"
};
declare OID, as Str, where { /\A[0-9a-f]{24}\z/ }, message {
"Value '$_' is not a valid OID"
};
declare PairArrayRef, as ArrayRef,
where {
@$_
% 2 == 0 };
enum ReadPrefMode,
[
qw/primary primaryPreferred secondary secondaryPreferred nearest/
];
class_type ReadPreference, {
class
=>
'MongoDB::ReadPreference'
};
class_type ReadConcern, {
class
=>
'MongoDB::ReadConcern'
};
class_type ServerDesc, {
class
=>
'MongoDB::_Server'
};
enum ServerType,
[
qw/Standalone Mongos PossiblePrimary RSPrimary RSSecondary RSArbiter RSOther RSGhost Unknown/
];
declare SingleChar, as Str, where {
length
$_
eq 1 };
declare SingleKeyHash, as HashRef, where { 1 ==
scalar
keys
%$_
};
enum TopologyType,
[
qw/Single ReplicaSetNoPrimary ReplicaSetWithPrimary Sharded Unknown/
];
class_type WriteConcern, {
class
=>
'MongoDB::WriteConcern'
};
declare OrderedDoc, as PairArrayRef|IxHash|SingleKeyHash;
declare Document, as HashRef|PairArrayRef|IxHash|HashLike;
declare DBRefColl, as NonEmptyStr;
declare DBRefDB, as NonEmptyStr|Undef;
declare IndexModel, as Dict [
keys
=> OrderedDoc,
options
=> Optional [HashRef] ];
declare IndexModelList, as ArrayRef [IndexModel];
coerce ArrayOfHashRef, from HashRef, via { [
$_
] };
coerce BSONCodec, from HashRef,
coerce Booleanpm, from Any, via { boolean(
$_
) };
coerce DBRefColl, from MongoDBCollection, via {
$_
->name };
coerce DBRefDB, from MongoDBDatabase, via {
$_
->name };
coerce ErrorStr, from Str, via {
$_
||
"unspecified error"
};
coerce HostAddress, from Str, via { /:/ ?
lc
$_
:
lc
"$_:27017"
};
coerce HostAddressList, from ArrayRef, via {
[
map
{ /:/ ?
lc
$_
:
lc
"$_:27017"
}
@$_
]
};
coerce ReadPrefMode, from Str, via {
$_
=
lc
$_
; s/_?preferred/Preferred/;
$_
};
coerce IxHash, from HashRef, via { Tie::IxHash->new(
%$_
) };
coerce IxHash, from ArrayRef, via { Tie::IxHash->new(
@$_
) };
coerce IxHash, from HashLike, via { Tie::IxHash->new(
%$_
) };
coerce OID, from Str, via {
lc
$_
};
coerce ReadPreference, from HashRef,
coerce ReadPreference, from Str,
coerce ReadPreference, from ArrayRef,
coerce ReadConcern, from Str,
coerce ReadConcern, from HashRef,
coerce WriteConcern, from HashRef,
1;