Port ::Replicated from Moose to Moo+Type::Tiny
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Replicated.pm
index 273b218..852c816 100644 (file)
@@ -10,19 +10,22 @@ BEGIN {
   }
 }
 
-use Moose;
+use Moo;
 use DBIx::Class::Storage::DBI;
 use DBIx::Class::Storage::DBI::Replicated::Pool;
 use DBIx::Class::Storage::DBI::Replicated::Balancer;
 use DBIx::Class::Storage::DBI::Replicated::Types qw/BalancerClassNamePart DBICSchema DBICStorageDBI/;
-use MooseX::Types::Moose qw/ClassName HashRef Object/;
-use Scalar::Util 'reftype';
+use Types::Standard qw/ClassName HashRef Object/;
+use Type::Utils qw(class_type role_type);
+use Scalar::Util qw(reftype blessed);
+use Sub::Name qw(subname);
 use Hash::Merge;
 use List::Util qw/min max reduce/;
 use Context::Preserve 'preserve_context';
+use Class::Inspector;
 use Try::Tiny;
 
-use namespace::clean -except => 'meta';
+use namespace::clean;
 
 =head1 NAME
 
@@ -203,8 +206,11 @@ container class for one or more replicated databases.
 
 has 'pool' => (
   is=>'ro',
-  isa=>'DBIx::Class::Storage::DBI::Replicated::Pool',
-  lazy_build=>1,
+  isa=>class_type('DBIx::Class::Storage::DBI::Replicated::Pool'),
+  lazy=>1,
+  builder=>1,
+  predicate=>1,
+  clearer=>1,
   handles=>[qw/
     connect_replicants
     replicants
@@ -221,8 +227,11 @@ is a class that takes a pool (L<DBIx::Class::Storage::DBI::Replicated::Pool>)
 
 has 'balancer' => (
   is=>'rw',
-  isa=>'DBIx::Class::Storage::DBI::Replicated::Balancer',
-  lazy_build=>1,
+  isa=>role_type('DBIx::Class::Storage::DBI::Replicated::Balancer'),
+  lazy=>1,
+  builder=>1,
+  predicate=>1,
+  clearer=>1,
   handles=>[qw/auto_validate_every/],
 );
 
@@ -239,7 +248,10 @@ pool of databases that is allowed to handle write traffic.
 has 'master' => (
   is=> 'ro',
   isa=>DBICStorageDBI,
-  lazy_build=>1,
+  lazy=>1,
+  builder=>1,
+  predicate=>1,
+  clearer=>1,
 );
 
 =head1 ATTRIBUTES IMPLEMENTING THE DBIx::Storage::DBI INTERFACE
@@ -322,7 +334,7 @@ my $method_dispatch = {
     _execute
     _do_query
     _dbh_execute
-  /, Class::MOP::Class->initialize('DBIx::Class::Storage::DBIHacks')->get_method_list ],
+  /, @{Class::Inspector->functions('DBIx::Class::Storage::DBIHacks')} ],
   reader => [qw/
     select
     select_single
@@ -366,10 +378,9 @@ my $method_dispatch = {
     _bind_sth_params
   /,(
     # the capability framework
-    # not sure if CMOP->initialize does evil things to DBIC::S::DBI, fix if a problem
     grep
       { $_ =~ /^ _ (?: use | supports | determine_supports ) _ /x and $_ ne '_use_multicolumn_in' }
-      ( Class::MOP::Class->initialize('DBIx::Class::Storage::DBI')->get_all_method_names )
+      @{Class::Inspector->functions('DBIx::Class::Storage::DBI')}
   )],
 };
 
@@ -400,10 +411,11 @@ if (DBIx::Class::_ENV_::DBICTEST) {
 }
 
 for my $method (@{$method_dispatch->{unimplemented}}) {
-  __PACKAGE__->meta->add_method($method, sub {
+  no strict 'refs';
+  *{$method} = subname $method, sub {
     my $self = shift;
     $self->throw_exception("$method() must not be called on ".(blessed $self).' objects');
-  });
+  };
 }
 
 =head2 read_handler
@@ -415,7 +427,10 @@ Defines an object that implements the read side of L<DBIx::Class::Storage::DBI>.
 has 'read_handler' => (
   is=>'rw',
   isa=>Object,
-  lazy_build=>1,
+  lazy=>1,
+  builder=>1,
+  predicate=>1,
+  clearer=>1,
   handles=>$method_dispatch->{reader},
 );
 
@@ -431,7 +446,10 @@ run on a replicant.
 has 'write_handler' => (
   is=>'ro',
   isa=>Object,
-  lazy_build=>1,
+  lazy=>1,
+  builder=>1,
+  predicate=>1,
+  clearer=>1,
   handles=>$method_dispatch->{writer},
 );
 
@@ -498,9 +516,11 @@ around connect_info => sub {
     # Make sure master is blessed into the correct class and apply role to it.
     my $master = $self->master;
     $master->_determine_driver;
-    Moose::Meta::Class->initialize(ref $master);
 
-    DBIx::Class::Storage::DBI::Replicated::WithDSN->meta->apply($master);
+    Moo::Role->apply_roles_to_object(
+      $master,
+      'DBIx::Class::Storage::DBI::Replicated::WithDSN',
+    );
 
     # link pool back to master
     $self->pool->master($master);
@@ -1131,6 +1151,4 @@ L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
 
 =cut
 
-__PACKAGE__->meta->make_immutable;
-
 1;