From: Matt S Trout Date: Thu, 27 Apr 2006 20:43:45 +0000 (+0000) Subject: pod patch from ted X-Git-Tag: v0.07002~109 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=086b93a29f2e26fbf269abee884535e46307697c;p=dbsrgits%2FDBIx-Class.git pod patch from ted --- diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 35b7d40..3518c29 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -690,4 +690,45 @@ is enough. If the left quote differs form the right quote, the first notation should be used. name_sep needs to be set to allow the SQL generator to put the quotes the correct place. +=head2 Overloading methods + +L uses the L package, which provides for redispatch of +method calls. You have to use calls to C to overload methods. +More information on using L with L can be found in +L. + +=head3 Changing one field whenever another changes + +For example, say that you have three columns, C, C, and +C. You would like to make changes to C and have +C be automagically set to the value of C squared. +You can accomplish this by overriding C: + + sub store_column { + my ( $self, $name, $value ) = @_; + if ($name eq 'number') { + $self->squared($value * $value); + } + $self->next::method($name, $value); + } + +Note that the hard work is done by the call to C, which +redispatches your call to store_column to the superclass(es). + +=head3 Automatically creating related objects + +You might have a class C which has many Cs. Further, you +want to create a C object every time you insert an C object. +You can accomplish this by overriding C: + + sub insert { + my ( $class, $args_ref ) = @_; + my $self = $class->next::method($args_ref); + $self->cds->new({})->fill_from_artist($self)->insert; + return $self; + } + +where C is a method you specify in C which sets +values in C based on the data in the C object you pass in. + =cut