Arthur Axel "fREW" Schmidt > DBIx-Class-0.08123 > DBIx::Class::FilterColumn

Download:
DBIx-Class-0.08123.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

New  12
Open  16
Stalled  11
View/Report Bugs
Source   Latest Release: DBIx-Class-0.08204_01

NAME ^

DBIx::Class::FilterColumn - Automatically convert column data

SYNOPSIS ^

 # 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;

DESCRIPTION ^

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.

METHODS ^

filter_column

 __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.

get_filtered_column

 $obj->get_filtered_column('colname')

Returns the filtered value of the column

set_filtered_column

 $obj->set_filtered_column(colname => 'new_value')

Sets the filtered value of the column

syntax highlighting: