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 # FIXME - both of these *PROBABLY* need to be 'inherited_ro_instance' type
13 __PACKAGE__->mk_classaccessor(table_class => 'DBIx::Class::ResultSource::Table');
14 # FIXME: Doesn't actually do anything yet!
15 __PACKAGE__->mk_group_accessors( inherited => 'table_alias' );
17 sub _init_result_source_instance {
20 $class->mk_group_accessors( inherited => [ result_source_instance => '_result_source' ] )
21 unless $class->can('result_source_instance');
23 # might be pre-made for us courtesy of DBIC::DB::result_source_instance()
24 my $rsrc = $class->result_source_instance;
27 if $rsrc and $rsrc->result_class eq $class;
29 my $table_class = $class->table_class;
30 $class->ensure_class_loaded($table_class);
34 # NOTE! - not using clone() here and *NOT* marking source as derived
35 # from the one already existing on the class (if any)
37 $rsrc = $table_class->new({
39 result_class => $class,
45 $rsrc = $table_class->new({
47 result_class => $class,
52 $class->result_source_instance($rsrc);
57 DBIx::Class::ResultSourceProxy::Table - provides a classdata table
58 object and method proxies
62 __PACKAGE__->table('cd');
63 __PACKAGE__->add_columns(qw/cdid artist title year/);
64 __PACKAGE__->set_primary_key('cdid');
70 __PACKAGE__->add_columns(qw/cdid artist title year/);
72 Adds columns to the current class and creates accessors for them.
78 __PACKAGE__->table('tbl_name');
80 Gets or sets the table name.
85 return $_[0]->result_source->name unless @_ > 1;
87 my ($class, $table) = @_;
89 unless (blessed $table && $table->isa($class->table_class)) {
91 my $ancestor = $class->can('result_source_instance')
92 ? $class->result_source_instance
96 # Folks calling ->table on a class *might* expect the name
97 # to shift everywhere, but that can't happen
98 # So what we do is mark the ancestor as "dirty"
99 # even though it will have no "derived" link to the one we
100 # will use afterwards
104 $ancestor->name ne $table
106 scalar $ancestor->__derived_instances
108 # Trigger the "descendants are dirty" logic, without giving
109 # it an explicit externally-callable interface
110 # This is ugly as sin, but likely saner in the long run
111 local $ancestor->{__in_rsrc_setter_callstack} = 1
112 unless $ancestor->{__in_rsrc_setter_callstack};
113 my $old_name = $ancestor->name;
114 $ancestor->set_rsrc_instance_specific_attribute( name => "\0" );
115 $ancestor->set_rsrc_instance_specific_attribute( name => $old_name );
119 my $table_class = $class->table_class;
120 $class->ensure_class_loaded($table_class);
123 # NOTE! - not using clone() here and *NOT* marking source as derived
124 # from the one already existing on the class (if any)
125 # This is logically sound as we are operating at class-level, and is
126 # in fact necessary, as otherwise any base-class with a "dummy" table
127 # will be marked as an ancestor of everything
128 $table = $table_class->new({
129 %{ $ancestor || {} },
131 result_class => $class,
135 $class->mk_group_accessors( inherited => [ result_source_instance => '_result_source' ] )
136 unless $class->can('result_source_instance');
138 $class->result_source_instance($table)->name;
143 __PACKAGE__->table_class('DBIx::Class::ResultSource::Table');
145 Gets or sets the table class used for construction and validation.
149 if ($obj->has_column($col)) { ... }
151 Returns 1 if the class has a column of this name, 0 otherwise.
155 my $info = $obj->column_info($col);
157 Returns the column metadata hashref for a column. For a description of
158 the various types of column data in this hashref, see
159 L<DBIx::Class::ResultSource/add_column>
163 my @column_names = $obj->columns;
165 =head1 FURTHER QUESTIONS?
167 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
169 =head1 COPYRIGHT AND LICENSE
171 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
172 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
173 redistribute it and/or modify it under the same terms as the
174 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.