'MooseX::AttributeHelpers' => 0.12,
'MooseX::Types', => 0.10,
'namespace::clean' => 0.11,
+ 'Hash::Merge', => 0.11,
# t/96_is_deteministic_value.t
'DateTime::Format::Strptime' => 0,
MooseX::AttributeHelpers => '0.12',
MooseX::Types => '0.10',
namespace::clean => '0.11',
+ Hash::Merge => '0.11'
);
my @didnt_load;
use MooseX::Types::Moose qw/ClassName HashRef Object/;
use Scalar::Util 'reftype';
use Carp::Clan qw/^DBIx::Class/;
+use Hash::Merge 'merge';
use namespace::clean -except => 'meta';
MooseX::AttributeHelpers => 0.12
MooseX::Types => 0.10
namespace::clean => 0.11
+ Hash::Merge => 0.11
You will need to install these modules manually via CPAN or make them part of the
Makefile for your distribution.
my %opts;
for my $arg (@$info) {
next unless (reftype($arg)||'') eq 'HASH';
- %opts = (%opts, %$arg);
+ %opts = %{ merge($arg, \%opts) };
}
delete $opts{dsn};
$self->pool_type(delete $opts{pool_type})
if $opts{pool_type};
- $self->pool_args({
- %{ $self->pool_args },
- %{ delete $opts{pool_args} || {} }
- });
+ $self->pool_args(
+ merge((delete $opts{pool_args} || {}), $self->pool_args)
+ );
$self->pool($self->_build_pool)
if $self->pool;
$self->balancer_type(delete $opts{balancer_type})
if $opts{balancer_type};
- $self->balancer_args({
- %{ $self->balancer_args },
- %{ delete $opts{balancer_args} || {} }
- });
+ $self->balancer_args(
+ merge((delete $opts{balancer_args} || {}), $self->balancer_args)
+ );
$self->balancer($self->_build_balancer)
if $self->balancer;
$r->[$i] = {} unless $r->[$i];
# merge if two hashes
- my %opts = map %$_, @$r[$i .. $#{$r}];
+ my @hashes = @$r[$i .. $#{$r}];
+
+ croak "invalid connect_info options"
+ if (grep { reftype($_) eq 'HASH' } @hashes) != @hashes;
+
+ croak "too many hashrefs in connect_info"
+ if @hashes > 2;
+
+ my %opts = %{ merge(reverse @hashes) };
+
+# delete them
splice @$r, $i+1, ($#{$r} - $i), ();
# merge with master
- %opts = (%{ $self->_master_connect_info_opts }, %opts);
+ %opts = %{ merge(\%opts, $self->_master_connect_info_opts) };
# update
$r->[$i] = \%opts;
=head2 master_read_weight
-A number from 0 to 1 that specifies what weight to give the master when choosing
-which backend to execute a read query on. A value of 0, which is the default,
-does no reads from master, while a value of 1 gives it the same priority as any
-single replicant.
+A number greater than 0 that specifies what weight to give the master when
+choosing which backend to execute a read query on. A value of 0, which is the
+default, does no reads from master, while a value of 1 gives it the same
+priority as any single replicant.
+
+For example: if you have 2 replicants, and a L</master_read_weight> of C<0.5>,
+the chance of reading from master will be C<20%>.
+
+You can set it to a value higher than 1, making master have higher weight than
+any single replicant, if for example you have a very powerful master.
=cut