Commit | Line | Data |
db57afbb |
1 | package DBIx::Class::ResultSetManager; |
ed28f830 |
2 | use strict; |
bf5ecff9 |
3 | use warnings; |
ed28f830 |
4 | use base 'DBIx::Class'; |
ddc0a6c8 |
5 | use Sub::Name (); |
ed28f830 |
6 | use Class::Inspector; |
7 | |
748ab0dc |
8 | warn "DBIx::Class::ResultSetManager never left experimental status and |
9 | has now been DEPRECATED. This module will be deleted in 09000 so please |
10 | migrate any and all code using it to explicit resultset classes using either |
11 | __PACKAGE__->resultset_class(...) calls or by switching from using |
12 | DBIx::Class::Schema->load_classes() to load_namespaces() and creating |
13 | appropriate My::Schema::ResultSet::* classes for it to pick up."; |
bc0c9800 |
14 | |
748ab0dc |
15 | =head1 NAME |
bc0c9800 |
16 | |
748ab0dc |
17 | DBIx::Class::ResultSetManager - scheduled for deletion in 09000 |
bc0c9800 |
18 | |
19 | =head1 DESCRIPTION |
20 | |
748ab0dc |
21 | DBIx::Class::ResultSetManager never left experimental status and |
22 | has now been DEPRECATED. This module will be deleted in 09000 so please |
23 | migrate any and all code using it to explicit resultset classes using either |
24 | __PACKAGE__->resultset_class(...) calls or by switching from using |
25 | DBIx::Class::Schema->load_classes() to load_namespaces() and creating |
26 | appropriate 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 | |
35 | sub 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 | |
45 | sub load_resultset_components { |
46 | my ($self,@comp) = @_; |
47 | my $resultset_class = $self->_setup_resultset_class; |
48 | $resultset_class->load_components(@comp); |
49 | } |
50 | |
ed28f830 |
51 | sub _register_attributes { |
52 | my $self = shift; |
53 | my $cache = $self->_attr_cache; |
da95b45f |
54 | return if keys %$cache == 0; |
9b83fccd |
55 | |
ed28f830 |
56 | foreach my $meth (@{Class::Inspector->methods($self) || []}) { |
57 | my $attrs = $cache->{$self->can($meth)}; |
58 | next unless $attrs; |
a39e84a3 |
59 | if ($attrs->[0] eq 'ResultSet') { |
ed28f830 |
60 | no strict 'refs'; |
61 | my $resultset_class = $self->_setup_resultset_class; |
ddc0a6c8 |
62 | my $name = join '::',$resultset_class, $meth; |
63 | *$name = Sub::Name::subname $name, $self->can($meth); |
f8d97a01 |
64 | delete ${"${self}::"}{$meth}; |
ed28f830 |
65 | } |
66 | } |
ed28f830 |
67 | } |
68 | |
69 | sub _setup_resultset_class { |
70 | my $self = shift; |
f0750722 |
71 | my $resultset_class = $self . $self->table_resultset_class_suffix; |
ed28f830 |
72 | no strict 'refs'; |
73 | unless (@{"$resultset_class\::ISA"}) { |
570783b1 |
74 | @{"$resultset_class\::ISA"} = ($self->base_resultset_class); |
ed28f830 |
75 | } |
76 | return $resultset_class; |
77 | } |
78 | |
570783b1 |
79 | sub _register_resultset_class { |
80 | my $self = shift; |
f0750722 |
81 | my $resultset_class = $self . $self->table_resultset_class_suffix; |
570783b1 |
82 | no strict 'refs'; |
83 | if (@{"$resultset_class\::ISA"}) { |
24d67825 |
84 | $self->result_source_instance->resultset_class($resultset_class); |
570783b1 |
85 | } else { |
24d67825 |
86 | $self->result_source_instance->resultset_class |
75d07914 |
87 | ($self->base_resultset_class); |
570783b1 |
88 | } |
89 | } |
90 | |
19345968 |
91 | 1; |