From: Peter Rabbitson Date: Wed, 27 Oct 2010 11:57:39 +0000 (+0200) Subject: Add a fix to cookbook recipe X-Git-Tag: v0.08124~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=70e6d5f7d5881c08702f71c6de80effc2f264ade Add a fix to cookbook recipe --- diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 83f7cee..3c08004 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -1878,14 +1878,18 @@ just looking for this. 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 in your L: +You can accomplish this by wrapping the C accessor with +L: - sub store_column { - my ( $self, $name, $value ) = @_; - if ($name eq 'number') { - $self->squared($value * $value); + around number => sub { + my ($orig, $self) = (shift, shift); + + if (@_) { + my $value = $_[0]; + $self->squared( $value * $value ); } - $self->next::method($name, $value); + + $self->next::method(@_); } Note that the hard work is done by the call to C, which