Commit | Line | Data |
5cc39991 |
1 | package DBIx::Class::ResultSource::Table::Cached; |
2 | |
3 | use Scalar::Util qw/weaken/; |
4 | |
5 | use base qw/DBIx::Class/; |
6 | __PACKAGE__->load_components(qw/ResultSource::Table/); |
7 | |
8 | sub 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 | |
17 | 1; |
18 | |
19 | __END__ |
20 | |
21 | =head1 NAME |
22 | |
23 | DBIx::Class::ResultSource::Table::Cached - Table object that caches its own resultset |
24 | |
25 | =head1 DESCRIPTION |
26 | |
27 | This is a modified version of L<DBIx::Class::ResultSource::Table> that caches |
28 | its resultset, so when you call $schema->resultset('Foo') it does not |
29 | re-instantiate the resultset each time. In pathological cases this may not |
30 | work correctly, e.g. if you change important attributes of the result source |
31 | object. |
32 | |
33 | =head1 AUTHORS |
34 | |
35 | David Kamholz <dkamholz@cpan.org> |
36 | |
37 | =head1 LICENSE |
38 | |
39 | You may distribute this code under the same terms as Perl itself. |
40 | |
41 | =cut |