1 package DBIx::Class::UTF8Columns;
4 use base qw/DBIx::Class/;
8 __PACKAGE__->mk_classdata( '_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 foreach my $col (@_) {
42 $self->throw_exception("column $col doesn't exist")
43 unless $self->has_column($col);
45 return $self->_utf8_columns({ map { $_ => 1 } @_ });
47 return $self->_utf8_columns;
51 =head1 EXTENDED METHODS
58 my ( $self, $column ) = @_;
59 my $value = $self->next::method($column);
61 my $cols = $self->_utf8_columns;
62 if ( $cols and defined $value and $cols->{$column} ) {
63 Encode::_utf8_on($value) unless Encode::is_utf8($value);
75 my %data = $self->next::method(@_);
77 foreach my $col (grep { defined $data{$_} } keys %{ $self->_utf8_columns || {} }) {
78 Encode::_utf8_on($data{$col}) unless Encode::is_utf8($data{$col});
89 my ( $self, $column, $value ) = @_;
91 my $cols = $self->_utf8_columns;
92 if ( $cols and defined $value and $cols->{$column} ) {
93 Encode::_utf8_off($value) if Encode::is_utf8($value);
96 $self->next::method( $column, $value );
101 Daisuke Murase <typester@cpan.org>
105 This program is free software; you can redistribute
106 it and/or modify it under the same terms as Perl itself.
108 The full text of the license can be found in the
109 LICENSE file included with this module.