From: Peter Rabbitson Date: Wed, 21 Jan 2009 15:52:25 +0000 (+0000) Subject: better hook docs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f97f9210550436b841141e791ee25dd3c723ab63;p=dbsrgits%2FDBIx-Class-Historic.git better hook docs --- diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index cbba2a0..055f89a 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -1385,11 +1385,17 @@ should not be used. It will be removed before 1.0. __PACKAGE__->column_info_from_storage(1); -=cut +=head2 sqlt_deploy_callback -=head2 sqlt_deploy_hook +An attribute which contains the callback to trigger on L. +Defaults to L. Can be a code reference or the name +of a method in the current result class. You would change the default value +in case you want to share a hook between several result sources, or if you +want to use a result source without a declared result class. -=over 4 +=head2 default_sqlt_deploy_hook + +=over =item Arguments: $source, $sqlt_table @@ -1397,67 +1403,58 @@ should not be used. It will be removed before 1.0. =back -An optional sub which you can declare in your own Result class that will get -passed the L object when you deploy the schema -via L or L. - -This is useful to make L create non-unique indexes, or set -table options such as C. For an example of what you can do with -this, see +Proxies its arguments to a C method on the C +if such a method exists. This is useful to make L create +non-unique indexes, or set table options such as C. For +examples of what you can do with this, see L. -Note that sqlt_deploy_hook is called by -L, which in turn is called before -L. Therefore the hook can be used only to manipulate -the L object before it is turned into SQL fed to the -database. If you want to execute post-deploy statements which can not be generated -by L, the currently suggested method is to overload -L and use L. - -Starting from DBIC 0.08100 a simple hook is inherited by all result sources, which -invokes the method or coderef specified in L. You can still -overload this method like in older DBIC versions without any compatibility issues. - =cut -sub sqlt_deploy_hook { +sub default_sqlt_deploy_hook { my $self = shift; - if ( my $hook = $self->sqlt_deploy_callback) { - $self->$hook(@_); + + my $class = $self->result_class; + + if ($class and $class->can('sqlt_deploy_hook')) { + $class->sqlt_deploy_hook(@_); } } -=head2 sqlt_deploy_callback -An attribute which contains the callback to trigger on C. -Defaults to C. Can be a code reference or the name -of a method in a result class. You would change the default value in case you -want to share a hook between several result sources, or if you want to use a -result source without a declared result class. +=head2 sqlt_deploy_hook -=head2 default_sqlt_deploy_hook($table) +=over 4 -Delegates to a an optional C method on the C. +=item Arguments: $source, $sqlt_table -This will get passed the L object when you -deploy the schema via L or L. +=item Return value: undefined -For an example of what you can do with this, see -L. +=back -=cut +This is the entry point invoked by L +during the execution of L. +Delegates to the method name or code reference specified in +L. -sub default_sqlt_deploy_hook { - my $self = shift; +Note that the code is called by +L, which in turn is called +before L. Therefore the hook can be used only +to manipulate the L object before it is turned into +SQL fed to the database. If you want to execute post-deploy statements which +currently can can not be generated by L, the suggested +method is to overload L and use +L. - my $class = $self->result_class; +=cut - if ($class and $class->can('sqlt_deploy_hook')) { - $class->sqlt_deploy_hook(@_); +sub sqlt_deploy_hook { + my $self = shift; + if ( my $hook = $self->sqlt_deploy_callback) { + $self->$hook(@_); } } - =head1 AUTHORS Matt S. Trout