tasks.
## Change storage_type in your schema class
- $schema->storage_type( '::DBI::Replicated' );
+ $schema->storage_type( ['::DBI::Replicated', {balancer=>'::Random'}] );
## Add some slaves. Basically this is an array of arrayrefs, where each
## arrayref is database connect information
has 'pool_type' => (
is=>'ro',
isa=>'ClassName',
- required=>1,
- lazy=>1,
- default=>'DBIx::Class::Storage::DBI::Replicated::Pool',
+ lazy_build=>1,
handles=>{
'create_pool' => 'new',
},
);
-
=head2 balancer_type
The replication pool requires a balance class to provider the methods for
has 'balancer_type' => (
is=>'ro',
isa=>'ClassName',
- required=>1,
- lazy=>1,
- default=>'DBIx::Class::Storage::DBI::Replicated::Balancer',
+ lazy_build=>1,
handles=>{
'create_balancer' => 'new',
},
);
+=head2 balancer_args
+
+Contains a hashref of initialized information to pass to the Balancer object.
+See L<DBIx::Class::Storage::Replicated::Pool> for available arguments.
+
+=cut
+
+has 'balancer_args' => (
+ is=>'ro',
+ isa=>'HashRef',
+);
=head2 pool
connect_replicants
replicants
has_replicants
- num_replicants
- delete_replicant
/],
);
-
=head2 balancer
Is a <DBIx::Class::Storage::DBI::Replicated::Balancer> or derived class. This
is=>'ro',
isa=>'DBIx::Class::Storage::DBI::Replicated::Balancer',
lazy_build=>1,
+ handles=>[qw/auto_validate_every/],
);
-
=head2 master
The master defines the canonical state for a pool of connected databases. All
lazy_build=>1,
);
-
=head1 ATTRIBUTES IMPLEMENTING THE DBIx::Storage::DBI INTERFACE
The following methods are delegated all the methods required for the
/],
);
-
=head2 write_handler
Defines an object that implements the write side of L<BIx::Class::Storage::DBI>.
/],
);
-
=head1 METHODS
This class defines the following methods.
my $schema = shift @_;
my $storage_type_args = shift @_;
my $obj = $class->SUPER::new($schema, $storage_type_args, @_);
-
+
+ ## Hate to do it this way, but can't seem to get advice on the attribute working right
+ ## maybe we can do a type and coercion for it.
+ if( $storage_type_args->{balancer_type} && $storage_type_args->{balancer_type}=~m/^::/) {
+ $storage_type_args->{balancer_type} = 'DBIx::Class::Storage::DBI::Replicated::Balancer'.$storage_type_args->{balancer_type};
+ eval "require $storage_type_args->{balancer_type}";
+ }
+
return $class->meta->new_object(
__INSTANCE__ => $obj,
%$storage_type_args,
DBIx::Class::Storage::DBI->new;
}
+=head2 _build_pool_type
+
+Lazy builder for the L</pool_type> attribute.
+
+=cut
+
+sub _build_pool_type {
+ return 'DBIx::Class::Storage::DBI::Replicated::Pool';
+}
+
=head2 _build_pool
Lazy builder for the L</pool> attribute.
=cut
sub _build_pool {
- shift->create_pool;
+ my $self = shift @_;
+ $self->create_pool;
+}
+
+=head2 _build_balancer_type
+
+Lazy builder for the L</balancer_type> attribute.
+
+=cut
+
+sub _build_balancer_type {
+ return 'DBIx::Class::Storage::DBI::Replicated::Balancer::First';
}
=head2 _build_balancer
sub _build_balancer {
my $self = shift @_;
- $self->create_balancer(pool=>$self->pool);
+ $self->create_balancer(
+ pool=>$self->pool,
+ master=>$self->master,
+ %{$self->balancer_args},);
}
=head2 _build_write_handler