workaround for Moose bug affecting Replicated storage
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Replicated / Replicant.pm
index 2367d4a..f5b4f34 100644 (file)
@@ -2,15 +2,20 @@ package DBIx::Class::Storage::DBI::Replicated::Replicant;
 
 use Moose::Role;
 requires qw/_query_start/;
+with 'DBIx::Class::Storage::DBI::Replicated::WithDSN';
+use MooseX::Types::Moose qw/Bool Str/;
+use DBIx::Class::Storage::DBI::Replicated::Types 'DBICStorageDBI';
+
+use namespace::clean -except => 'meta';
 
 =head1 NAME
 
-DBIx::Class::Storage::DBI::Replicated::Replicant; A replicated DBI Storage Role
+DBIx::Class::Storage::DBI::Replicated::Replicant - A replicated DBI Storage Role
 
 =head1 SYNOPSIS
 
 This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>.
-    
+
 =head1 DESCRIPTION
 
 Replicants are DBI Storages that follow a master DBI Storage.  Typically this
@@ -42,27 +47,26 @@ storage driver for more information.
 
 has 'active' => (
   is=>'rw',
-  isa=>'Bool',
+  isa=>Bool,
   lazy=>1,
   required=>1,
   default=>1,
 );
 
-=head1 METHODS
-
-This class defines the following methods.
+has dsn => (is => 'rw', isa => Str);
+has id  => (is => 'rw', isa => Str);
 
-=head2 after: _query_start
+=head2 master
 
-advice iof the _query_start method to add more debuggin
+Reference to the master Storage.
 
 =cut
 
-around '_query_start' => sub {
-  my ($method, $self, $sql, @bind) = @_;
-  my $dsn = $self->connect_info->[0];
-  $self->$method("DSN: $dsn SQL: $sql", @bind);
-};
+has master => (is => 'rw', isa => DBICStorageDBI, weak_ref => 1);
+
+=head1 METHODS
+
+This class defines the following methods.
 
 =head2 debugobj
 
@@ -71,12 +75,15 @@ Override the debugobj method to redirect this method call back to the master.
 =cut
 
 sub debugobj {
-    return shift->schema->storage->debugobj;
+  my $self = shift;
+
+  return $self->master->debugobj;
 }
 
 =head1 ALSO SEE
 
-L<<a href="http://en.wikipedia.org/wiki/Replicant">http://en.wikipedia.org/wiki/Replicant</a>>
+L<http://en.wikipedia.org/wiki/Replicant>,
+L<DBIx::Class::Storage::DBI::Replicated>
 
 =head1 AUTHOR
 
@@ -88,4 +95,4 @@ You may distribute this code under the same terms as Perl itself.
 
 =cut
 
-1;
\ No newline at end of file
+1;