added ResultSource::Table::Cached
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / ResultSource / Table / Cached.pm
CommitLineData
5cc39991 1package DBIx::Class::ResultSource::Table::Cached;
2
3use Scalar::Util qw/weaken/;
4
5use base qw/DBIx::Class/;
6__PACKAGE__->load_components(qw/ResultSource::Table/);
7
8sub resultset {
9 my $self = shift;
10 return $self->{_resultset} ||= do {
11 my $rs = $self->next::method;
12 weaken $rs->result_source;
13 $rs;
14 };
15}
16
171;
18
19__END__
20
21=head1 NAME
22
23DBIx::Class::ResultSource::Table::Cached - Table object that caches its own resultset
24
25=head1 DESCRIPTION
26
27This is a modified version of L<DBIx::Class::ResultSource::Table> that caches
28its resultset, so when you call $schema->resultset('Foo') it does not
29re-instantiate the resultset each time. In pathological cases this may not
30work correctly, e.g. if you change important attributes of the result source
31object.
32
33=head1 AUTHORS
34
35David Kamholz <dkamholz@cpan.org>
36
37=head1 LICENSE
38
39You may distribute this code under the same terms as Perl itself.
40
41=cut