DBIx::Class::FilterColumn - Automatically convert column data
In your Schema or DB class add "FilterColumn" to the top of the component list.
__PACKAGE__->load_components(qw( FilterColumn ... ));
Set up filters for the columns you want to convert.
__PACKAGE__->filter_column( money => {
filter_to_storage => 'to_pennies',
filter_from_storage => 'from_pennies',
});
sub to_pennies { $_[1] * 100 }
sub from_pennies { $_[1] / 100 }
1;
This component is meant to be a more powerful, but less DWIM-y, DBIx::Class::InflateColumn. One of the major issues with said component is that it only works with references. Generally speaking anything that can be done with DBIx::Class::InflateColumn can be done with this component.
__PACKAGE__->filter_column( colname => {
filter_from_storage => 'method',
filter_to_storage => 'method',
})
This is the method that you need to call to set up a filtered column. It takes exactly two arguments; the first being the column name the second being a HashRef with filter_from_storage and filter_to_storage having something that can be called as a method. The method will be called with the value of the column as the first non-$self argument.
$obj->get_filtered_column('colname')
Returns the filtered value of the column
$obj->set_filtered_column(colname => 'new_value')
Sets the filtered value of the column
MULTICREATE_DEBUG, copy, delete, discard_changes, get_dirty_columns, get_from_storage, get_inflated_columns, has_column_loaded, in_storage, inflate_result, insert, insert_or_update, is_changed, is_column_changed, make_column_dirty, register_column, result_source, set_column, set_columns, set_inflated_columns, throw_exception, update_or_insert
MODIFY_CODE_ATTRIBUTES, component_base_class, mk_classaccessor, mk_classdata
inject_base
ensure_class_found, ensure_class_loaded, load_components, load_optional_class, load_optional_components, load_own_components
get_component_class, get_inherited, get_simple, get_super_paths, make_group_accessor, make_group_ro_accessor, make_group_wo_accessor, mk_group_accessors, mk_group_ro_accessors, mk_group_wo_accessors, set_component_class, set_inherited, set_simple