Commit | Line | Data |
db57afbb |
1 | package DBIx::Class::ResultSetManager; |
ed28f830 |
2 | use strict; |
bf5ecff9 |
3 | use warnings; |
ed28f830 |
4 | use base 'DBIx::Class'; |
5 | use Class::Inspector; |
6 | |
748ab0dc |
7 | warn "DBIx::Class::ResultSetManager never left experimental status and |
8 | has now been DEPRECATED. This module will be deleted in 09000 so please |
9 | migrate any and all code using it to explicit resultset classes using either |
10 | __PACKAGE__->resultset_class(...) calls or by switching from using |
11 | DBIx::Class::Schema->load_classes() to load_namespaces() and creating |
12 | appropriate My::Schema::ResultSet::* classes for it to pick up."; |
bc0c9800 |
13 | |
748ab0dc |
14 | =head1 NAME |
bc0c9800 |
15 | |
748ab0dc |
16 | DBIx::Class::ResultSetManager - scheduled for deletion in 09000 |
bc0c9800 |
17 | |
18 | =head1 DESCRIPTION |
19 | |
748ab0dc |
20 | DBIx::Class::ResultSetManager never left experimental status and |
21 | has now been DEPRECATED. This module will be deleted in 09000 so please |
22 | migrate any and all code using it to explicit resultset classes using either |
23 | __PACKAGE__->resultset_class(...) calls or by switching from using |
24 | DBIx::Class::Schema->load_classes() to load_namespaces() and creating |
25 | appropriate 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 | |
34 | sub 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 | |
44 | sub load_resultset_components { |
45 | my ($self,@comp) = @_; |
46 | my $resultset_class = $self->_setup_resultset_class; |
47 | $resultset_class->load_components(@comp); |
48 | } |
49 | |
ed28f830 |
50 | sub _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 | |
67 | sub _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 |
77 | sub _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 |
89 | 1; |