This class defines the following methods.
-=head2 new
+=head2 BUILDARGS
L<DBIx::Class::Schema> when instantiating it's storage passed itself as the
first argument. So we need to massage the arguments a bit so that all the
=cut
-around 'new' => sub {
- my ($new, $self, $schema, $storage_type_args, @args) = @_;
- return $self->$new(schema=>$schema, %$storage_type_args, @args);
-};
+sub BUILDARGS {
+ my ($class, $schema, $storage_type_args, @args) = @_;
+
+ return {
+ schema=>$schema,
+ %$storage_type_args,
+ @args
+ }
+}
=head2 _build_master
=cut
+__PACKAGE__->meta->make_immutable;
+
1;
package DBIx::Class::Storage::DBI::Replicated::Balancer::First;
-use List::Util qw(shuffle);
use Moose;
with 'DBIx::Class::Storage::DBI::Replicated::Balancer';
=cut
+__PACKAGE__->meta->make_immutable;
+
1;
\ No newline at end of file
=cut
sub next_storage {
- return (shuffle(shift->pool->active_replicants))[0];
+ my $self = shift @_;
+ my @active_replicants = $self->pool->active_replicants;
+ my $count_active_replicants = $#active_replicants +1;
+
+ return $active_replicants[int(rand($count_active_replicants +1))];
}
=head1 AUTHOR
=cut
+__PACKAGE__->meta->make_immutable;
+
1;
\ No newline at end of file
=cut
+__PACKAGE__->meta->make_immutable;
+
1;
eval "use Moose; use Test::Moose";
plan $@
? ( skip_all => 'needs Moose for testing' )
- : ( tests => 80 );
+ : ( tests => 79 );
}
use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool';
[ 7, "Watergate"],
]);
-SKIP: {
- ## We can't do this test if we have a custom replicants, since we assume
- ## if there are custom one that you are trying to test a real replicating
- ## system. See docs above for more.
-
- skip 'Cannot test inconsistent replication since you have a real replication system', 1
- if DBICTest->has_custom_dsn && $ENV{"DBICTEST_SLAVE0_DSN"};
-
- ## Alright, the database 'cluster' is not in a consistent state. When we do
- ## a read now we expect bad news
- is $replicated->schema->resultset('Artist')->find(5), undef
- => 'read after disconnect fails because it uses a replicant which we have neglected to "replicate" yet';
-}
-
## Make sure all the slaves have the table definitions
$replicated->replicate;