From: Pedro Melo Date: Tue, 24 May 2011 14:18:34 +0000 (+0100) Subject: Revert "Fix incorrect default sqlt_deploy_hook signature" (fed15b916) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f3fd2621c5509873aa30e7a68b7dd670421cc86;p=dbsrgits%2FDBIx-Class-Historic.git Revert "Fix incorrect default sqlt_deploy_hook signature" (fed15b916) With this change, code that uses next::can or next::method inside sql_deploy_hook(), like components, stops working. Also fix documentation to match the actual code --- diff --git a/Changes b/Changes index 234c658..9701d7f 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,5 @@ Revision history for DBIx::Class - * New Features / Changes - Allow schema cloning to mutate attributes. @@ -8,6 +7,8 @@ Revision history for DBIx::Class - Fix issue where the query was becoming overly mangled when trying to use pagination with a query that has a sub-select in the WHERE clause. + - Revert "Fix incorrect signature of the default sqlt_deploy_hook" + from 0.08191 - documentation was in fact incorrect, not the code 0.08192 2011-05-10 04:20 (UTC) * Fixes diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 83f4c8e..228ade3 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -886,12 +886,21 @@ sub unique_constraint_columns { =over -=item Arguments: $callback +=item Arguments: $callback_name | \&callback_code + +=item Return value: $callback_name | \&callback_code =back __PACKAGE__->sqlt_deploy_callback('mycallbackmethod'); + or + + __PACKAGE__->sqlt_deploy_callback(sub { + my ($source_instance, $sqlt_table) = @_; + ... + } ); + An accessor to set a callback to be called during deployment of the schema via L or L. @@ -899,7 +908,7 @@ L. The callback can be set as either a code reference or the name of a method in the current result class. -If not set, the L is called. +Defaults to L. Your callback will be passed the $source object representing the ResultSource instance being deployed, and the @@ -919,19 +928,13 @@ and call L. =head2 default_sqlt_deploy_hook -=over - -=item Arguments: $source, $sqlt_table - -=item Return value: undefined - -=back - -This is the sensible default for L. - -If a method named C exists in your Result class, it -will be called and passed the current C<$source> and the -C<$sqlt_table> being deployed. +This is the default deploy hook implementation which checks if your +current Result class has a C method, and if present +invokes it B. This is to preserve the +semantics of C which was originally designed to expect +the Result class name and the +L<$sqlt_table instance|SQL::Translator::Schema::Table> of the table being +deployed. =cut @@ -940,8 +943,8 @@ sub default_sqlt_deploy_hook { my $class = $self->result_class; - if ($class and my $hook = $class->can('sqlt_deploy_hook')) { - $self->$hook(@_); + if ($class and $class->can('sqlt_deploy_hook')) { + $class->sqlt_deploy_hook(@_); } } diff --git a/t/86sqlt.t b/t/86sqlt.t index d240a9c..6435ba9 100644 --- a/t/86sqlt.t +++ b/t/86sqlt.t @@ -61,11 +61,11 @@ my $schema = DBICTest->init_schema (no_deploy => 1); # add a temporary sqlt_deploy_hook to a source no warnings 'once'; local *DBICTest::Track::sqlt_deploy_hook = sub { - my ($self, $sqlt_table) = @_; + my ($class, $sqlt_table) = @_; $deploy_hook_called = 1; - is (blessed ($self), 'DBIx::Class::ResultSource::Table', 'Source object passed to plain hook'); + is ($class, 'DBICTest::Track', 'Result class passed to plain hook'); is ( $sqlt_table->schema->translator->producer_type,