Mark forgotten ::Row::id() method as indirect_sugar
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / ResultSetManager.pm
1 package DBIx::Class::ResultSetManager;
2 use strict;
3 use warnings;
4 use base 'DBIx::Class';
5
6 use DBIx::Class::_Util qw( set_subname describe_class_methods );
7 use namespace::clean;
8
9 warn "DBIx::Class::ResultSetManager never left experimental status and
10 has now been DEPRECATED. This module will be deleted in 09000 so please
11 migrate any and all code using it to explicit resultset classes using either
12 __PACKAGE__->resultset_class(...) calls or by switching from using
13 DBIx::Class::Schema->load_classes() to load_namespaces() and creating
14 appropriate My::Schema::ResultSet::* classes for it to pick up.";
15
16 =head1 NAME
17
18 DBIx::Class::ResultSetManager - scheduled for deletion in 09000
19
20 =head1 DESCRIPTION
21
22 DBIx::Class::ResultSetManager never left experimental status and
23 has now been DEPRECATED. This module will be deleted in 09000 so please
24 migrate any and all code using it to explicit resultset classes using either
25 __PACKAGE__->resultset_class(...) calls or by switching from using
26 DBIx::Class::Schema->load_classes() to load_namespaces() and creating
27 appropriate My::Schema::ResultSet::* classes for it to pick up.";
28
29 =cut
30
31 __PACKAGE__->mk_group_accessors(inherited => qw(
32   base_resultset_class table_resultset_class_suffix
33 ));
34 __PACKAGE__->base_resultset_class('DBIx::Class::ResultSet');
35 __PACKAGE__->table_resultset_class_suffix('::_resultset');
36
37 sub table {
38     my ($self,@rest) = @_;
39     my $ret = $self->next::method(@rest);
40     if (@rest) {
41         $self->_register_attributes;
42         $self->_register_resultset_class;
43     }
44     return $ret;
45 }
46
47 sub load_resultset_components {
48     my ($self,@comp) = @_;
49     my $resultset_class = $self->_setup_resultset_class;
50     $resultset_class->load_components(@comp);
51 }
52
53 sub _register_attributes {
54     my $self = shift;
55     my $cache = $self->_attr_cache;
56     return if keys %$cache == 0;
57
58     for my $meth(
59       map
60         { $_->{name} }
61         grep
62           { $_->{attributes}{ResultSet} }
63           map
64             { $_->[0] }
65             values %{ describe_class_methods( ref $self || $self )->{methods} }
66     ) {
67         # This codepath is extremely old, miht as well keep it running
68         # as-is with no room for surprises
69         no strict 'refs';
70         my $resultset_class = $self->_setup_resultset_class;
71         my $name = join '::',$resultset_class, $meth;
72         *$name = set_subname $name, $self->can($meth);
73         delete ${"${self}::"}{$meth};
74     }
75 }
76
77 sub _setup_resultset_class {
78     my $self = shift;
79     my $resultset_class = $self . $self->table_resultset_class_suffix;
80     no strict 'refs';
81     unless (@{"$resultset_class\::ISA"}) {
82         @{"$resultset_class\::ISA"} = ($self->base_resultset_class);
83     }
84     return $resultset_class;
85 }
86
87 sub _register_resultset_class {
88     my $self = shift;
89     my $resultset_class = $self . $self->table_resultset_class_suffix;
90     no strict 'refs';
91     $self->result_source->resultset_class(
92       ( scalar @{"${resultset_class}::ISA"} )
93         ? $resultset_class
94         : $self->base_resultset_class
95     );
96 }
97
98 =head1 FURTHER QUESTIONS?
99
100 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
101
102 =head1 COPYRIGHT AND LICENSE
103
104 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
105 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
106 redistribute it and/or modify it under the same terms as the
107 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
108
109 =cut
110
111 1;