More internals cleanup, separated out ResultSourceInstance from TableInstance
Matt S Trout [Mon, 16 Jan 2006 05:19:00 +0000 (05:19 +0000)]
Build.PL
lib/DBIx/Class/CDBICompat/HasA.pm
lib/DBIx/Class/CDBICompat/ImaDBI.pm
lib/DBIx/Class/CDBICompat/LazyLoading.pm
lib/DBIx/Class/PK/Auto/Oracle.pm
lib/DBIx/Class/ResultSet.pm
lib/DBIx/Class/ResultSourceInstance.pm [new file with mode: 0644]
lib/DBIx/Class/Row.pm
lib/DBIx/Class/TableInstance.pm

index da41963..9a288b8 100644 (file)
--- a/Build.PL
+++ b/Build.PL
@@ -14,7 +14,7 @@ my %arguments = (
         'SQL::Abstract::Limit'      => 0.101,
         'DBD::SQLite'               => 1.08,
         'Class::C3'                 => 0.07,
-           'Tie::IxHash'               => 0,
+        'Tie::IxHash'               => 0,
         'Module::Find'              => 0,
         'Storable'                  => 0,
         'Class::Data::Accessor'     => 0.01,
index 4547ab5..c0d4458 100644 (file)
@@ -24,4 +24,22 @@ sub has_a {
   return 1;
 }
 
+sub search {
+  my $self = shift;
+  my $attrs = {};
+  if (@_ > 1 && ref $_[$#_] eq 'HASH') {
+    $attrs = { %{ pop(@_) } };
+  }
+  my $where = (@_ ? ((@_ == 1) ? ((ref $_[0] eq "HASH") ? { %{+shift} } : shift)
+                               : {@_})
+                  : undef());
+  if (ref $where eq 'HASH') {
+    foreach my $key (keys %$where) { # has_a deflation hack
+      $where->{$key} = ''.$where->{$key}
+        if eval { $where->{$key}->isa('DBIx::Class') };
+    }
+  }
+  $self->next::method($where, $attrs);
+}
+
 1;
index 9d29486..144195e 100644 (file)
@@ -14,11 +14,11 @@ __PACKAGE__->mk_classdata('_transform_sql_handlers' =>
     'TABLE' =>
       sub {
         my ($self, $class, $data) = @_;
-        return $class->_table_name unless $data;
+        return $class->result_source_instance->name unless $data;
         my ($f_class, $alias) = split(/=/, $data);
         $f_class ||= $class;
         $self->{_classes}{$alias} = $f_class;
-        return $f_class->_table_name." ${alias}";
+        return $f_class->result_source_instance->name." ${alias}";
       },
     'ESSENTIAL' =>
       sub {
index 44c5b3a..ff235e2 100644 (file)
@@ -24,7 +24,8 @@ sub _flesh {
   my %want;
   $want{$_} = 1 for map { keys %{$self->_column_groups->{$_}} } @groups;
   if (my @want = grep { !exists $self->{'_column_data'}{$_} } keys %want) {
-    my $cursor = $self->storage->select($self->_table_name, \@want,
+    my $cursor = $self->result_source->storage->select(
+                $self->result_source->name, \@want,
                 \$self->_ident_cond, { bind => [ $self->_ident_values ] });
     #my $sth = $self->storage->select($self->_table_name, \@want,
     #                                   $self->ident_condition);
index a9bde71..1b7a8e9 100644 (file)
@@ -34,7 +34,7 @@ sub get_autoinc_seq {
   # trigger_body is a LONG
   $dbh->{LongReadLen} = 64 * 1024 if ($dbh->{LongReadLen} < 64 * 1024);
   my $sth = $dbh->prepare($sql);
-  $sth->execute( uc($self->_table_name) );
+  $sth->execute( uc($self->result_source->name) );
   while (my ($insert_trigger) = $sth->fetchrow_array) {
     if ($insert_trigger =~ m!(\w+)\.nextval!i ) {
       $self->{_autoinc_seq} = uc($1);
index 5d5e811..9082aa2 100644 (file)
@@ -37,7 +37,7 @@ sub new {
   my $class = shift;
   return $class->new_result(@_) if ref $class;
   my ($source, $attrs) = @_;
-  #use Data::Dumper; warn Dumper(@_);
+  #use Data::Dumper; warn Dumper($attrs);
   $attrs = Storable::dclone($attrs || {}); # { %{ $attrs || {} } };
   my %seen;
   my $alias = ($attrs->{alias} ||= 'me');
diff --git a/lib/DBIx/Class/ResultSourceInstance.pm b/lib/DBIx/Class/ResultSourceInstance.pm
new file mode 100644 (file)
index 0000000..03fbe7d
--- /dev/null
@@ -0,0 +1,41 @@
+package DBIx::Class::ResultSourceInstance;
+
+use strict;
+use warnings;
+
+use base qw/DBIx::Class/;
+
+sub iterator_class { shift->result_source_instance->resultset_class(@_) }
+sub resultset_class { shift->result_source_instance->resultset_class(@_) }
+
+sub add_columns {
+  my ($class, @cols) = @_;
+  $class->result_source_instance->add_columns(@cols);
+  $class->_mk_column_accessors(@cols);
+}
+
+sub _select_columns {
+  return shift->result_source_instance->columns;
+}
+
+sub has_column {                                                                
+  my ($self, $column) = @_;                                                     
+  return $self->result_source_instance->has_column($column);                    
+}
+
+sub column_info {                                                               
+  my ($self, $column) = @_;                                                     
+  return $self->result_source_instance->column_info($column);                   
+}
+
+                                                                                
+sub columns {                                                                   
+  return shift->result_source_instance->columns(@_);                            
+}                                                                               
+                                                                                
+sub set_primary_key { shift->result_source_instance->set_primary_key(@_); }     
+sub primary_columns { shift->result_source_instance->primary_columns(@_); }
+
+sub result_source { shift->result_source_instance(@_); }
+
+1;
index f2bd3e9..33787aa 100644 (file)
@@ -54,7 +54,7 @@ sub insert {
   return $self if $self->in_storage;
   #use Data::Dumper; warn Dumper($self);
   $self->result_source->storage->insert(
-    $self->_table_name, { $self->get_columns });
+    $self->result_source->from, { $self->get_columns });
   $self->in_storage(1);
   $self->{_dirty_columns} = {};
   return $self;
index 4cb8d7f..6a44c84 100644 (file)
@@ -3,17 +3,13 @@ package DBIx::Class::TableInstance;
 use strict;
 use warnings;
 
-use base qw/DBIx::Class/;
+use base qw/DBIx::Class::ResultSourceInstance/;
 use DBIx::Class::Table;
 
 __PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do anything yet!
 
 __PACKAGE__->mk_classdata('table_class' => 'DBIx::Class::Table');
 
-sub iterator_class { shift->result_source->resultset_class(@_) }
-sub resultset_class { shift->result_source->resultset_class(@_) }
-sub _table_name { shift->result_source->name }
-
 =head1 NAME 
 
 DBIx::Class::TableInstance - provides a classdata table object and method proxies
@@ -41,16 +37,6 @@ Adds columns to the current class and creates accessors for them.
 
 =cut
 
-sub add_columns {
-  my ($class, @cols) = @_;
-  $class->result_source->add_columns(@cols);
-  $class->_mk_column_accessors(@cols);
-}
-
-sub _select_columns {
-  return shift->result_source->columns;
-}
-
 =head2 table
 
   __PACKAGE__->table('tbl_name');
@@ -61,18 +47,18 @@ Gets or sets the table name.
 
 sub table {
   my ($class, $table) = @_;
-  return $class->result_source->name unless $table;
+  return $class->result_source_instance->name unless $table;
   unless (ref $table) {
     $table = $class->table_class->new(
       {
         name => $table,
         result_class => $class,
       });
-    if ($class->can('result_source')) {
-      $table->{_columns} = { %{$class->result_source->{_columns}||{}} };
+    if ($class->can('result_source_instance')) {
+      $table->{_columns} = { %{$class->result_source_instance->{_columns}||{}} };
     }
   }
-  $class->mk_classdata('result_source' => $table);
+  $class->mk_classdata('result_source_instance' => $table);
   if ($class->can('schema_instance')) {
     $class =~ m/([^:]+)$/;
     $class->schema_instance->register_class($class, $class);
@@ -87,11 +73,6 @@ Returns 1 if the class has a column of this name, 0 otherwise.
                                                                                 
 =cut                                                                            
 
-sub has_column {
-  my ($self, $column) = @_;
-  return $self->result_source->has_column($column);
-}
-
 =head2 column_info                                                               
                                                                                 
   my $info = $obj->column_info($col);                                           
@@ -100,24 +81,12 @@ Returns the column metadata hashref for a column.
                                                                                 
 =cut                                                                            
 
-sub column_info {
-  my ($self, $column) = @_;
-  return $self->result_source->column_info($column);
-}
-
 =head2 columns
 
   my @column_names = $obj->columns;                                             
                                                                                 
 =cut                                                                            
 
-sub columns {
-  return shift->result_source->columns(@_);
-}
-
-sub set_primary_key { shift->result_source->set_primary_key(@_); }
-sub primary_columns { shift->result_source->primary_columns(@_); }
-
 1;
 
 =head1 AUTHORS