Add an explicit Sub::Quote dep in ::_Util
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / ResultSourceProxy.pm
1 package # hide from PAUSE
2     DBIx::Class::ResultSourceProxy;
3
4 use strict;
5 use warnings;
6
7 use base 'DBIx::Class';
8 use mro 'c3';
9
10 use Scalar::Util 'blessed';
11 use DBIx::Class::_Util qw( quote_sub fail_on_internal_call );
12 use namespace::clean;
13
14 __PACKAGE__->mk_group_accessors('inherited_ro_instance' => 'source_name');
15
16 sub get_inherited_ro_instance {  shift->get_inherited(@_) }
17
18 sub set_inherited_ro_instance {
19   my $self = shift;
20
21   $self->throw_exception ("Cannot set @{[shift]} on an instance")
22     if blessed $self;
23
24   $self->set_inherited(@_);
25 }
26
27
28 sub add_columns {
29   my ($class, @cols) = @_;
30   my $source = $class->result_source_instance;
31   $source->add_columns(@cols);
32   foreach my $c (grep { !ref } @cols) {
33     # If this is an augment definition get the real colname.
34     $c =~ s/^\+//;
35
36     $class->register_column($c => $source->column_info($c));
37   }
38 }
39
40 sub add_column {
41   DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call;
42   shift->add_columns(@_)
43 }
44
45
46 sub add_relationship {
47   my ($class, $rel, @rest) = @_;
48   my $source = $class->result_source_instance;
49   $source->add_relationship($rel => @rest);
50   $class->register_relationship($rel => $source->relationship_info($rel));
51 }
52
53
54 # legacy resultset_class accessor, seems to be used by cdbi only
55 sub iterator_class {
56   DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call;
57   shift->result_source_instance->resultset_class(@_)
58 }
59
60 for my $method_to_proxy (qw/
61   source_info
62   result_class
63   resultset_class
64   resultset_attributes
65
66   columns
67   has_column
68
69   remove_column
70   remove_columns
71
72   column_info
73   columns_info
74   column_info_from_storage
75
76   set_primary_key
77   primary_columns
78   sequence
79
80   add_unique_constraint
81   add_unique_constraints
82
83   unique_constraints
84   unique_constraint_names
85   unique_constraint_columns
86
87   relationships
88   relationship_info
89   has_relationship
90 /) {
91   quote_sub __PACKAGE__."::$method_to_proxy", sprintf( <<'EOC', $method_to_proxy );
92     DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and DBIx::Class::_Util::fail_on_internal_call;
93     shift->result_source_instance->%s (@_);
94 EOC
95
96 }
97
98 1;