[Bast-commits] r4135 - in DBIx-Class-Fixtures/1.001/trunk: . lib/DBIx/Class

captainL at dev.catalyst.perl.org captainL at dev.catalyst.perl.org
Wed Mar 5 15:01:21 GMT 2008


Author: captainL
Date: 2008-03-05 15:01:21 +0000 (Wed, 05 Mar 2008)
New Revision: 4135

Modified:
   DBIx-Class-Fixtures/1.001/trunk/Changes
   DBIx-Class-Fixtures/1.001/trunk/MANIFEST
   DBIx-Class-Fixtures/1.001/trunk/lib/DBIx/Class/Fixtures.pm
Log:
push from includes branch

Modified: DBIx-Class-Fixtures/1.001/trunk/Changes
===================================================================
--- DBIx-Class-Fixtures/1.001/trunk/Changes	2008-03-05 14:58:25 UTC (rev 4134)
+++ DBIx-Class-Fixtures/1.001/trunk/Changes	2008-03-05 15:01:21 UTC (rev 4135)
@@ -1,5 +1,8 @@
 Revision history for DBIx-Class-Fixtures
 
+1.001000
+- Added includes functionality
+
 1.000001
 - Added missing deps
 

Modified: DBIx-Class-Fixtures/1.001/trunk/MANIFEST
===================================================================
--- DBIx-Class-Fixtures/1.001/trunk/MANIFEST	2008-03-05 14:58:25 UTC (rev 4134)
+++ DBIx-Class-Fixtures/1.001/trunk/MANIFEST	2008-03-05 15:01:21 UTC (rev 4135)
@@ -26,6 +26,7 @@
 t/05-dump-rules.t
 t/06-dump-date.t
 t/07-dump-all.t
+t/07-dump-includes.t
 t/12-populate-basic.t
 t/13populate-two-dbs.t
 t/lib/DBICTest.pm
@@ -49,3 +50,4 @@
 t/var/configs/rules.json
 t/var/configs/sample.json
 t/var/configs/simple.json
+t/var/configs/includes.json

Modified: DBIx-Class-Fixtures/1.001/trunk/lib/DBIx/Class/Fixtures.pm
===================================================================
--- DBIx-Class-Fixtures/1.001/trunk/lib/DBIx/Class/Fixtures.pm	2008-03-05 14:58:25 UTC (rev 4134)
+++ DBIx-Class-Fixtures/1.001/trunk/lib/DBIx/Class/Fixtures.pm	2008-03-05 15:01:21 UTC (rev 4135)
@@ -150,6 +150,23 @@
 
 L</RULE ATTRIBUTES>
 
+=head2 includes
+
+To prevent repetition between configs you can include other configs. For example:
+
+    {
+        sets: [{
+            class: 'Producer',
+            ids: ['5']
+        }],
+        includes: [{
+            file: 'base.json'
+        }]
+    }
+
+Includes must be an arrayref of hashrefs where the hashrefs have key 'file' which is the name of another config
+file in the same directory. The original config is merged with its includes using Hash::Merge.
+
 =head2 datetime_relative
 
 Only available for MySQL and PostgreSQL at the moment, must be a value that DateTime::Format::*
@@ -409,16 +426,40 @@
   my $config_file;
   my $config;
   if ($params->{config}) {
+    #read config
     $config_file = file($self->config_dir, $params->{config});
     unless (-e $config_file) {
       return DBIx::Class::Exception->throw('config does not exist at ' . $config_file);
     }
+    $config = Config::Any::JSON->load($config_file);
 
-    $config = Config::Any::JSON->load($config_file);
+    #process includes
+    if ($config->{includes}) {
+      $self->msg($config->{includes});
+      unless (ref $config->{includes} eq 'ARRAY') {
+        return DBIx::Class::Exception->throw('includes params of config must be an array ref of hashrefs');
+      }
+      foreach my $include_config (@{$config->{includes}}) {
+        unless ((ref $include_config eq 'HASH') && $include_config->{file}) {
+          return DBIx::Class::Exception->throw('includes params of config must be an array ref of hashrefs');
+        }
+        
+        my $include_file = file($self->config_dir, $include_config->{file});
+        unless (-e $include_file) {
+          return DBIx::Class::Exception->throw('config does not exist at ' . $include_file);
+        }
+        my $include = Config::Any::JSON->load($include_file);
+        $self->msg($include);
+        $config = merge( $config, $include );
+      }
+      delete $config->{includes};
+    }
+    
+    # validate config
     unless ($config && $config->{sets} && ref $config->{sets} eq 'ARRAY' && scalar(@{$config->{sets}})) {
       return DBIx::Class::Exception->throw('config has no sets');
     }
-
+	
     $config->{might_have} = { fetch => 0 } unless (exists $config->{might_have});
     $config->{has_many} = { fetch => 0 } unless (exists $config->{has_many});
     $config->{belongs_to} = { fetch => 1 } unless (exists $config->{belongs_to});
@@ -793,7 +834,6 @@
   my $self = shift;
   my $subject = shift || return;
   my $level = shift || 1;
-
   return unless $self->debug >= $level;
   if (ref $subject) {
 	print Dumper($subject);




More information about the Bast-commits mailing list