add component_class accessors and use them for *_class
David Kamholz [Tue, 7 Feb 2006 22:50:06 +0000 (22:50 +0000)]
lib/DBIx/Class/AccessorGroup.pm
lib/DBIx/Class/ResultSource.pm
lib/DBIx/Class/ResultSourceProxy/Table.pm

index 79db519..4e42b27 100644 (file)
@@ -142,6 +142,27 @@ sub set_simple {
   return $self->{$set} = $val;
 }
 
+sub get_component_class {
+  my ($self, $get) = @_;
+  if (ref $self) {
+      return $self->{$get};
+  } else {
+      $get = "_$get";
+      return $self->can($get) ? $self->$get : undef;      
+  }
+}
+
+sub set_component_class {
+  my ($self, $set, $val) = @_;
+  eval "require $val";
+  if (ref $self) {
+      return $self->{$set} = $val;
+  } else {
+      $set = "_$set";
+      return $self->can($set) ? $self->$set($val) : $self->mk_classdata($set => $val);      
+  }  
+}
+
 1;
 
 =head1 AUTHORS
index 2d36f5e..eff072b 100644 (file)
@@ -12,7 +12,8 @@ use base qw/DBIx::Class/;
 __PACKAGE__->load_components(qw/AccessorGroup/);
 
 __PACKAGE__->mk_group_accessors('simple' =>
-  qw/_ordered_columns _columns _primaries _unique_constraints name resultset_class resultset_attributes result_class schema from _relationships/);
+  qw/_ordered_columns _columns _primaries _unique_constraints name resultset_attributes schema from _relationships/);
+__PACKAGE__->mk_group_accessors('component_class' => qw/resultset_class result_class/);
 
 =head1 NAME 
 
index 4f23097..6717f82 100644 (file)
@@ -4,11 +4,12 @@ use strict;
 use warnings;
 
 use base qw/DBIx::Class::ResultSourceProxy/;
-use DBIx::Class::ResultSource::Table;
+__PACKAGE__->load_components(qw/AccessorGroup/);
 
-__PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do anything yet!
+__PACKAGE__->mk_group_accessors('component_class' => 'table_class');
+__PACKAGE__->table_class('DBIx::Class::ResultSource::Table');
 
-__PACKAGE__->mk_classdata('table_class' => 'DBIx::Class::ResultSource::Table');
+__PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do anything yet!
 
 =head1 NAME