Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Commit

Permalink
convert type system to Type::Tiny
Browse files Browse the repository at this point in the history
  • Loading branch information
xdg committed Feb 26, 2015
1 parent 765457f commit c171c3e
Show file tree
Hide file tree
Showing 50 changed files with 425 additions and 324 deletions.
1 change: 1 addition & 0 deletions Makefile.PL
Expand Up @@ -28,6 +28,7 @@ requires 'Throwable';
requires 'Tie::IxHash';
requires 'Time::HiRes';
requires 'Try::Tiny';
requires 'Type::Tiny' => '1';
requires 'boolean';
requires 'namespace::clean';
requires 'version';
Expand Down
5 changes: 3 additions & 2 deletions lib/MongoDB/BSON/Binary.pm
Expand Up @@ -23,6 +23,7 @@ use version;
our $VERSION = 'v0.999.998.3'; # TRIAL

use Moose;
use Types::Standard -types;
use namespace::clean -except => 'meta';

=head1 NAME
Expand Down Expand Up @@ -96,7 +97,7 @@ A string of binary data.

has data => (
is => 'ro',
isa => 'Str',
isa => Str,
required => 1
);

Expand All @@ -108,7 +109,7 @@ A subtype. Defaults to C<SUBTYPE_GENERIC>.

has subtype => (
is => 'ro',
isa => 'Int',
isa => Int,
required => 0,
default => MongoDB::BSON::Binary->SUBTYPE_GENERIC
);
Expand Down
5 changes: 3 additions & 2 deletions lib/MongoDB/BSON/Regexp.pm
Expand Up @@ -5,17 +5,18 @@ use version;
our $VERSION = 'v0.999.998.3'; # TRIAL

use Moose;
use Types::Standard -types;
use namespace::clean -except => 'meta';

has pattern => (
is => 'ro',
isa => 'Str',
isa => Str,
required => 1,
);

has flags => (
is => 'ro',
isa => 'Str',
isa => Str,
required => 0,
predicate => 'has_flags',
writer => '_set_flags',
Expand Down
13 changes: 7 additions & 6 deletions lib/MongoDB/BulkWrite.pm
Expand Up @@ -29,6 +29,7 @@ use MongoDB::BulkWriteView;
use Syntax::Keyword::Junction qw/any/;

use Moose;
use Types::Standard -types;
use namespace::clean -except => 'meta';

=attr collection (required)
Expand All @@ -39,7 +40,7 @@ The L<MongoDB::Collection> where the operations are to be performed.

has 'collection' => (
is => 'ro',
isa => 'MongoDB::Collection',
isa => InstanceOf['MongoDB::Collection'],
required => 1,
);

Expand All @@ -52,20 +53,20 @@ unordered (false).

has 'ordered' => (
is => 'ro',
isa => 'Bool',
isa => Bool,
required => 1,
);

has '_executed' => (
is => 'rw',
isa => 'Bool',
isa => Bool,
init_arg => undef,
default => 0,
);

has '_queue' => (
is => 'rw',
isa => 'ArrayRef[ArrayRef]',
isa => ArrayRef[ArrayRef],
init_arg => undef,
default => sub { [] },
traits => ['Array'],
Expand All @@ -79,7 +80,7 @@ has '_queue' => (

has '_database' => (
is => 'ro',
isa => 'MongoDB::Database',
isa => InstanceOf['MongoDB::Database'],
lazy_build => 1,
);

Expand All @@ -90,7 +91,7 @@ sub _build__database {

has '_client' => (
is => 'ro',
isa => 'MongoDB::MongoClient',
isa => InstanceOf['MongoDB::MongoClient'],
lazy_build => 1,
);

Expand Down
13 changes: 7 additions & 6 deletions lib/MongoDB/BulkWriteResult.pm
Expand Up @@ -26,23 +26,24 @@ our @ISA = qw/MongoDB::WriteResult/;

use Moose;
use MongoDB::Error;
use MongoDB::_Types;
use MongoDB::_Types -types;
use Types::Standard -types;
use Syntax::Keyword::Junction qw/any/;
use namespace::clean -except => 'meta';

with 'MongoDB::Role::_WriteResult';

has upserted_ids => (
is => 'ro',
isa => 'ArrayOfHashRef',
isa => ArrayOfHashRef,
coerce => 1,
default => sub { [] },
);

for my $attr (qw/inserted_count upserted_count matched_count deleted_count/) {
has $attr => (
is => 'ro',
isa => 'Num',
isa => Num,
writer => "_set_$attr",
default => 0,
);
Expand All @@ -55,21 +56,21 @@ for my $attr (qw/inserted_count upserted_count matched_count deleted_count/) {

has modified_count => (
is => 'ro',
isa => 'Maybe[Num]',
isa => Maybe[Num],
writer => '_set_modified_count',
default => undef,
);

has op_count => (
is => 'ro',
isa => 'Num',
isa => Num,
writer => '_set_op_count',
default => 0,
);

has batch_count => (
is => 'ro',
isa => 'Num',
isa => Num,
writer => '_set_batch_count',
default => 0,
);
Expand Down
8 changes: 5 additions & 3 deletions lib/MongoDB/BulkWriteView.pm
Expand Up @@ -24,28 +24,30 @@ our $VERSION = 'v0.999.998.3'; # TRIAL
use Moose;

use Syntax::Keyword::Junction qw/any/;
use MongoDB::_Types -types;
use Types::Standard -types;
use boolean;
use namespace::clean -except => 'meta';

# A hash reference containing a MongoDB query document
has _query => (
is => 'ro',
isa => 'IxHash',
isa => IxHash,
coerce => 1,
required => 1
);

# Originating bulk write object for executing write operations.
has _bulk => (
is => 'ro',
isa => 'MongoDB::BulkWrite',
isa => InstanceOf['MongoDB::BulkWrite'],
required => 1,
handles => [qw/_enqueue_write/]
);

has _upsert => (
is => 'ro',
isa => 'boolean',
isa => Booleanpm,
default => sub { false },
);

Expand Down
5 changes: 3 additions & 2 deletions lib/MongoDB/Code.pm
Expand Up @@ -29,6 +29,7 @@ MongoDB::Code - JavaScript code
=cut

use Moose;
use Types::Standard -types;
use namespace::clean -except => 'meta';

=head1 ATTRIBUTES
Expand All @@ -41,7 +42,7 @@ A string of JavaScript code.

has code => (
is => 'ro',
isa => 'Str',
isa => Str,
required => 1,
);

Expand All @@ -53,7 +54,7 @@ An optional hash of variables to pass as the scope.

has scope => (
is => 'ro',
isa => 'HashRef',
isa => HashRef,
required => 0,
);

Expand Down
14 changes: 8 additions & 6 deletions lib/MongoDB/Collection.pm
Expand Up @@ -31,6 +31,8 @@ use MongoDB::Op::_InsertOne;
use MongoDB::Op::_InsertMany;
use MongoDB::Op::_ListIndexes;
use MongoDB::Op::_Update;
use MongoDB::_Types -types;
use Types::Standard -types;
use Tie::IxHash;
use Carp 'carp';
use boolean;
Expand All @@ -43,13 +45,13 @@ use namespace::clean -except => 'meta';

has _database => (
is => 'ro',
isa => 'MongoDB::Database',
isa => InstanceOf['MongoDB::Database'],
required => 1,
);

has _client => (
is => 'ro',
isa => 'MongoDB::MongoClient',
isa => InstanceOf['MongoDB::MongoClient'],
lazy => 1,
builder => '_build__client',
);
Expand All @@ -62,7 +64,7 @@ The name of the collection.

has name => (
is => 'ro',
isa => 'Str',
isa => Str,
required => 1,
);

Expand All @@ -75,7 +77,7 @@ in.

has full_name => (
is => 'ro',
isa => 'Str',
isa => Str,
lazy => 1,
builder => '_build_full_name',
);
Expand All @@ -90,7 +92,7 @@ that will be coerced into a new MongoDB::ReadPreference object.

has read_preference => (
is => 'ro',
isa => 'ReadPreference',
isa => ReadPreference,
required => 1,
coerce => 1,
);
Expand All @@ -104,7 +106,7 @@ reference that will be coerced into a new MongoDB::WriteConcern object.

has write_concern => (
is => 'ro',
isa => 'WriteConcern',
isa => WriteConcern,
required => 1,
coerce => 1,
);
Expand Down
6 changes: 4 additions & 2 deletions lib/MongoDB/CommandResult.pm
Expand Up @@ -23,6 +23,8 @@ our $VERSION = 'v0.999.998.3'; # TRIAL

use Moose;
use MongoDB::Error;
use MongoDB::_Types -types;
use Types::Standard -types;
use namespace::clean -except => 'meta';

with 'MongoDB::Role::_LastError';
Expand All @@ -35,7 +37,7 @@ Hash reference with the result of a database command

has result => (
is => 'ro',
isa => 'HashRef',
isa => HashRef,
required => 1,
);

Expand All @@ -47,7 +49,7 @@ Address ("host:port") of server that ran the command

has address => (
is => 'ro',
isa => 'HostAddress',
isa => HostAddress,
required => 1,
);

Expand Down
7 changes: 4 additions & 3 deletions lib/MongoDB/Cursor.pm
Expand Up @@ -28,7 +28,8 @@ use MongoDB::BSON;
use MongoDB::Error;
use MongoDB::QueryResult;
use MongoDB::_Protocol;
use MongoDB::_Types;
use MongoDB::_Types -types;
use Types::Standard -types;
use boolean;
use Tie::IxHash;
use Try::Tiny;
Expand Down Expand Up @@ -107,14 +108,14 @@ with 'MongoDB::Role::_Cursor';
# attributes for sending a query
has query => (
is => 'ro',
isa => 'MongoDB::_Query',
isa => InstanceOf['MongoDB::_Query'],
required => 1,
);

# lazy result attribute
has result => (
is => 'ro',
isa => 'MongoDB::QueryResult',
isa => InstanceOf['MongoDB::QueryResult'],
lazy => 1,
builder => '_build_result',
predicate => 'started_iterating',
Expand Down
13 changes: 7 additions & 6 deletions lib/MongoDB/DBRef.pm
Expand Up @@ -24,7 +24,8 @@ our $VERSION = 'v0.999.998.3'; # TRIAL
use Carp 'croak';
use Tie::IxHash;
use Moose;
use MongoDB::_Types;
use MongoDB::_Types -types;
use Types::Standard -types;
use namespace::clean -except => 'meta';

# no type constraint since an _id can be anything
Expand All @@ -35,34 +36,34 @@ has id => (

has ref => (
is => 'rw',
isa => 'DBRefColl',
isa => DBRefColl,
required => 1,
coerce => 1,
);

has db => (
is => 'rw',
isa => 'DBRefDB',
isa => DBRefDB,
required => 1,
coerce => 1,
);

has client => (
is => 'rw',
isa => 'MongoDB::MongoClient',
isa => InstanceOf['MongoDB::MongoClient'],
required => 0
);

has verify_db => (
is => 'rw',
isa => 'Bool',
isa => Bool,
required => 0,
default => 1
);

has verify_coll => (
is => 'rw',
isa => 'Bool',
isa => Bool,
required => 0,
default => 1
);
Expand Down

0 comments on commit c171c3e

Please sign in to comment.