The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DBIx::Class::FilterColumn::ByType - Apply FilterColumn by type instead of name

VERSION

version 1.122121

SYNOPSIS

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;

DESCRIPTION

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.

METHODS

filter_column_by_type

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

SEE ALSO

DBIx::Class, DBIx::Class::FilterColumn

AUTHOR

Matthew Phillips <mattp@cpan.org>

COPYRIGHT AND LICENSE

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.