[Bast-commits] r5273 - in DBIx-Class/0.08/branches/result_source_sqlt_deploy_hook/lib: DBIx/Class SQL/Translator/Parser/DBIx

nothingmuch at dev.catalyst.perl.org nothingmuch at dev.catalyst.perl.org
Mon Dec 22 02:09:23 GMT 2008


Author: nothingmuch
Date: 2008-12-22 02:09:23 +0000 (Mon, 22 Dec 2008)
New Revision: 5273

Modified:
   DBIx-Class/0.08/branches/result_source_sqlt_deploy_hook/lib/DBIx/Class/ResultSource.pm
   DBIx-Class/0.08/branches/result_source_sqlt_deploy_hook/lib/SQL/Translator/Parser/DBIx/Class.pm
Log:
add sqlt_deploy_hook to result source, which delegates to the class hook by default

Modified: DBIx-Class/0.08/branches/result_source_sqlt_deploy_hook/lib/DBIx/Class/ResultSource.pm
===================================================================
--- DBIx-Class/0.08/branches/result_source_sqlt_deploy_hook/lib/DBIx/Class/ResultSource.pm	2008-12-22 02:07:41 UTC (rev 5272)
+++ DBIx-Class/0.08/branches/result_source_sqlt_deploy_hook/lib/DBIx/Class/ResultSource.pm	2008-12-22 02:09:23 UTC (rev 5273)
@@ -13,7 +13,7 @@
 __PACKAGE__->mk_group_accessors('simple' => qw/_ordered_columns
   _columns _primaries _unique_constraints name resultset_attributes
   schema from _relationships column_info_from_storage source_info
-  source_name/);
+  source_name sqlt_deploy_callback/);
 
 __PACKAGE__->mk_group_accessors('component_class' => qw/resultset_class
   result_class/);
@@ -55,6 +55,7 @@
   $new->{_relationships} = { %{$new->{_relationships}||{}} };
   $new->{name} ||= "!!NAME NOT SET!!";
   $new->{_columns_info_loaded} ||= 0;
+  $new->{sqlt_deploy_callback} ||= "default_sqlt_deploy_callback";
   return $new;
 }
 
@@ -1132,15 +1133,48 @@
   }
 }
 
+
 =head2 sqlt_deploy_hook($sqlt_table)
 
-An optional sub which you can declare in your own Schema class that will get 
-passed the L<SQL::Translator::Schema::Table> object when you deploy the schema
-via L</create_ddl_dir> or L</deploy>.
+Triggers C<sqlt_deploy_callback>.
 
+=cut
+
+sub sqlt_deploy_hook {
+  my $self = shift;
+  if ( my $hook = $self->sqlt_deploy_callback) {
+    $self->$hook(@_);
+  }
+}
+
+=head2 default_sqlt_deploy_callback($table)
+
+Delegates to a an optional C<sqlt_deploy_hook> method on the C<result_class>.
+
+This will get passed the L<SQL::Translator::Schema::Table> object when you
+deploy the schema via L</create_ddl_dir> or L</deploy>.
+
 For an example of what you can do with this, see 
 L<DBIx::Class::Manual::Cookbook/Adding Indexes And Functions To Your SQL>.
 
+=cut
+
+sub default_sqlt_deploy_callback {
+  my $self = shift;
+
+  my $class = $self->result_class;
+
+  if ($class and $class->result_class->can('sqlt_deploy_hook')) {
+    $class->sqlt_deploy_hook(@_);
+  }
+}
+
+=head2 sqlt_deploy_callback
+
+An attribute which contains the callback to trigger on C<sqlt_deploy_hook>.
+Defaults to C<default_sqlt_deploy_callback>. Can be a code reference or a
+method name.
+
 =head1 AUTHORS
 
 Matt S. Trout <mst at shadowcatsystems.co.uk>

Modified: DBIx-Class/0.08/branches/result_source_sqlt_deploy_hook/lib/SQL/Translator/Parser/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/branches/result_source_sqlt_deploy_hook/lib/SQL/Translator/Parser/DBIx/Class.pm	2008-12-22 02:07:41 UTC (rev 5272)
+++ DBIx-Class/0.08/branches/result_source_sqlt_deploy_hook/lib/SQL/Translator/Parser/DBIx/Class.pm	2008-12-22 02:09:23 UTC (rev 5273)
@@ -214,9 +214,7 @@
             }
         }
 		
-        if ($source->result_class->can('sqlt_deploy_hook')) {
-          $source->result_class->sqlt_deploy_hook($table);
-        }
+        $source->sqlt_deploy_hook($table)
     }
 
     if ($dbicschema->can('sqlt_deploy_hook')) {




More information about the Bast-commits mailing list