added source_info method for source-level metadata (kinda like column_info)
Brandon L. Black [Wed, 23 Aug 2006 17:41:49 +0000 (17:41 +0000)]
lib/DBIx/Class/ResultSource.pm
lib/DBIx/Class/ResultSourceProxy.pm
t/60core.t
t/lib/DBICTest/Schema/Artist.pm

index 75b1487..82b7c7b 100644 (file)
@@ -12,7 +12,8 @@ __PACKAGE__->load_components(qw/AccessorGroup/);
 
 __PACKAGE__->mk_group_accessors('simple' => qw/_ordered_columns
   _columns _primaries _unique_constraints name resultset_attributes
-  schema from _relationships column_info_from_storage source_name/);
+  schema from _relationships column_info_from_storage source_name
+  source_info/);
 
 __PACKAGE__->mk_group_accessors('component_class' => qw/resultset_class
   result_class/);
@@ -61,6 +62,17 @@ sub new {
 
 =pod
 
+=head2 source_info
+
+Stores a hashref of per-source metadata.  No specific key names
+have yet been standardized, the examples below are purely hypothetical
+and don't actually accomplish anything on their own:
+
+  __PACKAGE__->source_info({
+    "_tablespace" => 'fast_disk_array_3',
+    "_engine" => 'InnoDB',
+  });
+
 =head2 add_columns
 
   $table->add_columns(qw/col1 col2 col3/);
index c1d6164..4d80cba 100644 (file)
@@ -10,6 +10,7 @@ sub iterator_class  { shift->result_source_instance->resultset_class(@_) }
 sub resultset_class { shift->result_source_instance->resultset_class(@_) }
 sub result_class { shift->result_source_instance->result_class(@_) }
 sub source_name { shift->result_source_instance->source_name(@_) }
+sub source_info { shift->result_source_instance->source_info(@_) }
 
 sub resultset_attributes {
   shift->result_source_instance->resultset_attributes(@_);
index 22eead9..a600cb0 100644 (file)
@@ -7,7 +7,7 @@ use DBICTest;
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 63;
+plan tests => 64;
 
 # figure out if we've got a version of sqlite that is older than 3.2.6, in
 # which case COUNT(DISTINCT()) doesn't work
@@ -285,6 +285,19 @@ ok(!$@, "stringify to false value doesn't cause error");
   ok($schema->source("Artist")->{_columns_info_loaded} == 1, 'Columns info flag set');
 }
 
+# test source_info
+{
+  my $expected = {
+    "source_info_key_A" => "source_info_value_A",
+    "source_info_key_B" => "source_info_value_B",
+    "source_info_key_C" => "source_info_value_C",
+  };
+
+  my $sinfo = $schema->source("Artist")->source_info;
+
+  is_deeply($sinfo, $expected, 'source_info data works');
+}
+
 # test remove_columns
 {
   is_deeply([$schema->source('CD')->columns], [qw/cdid artist title year/]);
index 0bb49c4..cf6eb3a 100644 (file)
@@ -4,6 +4,11 @@ package # hide from PAUSE
 use base 'DBIx::Class::Core';
 
 __PACKAGE__->table('artist');
+__PACKAGE__->source_info({
+    "source_info_key_A" => "source_info_value_A",
+    "source_info_key_B" => "source_info_value_B",
+    "source_info_key_C" => "source_info_value_C",
+});
 __PACKAGE__->add_columns(
   'artistid' => {
     data_type => 'integer',