is=>'ro',
isa=>'ClassName',
required=>1,
- default=>'DBIx::Class::Storage::DBI::Replicated::Replicant',
+ default=>'DBIx::Class::Storage::DBI',
handles=>{
'create_replicant' => 'new',
},
has 'replicants' => (
is=>'rw',
metaclass => 'Collection::Hash',
- isa=>'HashRef[DBIx::Class::Storage::DBI::Replicated::Replicant]',
+ isa=>'HashRef[DBIx::Class::Storage::DBI]',
default=>sub {{}},
provides => {
'set' => 'set_replicant',
=cut
+use Data::Dump qw/dump/;
+
sub connect_replicants {
my $self = shift @_;
my $schema = shift @_;
my @newly_created = ();
foreach my $connect_info (@_) {
+
my $replicant = $self->create_replicant($schema);
- $replicant->connect_info($connect_info);
+ $replicant->connect_info($connect_info);
$replicant->ensure_connected;
+
+ DBIx::Class::Storage::DBI::Replicated::Replicant->meta->apply($replicant);
+
my ($key) = ($connect_info->[0]=~m/^dbi\:.+\:(.+)$/);
$self->set_replicant( $key => $replicant);
push @newly_created, $replicant;
package DBIx::Class::Storage::DBI::Replicated::Replicant;
-use Moose;
-extends 'DBIx::Class::Storage::DBI', 'Moose::Object';
+use Moose::Role;
=head1 NAME
-DBIx::Class::Storage::DBI::Replicated::Replicant; A replicated DBI Storage
+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>. You
-shouldn't need to create instances of this class.
+This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>.
=head1 DESCRIPTION
$self->$method("DSN: $dsn SQL: $sql", @bind);
};
-=head2 is_replicating
-
-A boolean that reports if a particular L<DBIx::Class::Storage::DBI> is set to
-replicate from a master database. Default is false, which is the result
-returned by databases that don't support replication.
-
-=cut
-
-sub is_replicating {
- my $self = shift @_;
-}
-
-=head2 lag_behind_master
-
-Returns a number that represents a certain amount of lag behind a master db
-when a given storage is replicating. The number is database dependent, but
-starts at zero, which is the default, and increases with the amount of lag.
-
-=cut
-
-sub lag_behind_master {
- my $self = shift @_;
-}
=head1 AUTHOR
sub lag_behind_master {
my $self = shift @_;
+ return $self->dbh->selectrow_hashref('show slave status');
}
1;
use DBICTest;
BEGIN {
- eval "use Moose";
+ eval "use Moose; use Test::Moose";
plan $@
? ( skip_all => 'needs Moose for testing' )
- : ( tests => 40 );
+ : ( tests => 41 );
}
use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool';
is $replicated->schema->storage->num_replicants => 2
=> 'has two replicants';
-isa_ok $replicated_storages[0]
+does_ok $replicated_storages[0]
=> 'DBIx::Class::Storage::DBI::Replicated::Replicant';
-isa_ok $replicated_storages[1]
+does_ok $replicated_storages[1]
=> 'DBIx::Class::Storage::DBI::Replicated::Replicant';
my @replicant_names = keys %{$replicated->schema->storage->replicants};
-
-isa_ok $replicated->schema->storage->replicants->{$replicant_names[0]}
+
+does_ok $replicated->schema->storage->replicants->{$replicant_names[0]}
=> 'DBIx::Class::Storage::DBI::Replicated::Replicant';
-isa_ok $replicated->schema->storage->replicants->{$replicant_names[1]}
+does_ok $replicated->schema->storage->replicants->{$replicant_names[1]}
=> 'DBIx::Class::Storage::DBI::Replicated::Replicant';
## Add some info to the database
$replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
ok $replicated->schema->resultset('Artist')->find(2)
- => 'Fallback to master';
+ => 'Fallback to master';
+
+$replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
+$replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
+
+ok $replicated->schema->resultset('Artist')->find(2)
+ => 'Returned to replicates';
+
+## Getting slave status tests
+
+use Data::Dump qw/dump/;
+my $lag1 = $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master;
+warn dump $lag1;
## Delete the old database files
$replicated->cleanup;