1) changed all 4 space indentation to 2 space style indents for replication code...
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / ResultSetManager.pm
CommitLineData
db57afbb 1package DBIx::Class::ResultSetManager;
ed28f830 2use strict;
bf5ecff9 3use warnings;
ed28f830 4use base 'DBIx::Class';
5use Class::Inspector;
6
748ab0dc 7warn "DBIx::Class::ResultSetManager never left experimental status and
8has now been DEPRECATED. This module will be deleted in 09000 so please
9migrate any and all code using it to explicit resultset classes using either
10__PACKAGE__->resultset_class(...) calls or by switching from using
11DBIx::Class::Schema->load_classes() to load_namespaces() and creating
12appropriate My::Schema::ResultSet::* classes for it to pick up.";
bc0c9800 13
748ab0dc 14=head1 NAME
bc0c9800 15
748ab0dc 16DBIx::Class::ResultSetManager - scheduled for deletion in 09000
bc0c9800 17
18=head1 DESCRIPTION
19
748ab0dc 20DBIx::Class::ResultSetManager never left experimental status and
21has now been DEPRECATED. This module will be deleted in 09000 so please
22migrate any and all code using it to explicit resultset classes using either
23__PACKAGE__->resultset_class(...) calls or by switching from using
24DBIx::Class::Schema->load_classes() to load_namespaces() and creating
25appropriate My::Schema::ResultSet::* classes for it to pick up.";
bc0c9800 26
27=cut
28
24d67825 29__PACKAGE__->mk_classdata($_)
30 for qw/ base_resultset_class table_resultset_class_suffix /;
570783b1 31__PACKAGE__->base_resultset_class('DBIx::Class::ResultSet');
f0750722 32__PACKAGE__->table_resultset_class_suffix('::_resultset');
ed28f830 33
34sub table {
35 my ($self,@rest) = @_;
e8861f71 36 my $ret = $self->next::method(@rest);
37 if (@rest) {
38 $self->_register_attributes;
75d07914 39 $self->_register_resultset_class;
e8861f71 40 }
41 return $ret;
ed28f830 42}
43
44sub load_resultset_components {
45 my ($self,@comp) = @_;
46 my $resultset_class = $self->_setup_resultset_class;
47 $resultset_class->load_components(@comp);
48}
49
ed28f830 50sub _register_attributes {
51 my $self = shift;
52 my $cache = $self->_attr_cache;
da95b45f 53 return if keys %$cache == 0;
9b83fccd 54
ed28f830 55 foreach my $meth (@{Class::Inspector->methods($self) || []}) {
56 my $attrs = $cache->{$self->can($meth)};
57 next unless $attrs;
a39e84a3 58 if ($attrs->[0] eq 'ResultSet') {
ed28f830 59 no strict 'refs';
60 my $resultset_class = $self->_setup_resultset_class;
e250c046 61 *{"$resultset_class\::$meth"} = $self->can($meth);
f8d97a01 62 delete ${"${self}::"}{$meth};
ed28f830 63 }
64 }
ed28f830 65}
66
67sub _setup_resultset_class {
68 my $self = shift;
f0750722 69 my $resultset_class = $self . $self->table_resultset_class_suffix;
ed28f830 70 no strict 'refs';
71 unless (@{"$resultset_class\::ISA"}) {
570783b1 72 @{"$resultset_class\::ISA"} = ($self->base_resultset_class);
ed28f830 73 }
74 return $resultset_class;
75}
76
570783b1 77sub _register_resultset_class {
78 my $self = shift;
f0750722 79 my $resultset_class = $self . $self->table_resultset_class_suffix;
570783b1 80 no strict 'refs';
81 if (@{"$resultset_class\::ISA"}) {
24d67825 82 $self->result_source_instance->resultset_class($resultset_class);
570783b1 83 } else {
24d67825 84 $self->result_source_instance->resultset_class
75d07914 85 ($self->base_resultset_class);
570783b1 86 }
87}
88
19345968 891;