1 package DBIx::Class::UTF8Columns;
4 use base qw/DBIx::Class/;
7 __PACKAGE__->mk_classdata( '_utf8_columns' );
11 DBIx::Class::UTF8Columns - Force UTF8 (Unicode) flag on columns
16 use base 'DBIx::Class::Core';
18 __PACKAGE__->load_components(qw/UTF8Columns/);
19 __PACKAGE__->utf8_columns(qw/name description/);
21 # then belows return strings with utf8 flag
23 $artist->get_column('description');
27 This module allows you to get columns data that have utf8 (Unicode) flag.
31 L<Template::Stash::ForceUTF8>, L<DBIx::Class::UUIDColumns>.
42 foreach my $col (@_) {
43 $self->throw_exception("column $col doesn't exist")
44 unless $self->has_column($col);
46 return $self->_utf8_columns({ map { $_ => 1 } @_ });
48 return $self->_utf8_columns;
52 =head1 EXTENDED METHODS
59 my ( $self, $column ) = @_;
60 my $value = $self->next::method($column);
62 my $cols = $self->_utf8_columns;
63 if ( $cols and defined $value and $cols->{$column} ) {
64 utf8::decode($value) unless utf8::is_utf8($value);
76 my %data = $self->next::method(@_);
78 foreach my $col (grep { defined $data{$_} } keys %{ $self->_utf8_columns || {} }) {
79 utf8::decode($data{$col}) unless utf8::is_utf8($data{$col});
90 my ( $self, $column, $value ) = @_;
92 my $cols = $self->_utf8_columns;
93 if ( $cols and defined $value and $cols->{$column} ) {
94 utf8::encode($value) if utf8::is_utf8($value);
97 $self->next::method( $column, $value );
102 Daisuke Murase <typester@cpan.org>
106 This program is free software; you can redistribute
107 it and/or modify it under the same terms as Perl itself.
109 The full text of the license can be found in the
110 LICENSE file included with this module.