[Bast-commits] r8952 - in DBIx-Class/0.08/trunk: . lib/DBIx lib/DBIx/Class t/lib/DBICTest/Schema

hobbs at dev.catalyst.perl.org hobbs at dev.catalyst.perl.org
Tue Mar 9 19:29:50 GMT 2010


Author: hobbs
Date: 2010-03-09 19:29:50 +0000 (Tue, 09 Mar 2010)
New Revision: 8952

Modified:
   DBIx-Class/0.08/trunk/Changes
   DBIx-Class/0.08/trunk/lib/DBIx/Class.pm
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSourceProxy.pm
   DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Event.pm
Log:
Support add_columns('+colname'=>{...}) syntax to augment column definitions.


Modified: DBIx-Class/0.08/trunk/Changes
===================================================================
--- DBIx-Class/0.08/trunk/Changes	2010-03-09 18:38:01 UTC (rev 8951)
+++ DBIx-Class/0.08/trunk/Changes	2010-03-09 19:29:50 UTC (rev 8952)
@@ -19,6 +19,8 @@
           attribute
         - Fix ambiguity in default directory handling of create_ddl_dir
           (RT#54063)
+        - Support add_columns('+colname' => { ... }) to augment column
+          definitions.
 
 0.08120 2010-02-24 08:58:00 (UTC)
         - Make sure possibly overwritten deployment_statements methods in

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm	2010-03-09 18:38:01 UTC (rev 8951)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm	2010-03-09 19:29:50 UTC (rev 8952)
@@ -139,6 +139,13 @@
 L<DBIx::Class::Row> objects. You can change the name of the accessor
 by supplying an L</accessor> in the column_info hash.
 
+If a column name beginning with a plus sign ('+col1') is provided, the
+attributes provided will be merged with any existing attributes for the
+column, with the new attributes taking precedence in the case that an
+attribute already exists. Using this without a hashref 
+(C<< $source->add_columns(qw/+col1 +col2/) >>) is legal, but useless --
+it does the same thing it would do without the plus.
+
 The contents of the column_info are not set in stone. The following
 keys are currently recognised/used by DBIx::Class:
 
@@ -288,9 +295,17 @@
   my @added;
   my $columns = $self->_columns;
   while (my $col = shift @cols) {
+    my $column_info = {};
+    if ($col =~ s/^\+//) {
+      $column_info = $self->column_info($col);
+    }
+
     # If next entry is { ... } use that for the column info, if not
     # use an empty hashref
-    my $column_info = ref $cols[0] ? shift(@cols) : {};
+    if (ref $cols[0]) {
+      my $new_info = shift(@cols);
+      %$column_info = (%$column_info, %$new_info);
+    }
     push(@added, $col) unless exists $columns->{$col};
     $columns->{$col} = $column_info;
   }

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSourceProxy.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSourceProxy.pm	2010-03-09 18:38:01 UTC (rev 8951)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSourceProxy.pm	2010-03-09 19:29:50 UTC (rev 8952)
@@ -37,6 +37,9 @@
   my $source = $class->result_source_instance;
   $source->add_columns(@cols);
   foreach my $c (grep { !ref } @cols) {
+    # If this is an augment definition get the real colname.
+    $c =~ s/^\+//;
+
     $class->register_column($c => $source->column_info($c));
   }
 }

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class.pm	2010-03-09 18:38:01 UTC (rev 8951)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class.pm	2010-03-09 19:29:50 UTC (rev 8952)
@@ -276,6 +276,8 @@
 
 groditi: Guillermo Roditi <groditi at cpan.org>
 
+hobbs: Andrew Rodland <arodland at cpan.org>
+
 ilmari: Dagfinn Ilmari MannsE<aring>ker <ilmari at ilmari.org>
 
 jasonmay: Jason May <jason.a.may at gmail.com>

Modified: DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Event.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Event.pm	2010-03-09 18:38:01 UTC (rev 8951)
+++ DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Event.pm	2010-03-09 19:29:50 UTC (rev 8952)
@@ -15,12 +15,22 @@
   starts_at => { data_type => 'date' },
 
   created_on => { data_type => 'timestamp' },
-  varchar_date => { data_type => 'varchar', inflate_date => 1, size => 20, is_nullable => 1 },
-  varchar_datetime => { data_type => 'varchar', inflate_datetime => 1, size => 20, is_nullable => 1 },
+  varchar_date => { data_type => 'varchar', size => 20, is_nullable => 1 },
+  varchar_datetime => { data_type => 'varchar', size => 20, is_nullable => 1 },
   skip_inflation => { data_type => 'datetime', inflate_datetime => 0, is_nullable => 1 },
   ts_without_tz => { data_type => 'datetime', is_nullable => 1 }, # used in EventTZPg
 );
 
 __PACKAGE__->set_primary_key('id');
 
+# Test add_columns '+colname' to augment a column definition.
+__PACKAGE__->add_columns(
+  '+varchar_date' => {
+    inflate_date => 1,
+  },
+  '+varchar_datetime' => {
+    inflate_datetime => 1,
+  },
+);
+
 1;




More information about the Bast-commits mailing list