Revision history for DBIx::Class
+ - cleanup UTF8Columns and make more efficient
- rename DBIX_CLASS_STORAGE_DBI_DEBUG to DBIC_TRACE
- rename _parent_rs to _parent_source in ResultSet
use Encode;
-__PACKAGE__->mk_classdata( force_utf8_columns => [] );
+__PACKAGE__->mk_classdata( 'force_utf8_columns' );
=head1 NAME
sub utf8_columns {
my $self = shift;
- for (@_) {
- $self->throw_exception("column $_ doesn't exist")
- unless $self->has_column($_);
+ foreach my $col (@_) {
+ $self->throw_exception("column $col doesn't exist")
+ unless $self->has_column($col);
}
- $self->force_utf8_columns( \@_ );
+ $self->force_utf8_columns({ map { $_ => 1 } @_ });
}
=head1 EXTENDED METHODS
my ( $self, $column ) = @_;
my $value = $self->next::method($column);
- if ( { map { $_ => 1 } @{ $self->force_utf8_columns } }->{$column} ) {
+ if ( defined $value and $self->force_utf8_columns->{$column} ) {
Encode::_utf8_on($value) unless Encode::is_utf8($value);
}
my $self = shift;
my %data = $self->next::method(@_);
- for (@{ $self->force_utf8_columns }) {
- Encode::_utf8_on($data{$_}) if $data{$_} and !Encode::is_utf8($_);
+ foreach my $col (grep { defined $data{$_} } keys %{ $self->force_utf8_columns }) {
+ Encode::_utf8_on($data{$col}) unless Encode::is_utf8($data{$col});
}
%data;
sub store_column {
my ( $self, $column, $value ) = @_;
- if ( { map { $_ => 1 } @{ $self->force_utf8_columns } }->{$column} ) {
+ if ( defined $value and $self->force_utf8_columns->{$column} ) {
Encode::_utf8_off($value) if Encode::is_utf8($value);
}
eval 'use Encode ; 1'
or plan skip_all => 'Install Encode run this test';
-plan tests => 2;
+plan tests => 3;
-DBICTest::Schema::Artist->load_components('UTF8Columns');
-DBICTest::Schema::Artist->utf8_columns('name');
+DBICTest::Schema::CD->load_components('UTF8Columns');
+DBICTest::Schema::CD->utf8_columns('title');
Class::C3->reinitialize();
-my $artist = $schema->resultset("Artist")->create( { name => 'uni' } );
-ok( Encode::is_utf8( $artist->name ), 'got name with utf8 flag' );
+my $cd = $schema->resultset('CD')->create( { artist => 1, title => 'uni', year => 'foo' } );
+ok( Encode::is_utf8( $cd->title ), 'got title with utf8 flag' );
+ok( !Encode::is_utf8( $cd->year ), 'got year without utf8 flag' );
my $utf8_char = 'uniuni';
Encode::_utf8_on($utf8_char);
-$artist->name($utf8_char);
-ok( !Encode::is_utf8( $artist->{_column_data}->{name} ),
- 'store utf8 less chars' );
+$cd->title($utf8_char);
+ok( !Encode::is_utf8( $cd->{_column_data}{title} ),
+ 'store utf8-less chars' );