1 package DBIx::Class::ResultSetManager;
3 use base 'DBIx::Class';
6 __PACKAGE__->mk_classdata($_) for qw/ base_resultset_class table_resultset_class_suffix /;
7 __PACKAGE__->base_resultset_class('DBIx::Class::ResultSet');
8 __PACKAGE__->table_resultset_class_suffix('::_resultset');
11 my ($self,@rest) = @_;
12 my $ret = $self->next::method(@rest);
14 $self->_register_attributes;
15 $self->_register_resultset_class;
20 sub load_resultset_components {
21 my ($self,@comp) = @_;
22 my $resultset_class = $self->_setup_resultset_class;
23 $resultset_class->load_components(@comp);
26 sub _register_attributes {
28 return unless $self->can('_attr_cache');
30 my $cache = $self->_attr_cache;
31 foreach my $meth (@{Class::Inspector->methods($self) || []}) {
32 my $attrs = $cache->{$self->can($meth)};
34 if ($attrs->[0] eq 'ResultSet') {
36 my $resultset_class = $self->_setup_resultset_class;
37 *{"$resultset_class\::$meth"} = $self->can($meth);
38 delete ${"${self}::"}{$meth};
43 sub _setup_resultset_class {
45 my $resultset_class = $self . $self->table_resultset_class_suffix;
47 unless (@{"$resultset_class\::ISA"}) {
48 @{"$resultset_class\::ISA"} = ($self->base_resultset_class);
50 return $resultset_class;
53 sub _register_resultset_class {
55 my $resultset_class = $self . $self->table_resultset_class_suffix;
57 if (@{"$resultset_class\::ISA"}) {
58 $self->result_source_instance->resultset_class($resultset_class);
60 $self->result_source_instance->resultset_class($self->base_resultset_class);
70 DBIx::Class::ResultSetManager - helpful methods for managing resultset classes (EXPERIMENTAL)
75 __PACKAGE__->load_components(qw/ResultSetManager/);
76 __PACKAGE__->load_resultset_components(qw/AlwaysRS/);
78 # will be removed from the table class and inserted into a table-specific resultset class
79 sub foo : ResultSet { ... }
83 This package implements two useful features for customizing resultset classes.
84 C<load_resultset_components> loads components in addition to C<DBIx::Class::ResultSet>
85 (or whatever you set as C<base_resultset_class>). Any methods tagged with the C<ResultSet>
86 attribute will be moved into a table-specific resultset class (by default called
87 C<Class::_resultset>).
91 David Kamholz <dkamholz@cpan.org>
95 You may distribute this code under the same terms as Perl itself.