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