=for comment POD_DERIVED_INDEX_GENERATED The following documentation is automatically generated. Please do not edit this file, but rather the original, inline with DBIx::Class::FilterColumn at lib/DBIx/Class/FilterColumn.pm (on the system that originally ran this). If you do edit this file, and don't want your changes to be removed, make sure you change the first line. =cut =head1 NAME DBIx::Class::FilterColumn - Automatically convert column data =head1 SYNOPSIS 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; =head1 DESCRIPTION This component is meant to be a more powerful, but less DWIM-y, L. One of the major issues with said component is that it B works with references. Generally speaking anything that can be done with L can be done with this component. =head1 METHODS =head2 filter_column __PACKAGE__->filter_column( colname => { filter_from_storage => 'method'|\&coderef, filter_to_storage => 'method'|\&coderef, }) 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 hash reference with C and C set to either a method name or a code reference. In either case the filter is invoked as: $result->$filter_specification ($value_to_filter) with C<$filter_specification> being chosen depending on whether the C<$value_to_filter> is being retrieved from or written to permanent storage. If a specific directional filter is not specified, the original value will be passed to/from storage unfiltered. =head2 get_filtered_column $obj->get_filtered_column('colname') Returns the filtered value of the column =head2 set_filtered_column $obj->set_filtered_column(colname => 'new_value') Sets the filtered value of the column =head1 EXAMPLE OF USE Some databases have restrictions on values that can be passed to boolean columns, and problems can be caused by passing value that perl considers to be false (such as C). One solution to this is to ensure that the boolean values are set to something that the database can handle - such as numeric zero and one, using code like this:- __PACKAGE__->filter_column( my_boolean_column => { filter_to_storage => sub { $_[1] ? 1 : 0 }, } ); In this case the C is not required, as just passing the database value through to perl does the right thing. =head1 INHERITED METHODS =over 4 =item L L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L =back =head1 FURTHER QUESTIONS? Check the list of L. =head1 COPYRIGHT AND LICENSE This module is free software L by the L. You can redistribute it and/or modify it under the same terms as the L.