DBIx::Class::FilterColumn - Automatically convert column data
# In your result classes __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.
HashRef
filter_from_storage
filter_to_storage
$self
$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
To install DBIx::Class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class
CPAN shell
perl -MCPAN -e shell install DBIx::Class
For more information on module installation, please visit the detailed CPAN module installation guide.