From: David Kamholz <dkamholz@cpan.org>
Date: Tue, 7 Feb 2006 22:46:57 +0000 (+0000)
Subject: added ResultSource::Table::Cached
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5cc39991b2dd3f12c93c84932520fe376ba9b220;p=dbsrgits%2FDBIx-Class-Historic.git

added ResultSource::Table::Cached
---

diff --git a/lib/DBIx/Class/ResultSource/Table/Cached.pm b/lib/DBIx/Class/ResultSource/Table/Cached.pm
new file mode 100644
index 0000000..ebf40b4
--- /dev/null
+++ b/lib/DBIx/Class/ResultSource/Table/Cached.pm
@@ -0,0 +1,41 @@
+package DBIx::Class::ResultSource::Table::Cached;
+
+use Scalar::Util qw/weaken/;
+
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/ResultSource::Table/);
+
+sub resultset {
+  my $self = shift;
+  return $self->{_resultset} ||= do {
+      my $rs = $self->next::method;
+      weaken $rs->result_source;
+      $rs;
+  };
+}
+
+1;
+
+__END__
+
+=head1 NAME 
+
+DBIx::Class::ResultSource::Table::Cached - Table object that caches its own resultset
+
+=head1 DESCRIPTION
+
+This is a modified version of L<DBIx::Class::ResultSource::Table> that caches
+its resultset, so when you call $schema->resultset('Foo') it does not 
+re-instantiate the resultset each time. In pathological cases this may not
+work correctly, e.g. if you change important attributes of the result source
+object.
+
+=head1 AUTHORS
+
+David Kamholz <dkamholz@cpan.org>
+
+=head1 LICENSE
+
+You may distribute this code under the same terms as Perl itself.
+
+=cut