Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / AccessorGroup.pm
CommitLineData
fe5d862b 1package DBIx::Class::AccessorGroup;
2
12bbb339 3use strict;
4use warnings;
5
5f48fa56 6use base qw( DBIx::Class::MethodAttributes Class::Accessor::Grouped );
983f766d 7
d46eac43 8use Scalar::Util 'blessed';
e5053694 9use DBIx::Class::_Util 'fail_on_internal_call';
0d374214 10use namespace::clean;
701da8c4 11
1b822bd3 12sub mk_classdata :DBIC_method_is_indirect_sugar {
e5053694 13 DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call;
d009cb7d 14 shift->mk_classaccessor(@_);
15}
16
1b822bd3 17sub mk_classaccessor :DBIC_method_is_indirect_sugar {
d009cb7d 18 my $self = shift;
19 $self->mk_group_accessors('inherited', $_[0]);
e5053694 20 (@_ > 1)
21 ? $self->set_inherited(@_)
22 : ( DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call )
23 ;
d009cb7d 24}
25
09d8fb4a 26sub mk_group_accessors {
27 my $class = shift;
28 my $type = shift;
29
30 $class->next::method($type, @_);
31
32 # label things
33 if( $type =~ /^ ( inflated_ | filtered_ )? column $/x ) {
34
35 $class = ref $class
36 if length ref $class;
37
38 for my $acc_pair (
39 map
40 { [ $_, "_${_}_accessor" ] }
41 map
42 { ref $_ ? $_->[0] : $_ }
43 @_
44 ) {
45
46 for my $i (0, 1) {
47
48 my $acc_name = $acc_pair->[$i];
49
50 attributes->import(
51 $class,
52 (
53 $class->can($acc_name)
54 ||
55 Carp::confess("Accessor '$acc_name' we just created on $class can't be found...?")
56 ),
57 'DBIC_method_is_generated_from_resultsource_metadata',
58 ($i
59 ? "DBIC_method_is_${type}_extra_accessor"
60 : "DBIC_method_is_${type}_accessor"
61 ),
62 )
63 }
64 }
65 }
d2308dde 66 elsif( $type eq 'inherited_ro_instance' ) {
67 DBIx::Class::Exception->throw(
68 "The 'inherted_ro_instance' CAG group has been retired - use 'inherited' instead"
69 );
70 }
09d8fb4a 71}
72
db29433c 73sub get_component_class {
74 my $class = $_[0]->get_inherited($_[1]);
0d374214 75
d46eac43 76 no strict 'refs';
77 if (
78 defined $class
79 and
80 # inherited CAG can't be set to undef effectively, so people may use ''
81 length $class
82 and
83 # It's already an object, just go for it.
84 ! defined blessed $class
85 and
86 ! ${"${class}::__LOADED__BY__DBIC__CAG__COMPONENT_CLASS__"}
87 ) {
db29433c 88 $_[0]->ensure_class_loaded($class);
0d374214 89
d46eac43 90 ${"${class}::__LOADED__BY__DBIC__CAG__COMPONENT_CLASS__"}
91 = do { \(my $anon = 'loaded') };
db29433c 92 }
0d374214 93
db29433c 94 $class;
95};
96
97sub set_component_class {
dd185339 98 $_[0]->set_inherited($_[1], $_[2]);
99
100 # trigger a load for the case of $foo->component_accessor("bar")->new
101 $_[0]->get_component_class($_[1])
102 if defined wantarray;
db29433c 103}
104
fe0e9f67 1051;
106
75d07914 107=head1 NAME
34d52be2 108
73281318 109DBIx::Class::AccessorGroup - See Class::Accessor::Grouped
34d52be2 110
111=head1 SYNOPSIS
112
113=head1 DESCRIPTION
114
73281318 115This class now exists in its own right on CPAN as Class::Accessor::Grouped
fc969005 116
a2bd3796 117=head1 FURTHER QUESTIONS?
34d52be2 118
a2bd3796 119Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
34d52be2 120
a2bd3796 121=head1 COPYRIGHT AND LICENSE
34d52be2 122
a2bd3796 123This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
124by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
125redistribute it and/or modify it under the same terms as the
126L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
34d52be2 127
128=cut