DESCRIPTION

This module codifies a pattern that I've used in a number of projects, namely that of doing something when a column changes it's value in the database. It leverages DBIx::Class::Helper::Row::StorageValues for passing in the $old_value, which do not have to use. If you leave the keep_storage_value out of the column definition it will just pass undef in as the $old_value. Also note the txn_wrap option. This allows you to specify that you want the call to update and the call to the method you requested to be wrapped in a transaction. If you end up calling more than one method due to multple column change methods and more than one specify txn_wrap it will still only wrap once.

I've gone to great lengths to ensure that order is preserved, so before and around changes are called in order of definition and after changes are called in reverse order.

To be clear, the change methods only get called if the value will be changed after update runs. It correctly looks at the current value of the column as well as the arguments passed to update.

METHODS

before_column_change

__PACKAGE__->before_column_change(
col_name => {
method => 'method', # <-- anything that can be called as a method
txn_wrap => 1, # <-- true if you want it to be wrapped in a txn
}
);

Note: the arguments passed to method will be $self, $old_value, $new_value.

after_column_change

__PACKAGE__->after_column_change(
col_name => {
method => 'method', # <-- anything that can be called as a method
txn_wrap => 1, # <-- true if you want it to be wrapped in a txn
}
);

Note: the arguments passed to method will be $self, $old_value, $new_value.

around_column_change

__PACKAGE__->around_column_change(
col_name => {
method => 'method', # <-- anything that can be called as a method
txn_wrap => 1, # <-- true if you want it to be wrapped in a txn
}
);

Note: the arguments passed to method will be $self, $next, $old_value, $new_value.

Around is subtly different than the other two callbacks. You must call $next in your method or it will not work at all. A silly example of how this is done could be: