1 package DBIx::Class::ResultSourceProxy::Table;
6 use base qw/DBIx::Class::ResultSourceProxy/;
8 use DBIx::Class::ResultSource::Table;
9 use Scalar::Util 'blessed';
12 __PACKAGE__->mk_classaccessor(table_class => 'DBIx::Class::ResultSource::Table');
13 # FIXME: Doesn't actually do anything yet!
14 __PACKAGE__->mk_group_accessors( inherited => 'table_alias' );
16 sub _init_result_source_instance {
19 $class->mk_group_accessors( inherited => [ result_source_instance => '_result_source' ] )
20 unless $class->can('result_source_instance');
22 # might be pre-made for us courtesy of DBIC::DB::result_source_instance()
23 my $rsrc = $class->result_source_instance;
26 if $rsrc and $rsrc->result_class eq $class;
28 my $table_class = $class->table_class;
29 $class->ensure_class_loaded($table_class);
33 # NOTE! - not using clone() here and *NOT* marking source as derived
34 # from the one already existing on the class (if any)
36 $rsrc = $table_class->new({
38 result_class => $class,
44 $rsrc = $table_class->new({
46 result_class => $class,
51 $class->result_source_instance($rsrc);
56 DBIx::Class::ResultSourceProxy::Table - provides a classdata table
57 object and method proxies
61 __PACKAGE__->table('cd');
62 __PACKAGE__->add_columns(qw/cdid artist title year/);
63 __PACKAGE__->set_primary_key('cdid');
69 __PACKAGE__->add_columns(qw/cdid artist title year/);
71 Adds columns to the current class and creates accessors for them.
77 __PACKAGE__->table('tbl_name');
79 Gets or sets the table name.
84 return $_[0]->result_source->name unless @_ > 1;
86 my ($class, $table) = @_;
88 unless (blessed $table && $table->isa($class->table_class)) {
90 my $ancestor = $class->can('result_source_instance')
91 ? $class->result_source_instance
95 # Folks calling ->table on a class *might* expect the name
96 # to shift everywhere, but that can't happen
97 # So what we do is mark the ancestor as "dirty"
98 # even though it will have no "derived" link to the one we
103 $ancestor->name ne $table
105 scalar $ancestor->__derived_instances
107 # Trigger the "descendants are dirty" logic, without giving
108 # it an explicit externally-callable interface
109 # This is ugly as sin, but likely saner in the long run
110 local $ancestor->{__in_rsrc_setter_callstack} = 1
111 unless $ancestor->{__in_rsrc_setter_callstack};
112 my $old_name = $ancestor->name;
113 $ancestor->set_rsrc_instance_specific_attribute( name => "\0" );
114 $ancestor->set_rsrc_instance_specific_attribute( name => $old_name );
118 my $table_class = $class->table_class;
119 $class->ensure_class_loaded($table_class);
122 # NOTE! - not using clone() here and *NOT* marking source as derived
123 # from the one already existing on the class (if any)
124 # This is logically sound as we are operating at class-level, and is
125 # in fact necessary, as otherwise any base-class with a "dummy" table
126 # will be marked as an ancestor of everything
127 $table = $table_class->new({
128 %{ $ancestor || {} },
130 result_class => $class,
134 $class->mk_group_accessors( inherited => [ result_source_instance => '_result_source' ] )
135 unless $class->can('result_source_instance');
137 $class->result_source_instance($table)->name;
142 __PACKAGE__->table_class('DBIx::Class::ResultSource::Table');
144 Gets or sets the table class used for construction and validation.
148 if ($obj->has_column($col)) { ... }
150 Returns 1 if the class has a column of this name, 0 otherwise.
154 my $info = $obj->column_info($col);
156 Returns the column metadata hashref for a column. For a description of
157 the various types of column data in this hashref, see
158 L<DBIx::Class::ResultSource/add_column>
162 my @column_names = $obj->columns;
164 =head1 FURTHER QUESTIONS?
166 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
168 =head1 COPYRIGHT AND LICENSE
170 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
171 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
172 redistribute it and/or modify it under the same terms as the
173 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.