DBIx::Class::FilterColumn::ByType - Apply FilterColumn by type instead of name
version 1.122121
In your Schema or DB class add "FilterColumn::ByType" to the top of the component list.
__PACKAGE__->load_components(qw( FilterColumn::ByType ... ));
Set up filters for the column types you want to convert.
__PACKAGE__->filter_columns_by_type( [qw/varchar text/] => { filter_to_storage => 'to_utf8', filter_from_storage => 'from_utf8', }); use Encode; sub to_utf8 { encode('utf8', $_[1]) } sub from_utf8 { decode('utf8', $_[1]) } 1;
This module is a subclass of DBIx::Class::FilterColumn, which allows you to attach filters by column type, as well as by column name. You should look at DBIx::Class::FilterColumn documentation for a full explanation of how FilterColumn works.
If you'd like to do something like filter all varchars in your entire schema, you would only need to create a base result class, then call filter_columns_by_type from there. See t/lib/A/Schema inside the dist for an example.
__PACKAGE__->filter_columns_by_type( coltype => { ... }) __PACKAGE__->filter_columns_by_type( [qw/coltype/] => { ... })
This method takes two arguments. The first, coltype, can be either an array of scalars, or a scalar that describe the type(s) the filters will be attached to. The second argument is passed straight through to FilterColumn::filter_column() without modification.
DBIx::Class, DBIx::Class::FilterColumn
Matthew Phillips <mattp@cpan.org>
This software is copyright (c) 2012 by Matthew Phillips.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install DBIx::Class::FilterColumn::ByType, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class::FilterColumn::ByType
CPAN shell
perl -MCPAN -e shell install DBIx::Class::FilterColumn::ByType
For more information on module installation, please visit the detailed CPAN module installation guide.