X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FReplicated.pm;h=3275de26cc450e9c5fadc10e19b1b3764d1cbe0c;hb=243d702ea2d1350e9c08d52eb84cdde745913452;hp=8badd5cd83c1699357c1841b35f552608c62b746;hpb=90a63099ad8b0269a300f6aa1c48d336e9e6c21e;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index 8badd5c..3275de2 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -7,9 +7,8 @@ BEGIN { ## use, so we explicitly test for these. my %replication_required = ( - 'Moose' => '0.87', - 'MooseX::AttributeHelpers' => '0.21', - 'MooseX::Types' => '0.16', + 'Moose' => '0.90', + 'MooseX::Types' => '0.21', 'namespace::clean' => '0.11', 'Hash::Merge' => '0.11' ); @@ -17,9 +16,9 @@ BEGIN { my @didnt_load; for my $module (keys %replication_required) { - eval "use $module $replication_required{$module}"; - push @didnt_load, "$module $replication_required{$module}" - if $@; + eval "use $module $replication_required{$module}"; + push @didnt_load, "$module $replication_required{$module}" + if $@; } croak("@{[ join ', ', @didnt_load ]} are missing and are required for Replication") @@ -33,7 +32,6 @@ use DBIx::Class::Storage::DBI::Replicated::Balancer; use DBIx::Class::Storage::DBI::Replicated::Types qw/BalancerClassNamePart DBICSchema DBICStorageDBI/; 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'; @@ -52,7 +50,9 @@ You should set the 'storage_type attribute to a replicated type. You should also define your arguments, such as which balancer you want and any arguments that the Pool object should get. + my $schema = Schema::Class->clone; $schema->storage_type( ['::DBI::Replicated', {balancer=>'::Random'}] ); + $schema->connection(...); Next, you need to add in the Replicants. Basically this is an array of arrayrefs, where each arrayref is database connect information. Think of these @@ -120,9 +120,8 @@ to force a query to run against Master when needed. Replicated Storage has additional requirements not currently part of L - Moose => '0.87', - MooseX::AttributeHelpers => '0.20', - MooseX::Types => '0.16', + Moose => '0.90', + MooseX::Types => '0.21', namespace::clean => '0.11', Hash::Merge => '0.11' @@ -326,7 +325,6 @@ has 'write_handler' => ( _count_select _subq_count_select _subq_update_delete - _order_select_columns svp_rollback svp_begin svp_release @@ -411,7 +409,7 @@ bits get put into the correct places. =cut sub BUILDARGS { - my ($class, $schema, $storage_type_args, @args) = @_; + my ($class, $schema, $storage_type_args, @args) = @_; return { schema=>$schema, @@ -495,7 +493,7 @@ around connect_replicants => sub { for my $r (@args) { $r = [ $r ] unless reftype $r eq 'ARRAY'; - croak "coderef replicant connect_info not supported" + $self->throw_exception('coderef replicant connect_info not supported') if ref $r->[0] && reftype $r->[0] eq 'CODE'; # any connect_info options? @@ -508,10 +506,10 @@ around connect_replicants => sub { # merge if two hashes my @hashes = @$r[$i .. $#{$r}]; - croak "invalid connect_info options" + $self->throw_exception('invalid connect_info options') if (grep { reftype($_) eq 'HASH' } @hashes) != @hashes; - croak "too many hashrefs in connect_info" + $self->throw_exception('too many hashrefs in connect_info') if @hashes > 2; my %opts = %{ merge(reverse @hashes) }; @@ -519,8 +517,15 @@ around connect_replicants => sub { # delete them splice @$r, $i+1, ($#{$r} - $i), (); +# make sure master/replicants opts don't clash + my %master_opts = %{ $self->_master_connect_info_opts }; + if (exists $opts{dbh_maker}) { + delete @master_opts{qw/dsn user password/}; + } + delete $master_opts{dbh_maker}; + # merge with master - %opts = %{ merge(\%opts, $self->_master_connect_info_opts) }; + %opts = %{ merge(\%opts, \%master_opts) }; # update $r->[$i] = \%opts;