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>.
40 foreach my $col (@_) {
41 $self->throw_exception("column $col doesn't exist")
42 unless $self->has_column($col);
44 $self->force_utf8_columns({ map { $_ => 1 } @_ });
47 =head1 EXTENDED METHODS
54 my ( $self, $column ) = @_;
55 my $value = $self->next::method($column);
57 if ( defined $value and $self->force_utf8_columns->{$column} ) {
58 Encode::_utf8_on($value) unless Encode::is_utf8($value);
70 my %data = $self->next::method(@_);
72 foreach my $col (grep { defined $data{$_} } keys %{ $self->force_utf8_columns }) {
73 Encode::_utf8_on($data{$col}) unless Encode::is_utf8($data{$col});
84 my ( $self, $column, $value ) = @_;
86 if ( defined $value and $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.