1 package DBIx::Class::UTF8Columns;
4 use base qw/DBIx::Class/;
8 __PACKAGE__->mk_classdata( force_utf8_columns => [] );
12 DBIx::Class::UTF8Columns - Force UTF8 (Unicode) flag on columns
17 __PACKAGE__->load_components(qw/UTF8Columns Core/);
18 __PACKAGE__->utf8_columns(qw/name description/);
20 # then belows return strings with utf8 flag
22 $artist->get_column('description');
26 This module allows you to get columns data that have utf8 (Unicode) flag.
30 L<Template::Stash::ForceUTF8>, L<DBIx::Class::UUIDColumns>.
41 $self->throw_exception("column $_ doesn't exist")
42 unless $self->has_column($_);
44 $self->force_utf8_columns( \@_ );
47 =head1 EXTENDED METHODS
54 my ( $self, $column ) = @_;
55 my $value = $self->next::method($column);
57 if ( { map { $_ => 1 } @{ $self->force_utf8_columns } }->{$column} ) {
58 Encode::_utf8_on($value) unless Encode::is_utf8($value);
70 my %data = $self->next::method(@_);
72 for (@{ $self->force_utf8_columns }) {
73 Encode::_utf8_on($data{$_}) if $data{$_} and !Encode::is_utf8($_);
84 my ( $self, $column, $value ) = @_;
86 if ( { map { $_ => 1 } @{ $self->force_utf8_columns } }->{$column} ) {
87 Encode::_utf8_off($value) if Encode::is_utf8($value);
90 $self->next::method( $column, $value );
95 Daisuke Murase <typester@cpan.org>
99 This program is free software; you can redistribute
100 it and/or modify it under the same terms as Perl itself.
102 The full text of the license can be found in the
103 LICENSE file included with this module.