Centralize remaining uses of Sub::Name within _Util
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / ResultSetManager.pm
CommitLineData
db57afbb 1package DBIx::Class::ResultSetManager;
ed28f830 2use strict;
bf5ecff9 3use warnings;
ed28f830 4use base 'DBIx::Class';
817ac9e9 5use Package::Stash ();
ed28f830 6
514b84f6 7use DBIx::Class::_Util 'set_subname';
8use namespace::clean;
9
748ab0dc 10warn "DBIx::Class::ResultSetManager never left experimental status and
11has now been DEPRECATED. This module will be deleted in 09000 so please
12migrate any and all code using it to explicit resultset classes using either
13__PACKAGE__->resultset_class(...) calls or by switching from using
14DBIx::Class::Schema->load_classes() to load_namespaces() and creating
15appropriate My::Schema::ResultSet::* classes for it to pick up.";
bc0c9800 16
748ab0dc 17=head1 NAME
bc0c9800 18
748ab0dc 19DBIx::Class::ResultSetManager - scheduled for deletion in 09000
bc0c9800 20
21=head1 DESCRIPTION
22
748ab0dc 23DBIx::Class::ResultSetManager never left experimental status and
24has now been DEPRECATED. This module will be deleted in 09000 so please
25migrate any and all code using it to explicit resultset classes using either
26__PACKAGE__->resultset_class(...) calls or by switching from using
27DBIx::Class::Schema->load_classes() to load_namespaces() and creating
28appropriate My::Schema::ResultSet::* classes for it to pick up.";
bc0c9800 29
30=cut
31
24d67825 32__PACKAGE__->mk_classdata($_)
33 for qw/ base_resultset_class table_resultset_class_suffix /;
570783b1 34__PACKAGE__->base_resultset_class('DBIx::Class::ResultSet');
f0750722 35__PACKAGE__->table_resultset_class_suffix('::_resultset');
ed28f830 36
37sub table {
38 my ($self,@rest) = @_;
e8861f71 39 my $ret = $self->next::method(@rest);
40 if (@rest) {
41 $self->_register_attributes;
75d07914 42 $self->_register_resultset_class;
e8861f71 43 }
44 return $ret;
ed28f830 45}
46
47sub load_resultset_components {
48 my ($self,@comp) = @_;
49 my $resultset_class = $self->_setup_resultset_class;
50 $resultset_class->load_components(@comp);
51}
52
ed28f830 53sub _register_attributes {
54 my $self = shift;
55 my $cache = $self->_attr_cache;
da95b45f 56 return if keys %$cache == 0;
9b83fccd 57
817ac9e9 58 foreach my $meth (keys %{ { map
59 { $_ => 1 }
60 map
61 { Package::Stash->new($_)->list_all_symbols("CODE") }
62 @{ mro::get_linear_isa( ref $self || $self ) }
63 } } ) {
64 # *DO NOT* rely on P::S returning crefs in reverse mro order
65 # but instead ask the mro to redo the lookup
66 # This codepath is extremely old, miht as well keep it running
67 # as-is with no room for surprises
ed28f830 68 my $attrs = $cache->{$self->can($meth)};
69 next unless $attrs;
a39e84a3 70 if ($attrs->[0] eq 'ResultSet') {
ed28f830 71 no strict 'refs';
72 my $resultset_class = $self->_setup_resultset_class;
ddc0a6c8 73 my $name = join '::',$resultset_class, $meth;
514b84f6 74 *$name = set_subname $name, $self->can($meth);
f8d97a01 75 delete ${"${self}::"}{$meth};
ed28f830 76 }
77 }
ed28f830 78}
79
80sub _setup_resultset_class {
81 my $self = shift;
f0750722 82 my $resultset_class = $self . $self->table_resultset_class_suffix;
ed28f830 83 no strict 'refs';
84 unless (@{"$resultset_class\::ISA"}) {
570783b1 85 @{"$resultset_class\::ISA"} = ($self->base_resultset_class);
ed28f830 86 }
87 return $resultset_class;
88}
89
570783b1 90sub _register_resultset_class {
91 my $self = shift;
f0750722 92 my $resultset_class = $self . $self->table_resultset_class_suffix;
570783b1 93 no strict 'refs';
94 if (@{"$resultset_class\::ISA"}) {
24d67825 95 $self->result_source_instance->resultset_class($resultset_class);
570783b1 96 } else {
24d67825 97 $self->result_source_instance->resultset_class
75d07914 98 ($self->base_resultset_class);
570783b1 99 }
100}
101
a2bd3796 102=head1 FURTHER QUESTIONS?
103
104Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
105
106=head1 COPYRIGHT AND LICENSE
107
108This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
109by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
110redistribute it and/or modify it under the same terms as the
111L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
112
113=cut
114
19345968 1151;