From: Matt S Trout Date: Tue, 20 Dec 2005 05:33:34 +0000 (+0000) Subject: CDBICompat happy again on rs branch X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ec77fadc80e2ce78abf208f2126b74e5445bec22;p=dbsrgits%2FDBIx-Class-Historic.git CDBICompat happy again on rs branch --- diff --git a/lib/DBIx/Class/CDBICompat/ColumnCase.pm b/lib/DBIx/Class/CDBICompat/ColumnCase.pm index 8ef8080..3f49f23 100644 --- a/lib/DBIx/Class/CDBICompat/ColumnCase.pm +++ b/lib/DBIx/Class/CDBICompat/ColumnCase.pm @@ -15,6 +15,12 @@ sub _register_columns { return $class->next::method(map lc, @cols); } +sub add_columns { + my ($class, @cols) = @_; + $class->table_instance->add_columns(map lc, @cols); + $class->_mk_column_accessors(@cols); +} + sub has_a { my ($class, $col, @rest) = @_; $class->next::method(lc($col), @rest); diff --git a/lib/DBIx/Class/CDBICompat/ColumnGroups.pm b/lib/DBIx/Class/CDBICompat/ColumnGroups.pm index 80b17e0..60a1e3c 100644 --- a/lib/DBIx/Class/CDBICompat/ColumnGroups.pm +++ b/lib/DBIx/Class/CDBICompat/ColumnGroups.pm @@ -39,21 +39,16 @@ sub _register_column_group { $class->set_primary_key($cols[0]); } unless (exists $class->_column_groups->{'Essential'}) { - #$class->_register_column_group('Essential' => $cols[0]); $groups->{'Essential'}{$cols[0]} = {}; - #$groups->{'Essential'}{$_} ||= {} for keys %{ $class->_primaries || {} }; } } $groups->{$group}{$_} ||= {} for @cols; - #if ($group eq 'Essential') { - # $groups->{$group}{$_} ||= {} for keys %{ $class->_primaries || {} }; - #} $class->_column_groups($groups); } -sub all_columns { return keys %{$_[0]->_columns}; } +sub all_columns { return shift->table_instance->columns; } sub primary_column { my ($class) = @_; diff --git a/lib/DBIx/Class/CDBICompat/ImaDBI.pm b/lib/DBIx/Class/CDBICompat/ImaDBI.pm index 4d6e3d5..8cb7c48 100644 --- a/lib/DBIx/Class/CDBICompat/ImaDBI.pm +++ b/lib/DBIx/Class/CDBICompat/ImaDBI.pm @@ -70,8 +70,6 @@ sub __driver { sub set_sql { my ($class, $name, $sql) = @_; - my $table = $class->_table_name; - #$sql =~ s/__TABLE__/$table/; no strict 'refs'; *{"${class}::sql_${name}"} = sub { @@ -103,7 +101,6 @@ sub sth_to_objects { sub transform_sql { my ($class, $sql, @args) = @_; - my $table = $class->_table_name; my $attrs = { }; foreach my $key (@{$class->_transform_sql_handler_order}) { my $h = $class->_transform_sql_handlers->{$key}; diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index ce038db..c980c60 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -38,7 +38,7 @@ sub new { $class = ref $class if ref $class; $attrs = { %{ $attrs || {} } }; my %seen; - $attrs->{cols} ||= [ map { "me.$_" } $source->columns ]; + $attrs->{cols} ||= [ map { "me.$_" } $source->result_class->_select_columns ]; $attrs->{from} ||= [ { 'me' => $source->name } ]; if ($attrs->{join}) { foreach my $j (ref $attrs->{join} eq 'ARRAY' @@ -56,7 +56,7 @@ sub new { unless $seen{$pre}; push(@{$attrs->{cols}}, map { "$pre.$_" } - $source->result_class->_relationships->{$pre}->{class}->table->columns); + $source->result_class->_relationships->{$pre}->{class}->columns); } my $new = { source => $source, diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index fa8e850..557e036 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -167,9 +167,6 @@ sub compose_connection { while (my ($comp, $comp_class) = each %reg) { my $target_class = "${target}::${comp}"; $class->inject_base($target_class, $comp_class, $conn_class); - my $table = $comp_class->table->new({ %{$comp_class->table} }); - $table->result_class($target_class); - $target_class->table($table); @map{$comp, $comp_class} = ($target_class, $target_class); } { diff --git a/lib/DBIx/Class/Table.pm b/lib/DBIx/Class/Table.pm index 01771ee..ddce803 100644 --- a/lib/DBIx/Class/Table.pm +++ b/lib/DBIx/Class/Table.pm @@ -31,7 +31,7 @@ L classes. sub new { my ($class, $attrs) = @_; $class = ref $class if ref $class; - my $new = bless($attrs || {}, $class); + my $new = bless({ %{$attrs || {}} }, $class); $new->{resultset_class} ||= 'DBIx::Class::ResultSet'; $new->{_columns} ||= {}; $new->{name} ||= "!!NAME NOT SET!!"; diff --git a/lib/DBIx/Class/TableInstance.pm b/lib/DBIx/Class/TableInstance.pm index 81c3c39..93e08c6 100644 --- a/lib/DBIx/Class/TableInstance.pm +++ b/lib/DBIx/Class/TableInstance.pm @@ -10,9 +10,9 @@ __PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do anything __PACKAGE__->mk_classdata('_resultset_class' => 'DBIx::Class::ResultSet'); -sub iterator_class { shift->table->resultset_class(@_) } -sub resultset_class { shift->table->resultset_class(@_) } -sub _table_name { shift->table->name } +sub iterator_class { shift->table_instance->resultset_class(@_) } +sub resultset_class { shift->table_instance->resultset_class(@_) } +sub _table_name { shift->table_instance->name } =head1 NAME @@ -43,18 +43,20 @@ Adds columns to the current class and creates accessors for them. sub add_columns { my ($class, @cols) = @_; - $class->table->add_columns(@cols); + $class->table_instance->add_columns(@cols); $class->_mk_column_accessors(@cols); } sub resultset_instance { my $class = shift; - $class->table->storage($class->storage); - $class->next::method($class->table->resultset); + my $table = $class->table_instance->new($class->table_instance); + $table->storage($class->storage); + $table->result_class($class); + return $table->resultset; } sub _select_columns { - return shift->table->columns; + return shift->table_instance->columns; } =head2 table @@ -67,7 +69,7 @@ Gets or sets the table name. sub table { my ($class, $table) = @_; - die "$class->table called and no table instance set yet" unless $table; + return $class->table_instance->name unless $table; unless (ref $table) { $table = DBIx::Class::Table->new( { @@ -75,8 +77,11 @@ sub table { result_class => $class, #storage => $class->storage, }); + if ($class->can('table_instance')) { + $table->{_columns} = { %{$class->table_instance->{_columns}||{}} }; + } } - $class->mk_classdata('table' => $table); + $class->mk_classdata('table_instance' => $table); } =head2 find_or_create @@ -105,7 +110,7 @@ Returns 1 if the class has a column of this name, 0 otherwise. sub has_column { my ($self, $column) = @_; - return $self->table->has_column($column); + return $self->table_instance->has_column($column); } =head2 column_info @@ -118,7 +123,7 @@ Returns the column metadata hashref for a column. sub column_info { my ($self, $column) = @_; - return $self->table->column_info($column); + return $self->table_instance->column_info($column); } =head2 columns @@ -128,7 +133,7 @@ sub column_info { =cut sub columns { - return shift->table->columns(@_); + return shift->table_instance->columns(@_); } 1; diff --git a/t/cdbi-t/01-columns.t b/t/cdbi-t/01-columns.t index 2bc8573..2782b31 100644 --- a/t/cdbi-t/01-columns.t +++ b/t/cdbi-t/01-columns.t @@ -121,14 +121,17 @@ package State; package A; @A::ISA = qw(DBIx::Class); __PACKAGE__->load_components(qw/CDBICompat Core/); +__PACKAGE__->table('dummy'); __PACKAGE__->columns(Primary => 'id'); package A::B; @A::B::ISA = 'A'; +__PACKAGE__->table('dummy2'); __PACKAGE__->columns(All => qw(id b1)); package A::C; @A::C::ISA = 'A'; +__PACKAGE__->table('dummy3'); __PACKAGE__->columns(All => qw(id c1 c2 c3)); package main; diff --git a/t/cdbi-t/12-filter.t b/t/cdbi-t/12-filter.t index adab754..ecaff02 100644 --- a/t/cdbi-t/12-filter.t +++ b/t/cdbi-t/12-filter.t @@ -158,7 +158,6 @@ sub slice { qw/fred barney/ } package main; Actor->iterator_class('Class::DBI::My::Iterator'); -Actor->resultset_instance(Actor->construct_resultset); { my @acts = $film->actors->slice(1, 2);