From: David Kamholz Date: Sat, 11 Feb 2006 17:35:05 +0000 (+0000) Subject: - fix DB.pm resultset_instance for CDBICompat usage X-Git-Tag: v0.06000~61^2~45 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1225fc4d302d2420ee57d0073f758cfb0e327c70;p=dbsrgits%2FDBIx-Class.git - fix DB.pm resultset_instance for CDBICompat usage - cache resultsets in ResultSource --- diff --git a/lib/DBIx/Class/DB.pm b/lib/DBIx/Class/DB.pm index 0fdb184..0e6ac17 100644 --- a/lib/DBIx/Class/DB.pm +++ b/lib/DBIx/Class/DB.pm @@ -14,7 +14,7 @@ __PACKAGE__->load_components(qw/ResultSetProxy/); sub storage { shift->schema_instance(@_)->storage; } sub resultset_instance { - my $class = shift; + my $class = ref $_[0] || $_[0]; my $source = $class->result_source_instance; if ($source->result_class ne $class) { $source = $source->new($source); diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index eff072b..c8341de 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -7,6 +7,7 @@ use DBIx::Class::ResultSet; use Carp::Clan qw/^DBIx::Class/; use Storable; +use Scalar::Util qw/weaken/; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/AccessorGroup/); @@ -33,7 +34,7 @@ retrieved, most usually a table (see L) sub new { my ($class, $attrs) = @_; $class = ref $class if ref $class; - my $new = bless({ %{$attrs || {}} }, $class); + my $new = bless({ %{$attrs || {}}, _resultset => undef }, $class); $new->{resultset_class} ||= 'DBIx::Class::ResultSet'; $new->{resultset_attributes} = { %{$new->{resultset_attributes} || {}} }; $new->{_ordered_columns} = [ @{$new->{_ordered_columns}||[]}]; @@ -522,7 +523,12 @@ Simple accessor. sub resultset { my $self = shift; - return $self->resultset_class->new($self, $self->{resultset_attributes}); + return $self->{_resultset} if ref $self->{_resultset} eq $self->resultset_class; + return $self->{_resultset} = do { + my $rs = $self->resultset_class->new($self, $self->{resultset_attributes}); + weaken $rs->result_source; + $rs; + }; } =head2 throw_exception