X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FReplicated.pm;h=8cb0fcd82e3ff8f804c338ed7b58c259c58a88b1;hb=bd5da3696c505d7f014320ef53e477985b5f7b3c;hp=0dc50d784f5d07bf13eec5b33bc367caf3bdf449;hpb=b88b85e73de8ca03cfd1f7bc2ee43d6403302986;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index 0dc50d7..8cb0fcd 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -7,11 +7,11 @@ BEGIN { ## use, so we explicitly test for these. my %replication_required = ( - Moose => '0.77', - MooseX::AttributeHelpers => '0.12', - MooseX::Types => '0.10', - namespace::clean => '0.11', - Hash::Merge => '0.11' + 'Moose' => '0.77', + 'MooseX::AttributeHelpers' => '0.12', + 'MooseX::Types' => '0.10', + 'namespace::clean' => '0.11', + 'Hash::Merge' => '0.11' ); my @didnt_load; @@ -324,6 +324,8 @@ C, C, C and C. around connect_info => sub { my ($next, $self, $info, @extra) = @_; + my $wantarray = wantarray; + my %opts; for my $arg (@$info) { next unless (reftype($arg)||'') eq 'HASH'; @@ -357,7 +359,20 @@ around connect_info => sub { $self->_master_connect_info_opts(\%opts); - $self->$next($info, @extra); + my (@res, $res); + if ($wantarray) { + @res = $self->$next($info, @extra); + } else { + $res = $self->$next($info, @extra); + } + + # Make sure master is blessed into the correct class and apply role to it. + my $master = $self->master; + $master->_determine_driver; + Moose::Meta::Class->initialize(ref $master); + DBIx::Class::Storage::DBI::Replicated::WithDSN->meta->apply($master); + + $wantarray ? @res : $res; }; =head1 METHODS @@ -391,7 +406,6 @@ Lazy builder for the L attribute. sub _build_master { my $self = shift @_; my $master = DBIx::Class::Storage::DBI->new($self->schema); - DBIx::Class::Storage::DBI::Replicated::WithDSN->meta->apply($master); $master } @@ -598,24 +612,11 @@ writea are sent to the master only sub set_balanced_storage { my $self = shift @_; my $schema = $self->schema; - my $write_handler = $self->schema->storage->balancer; + my $balanced_handler = $self->schema->storage->balancer; - $schema->storage->read_handler($write_handler); + $schema->storage->read_handler($balanced_handler); } -=head2 around: txn_do ($coderef) - -Overload to the txn_do method, which is delegated to whatever the -L is set to. We overload this in order to wrap in inside a -L method. - -=cut - -around 'txn_do' => sub { - my($txn_do, $self, $coderef, @args) = @_; - $self->execute_reliably(sub {$self->$txn_do($coderef, @args)}); -}; - =head2 connected Check that the master and at least one of the replicants is connected.