[Bast-commits] r5329 - in DBIx-Class/0.08/trunk: lib/DBIx/Class t
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Tue Jan 20 23:39:24 GMT 2009
Author: ribasushi
Date: 2009-01-20 23:39:24 +0000 (Tue, 20 Jan 2009)
New Revision: 5329
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm
DBIx-Class/0.08/trunk/t/60core.t
Log:
remove_columns() sanitization by Oleg Pronin
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm 2009-01-20 23:11:20 UTC (rev 5328)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSource.pm 2009-01-20 23:39:24 UTC (rev 5329)
@@ -318,22 +318,18 @@
=cut
sub remove_columns {
- my ($self, @cols) = @_;
+ my ($self, @to_remove) = @_;
- return unless $self->_ordered_columns;
+ my $columns = $self->_columns
+ or return;
- my $columns = $self->_columns;
- my @remaining;
-
- foreach my $col (@{$self->_ordered_columns}) {
- push @remaining, $col unless grep(/$col/, @cols);
+ my %to_remove;
+ for (@to_remove) {
+ delete $columns->{$_};
+ ++$to_remove{$_};
}
- foreach (@cols) {
- delete $columns->{$_};
- };
-
- $self->_ordered_columns(\@remaining);
+ $self->_ordered_columns([ grep { not $to_remove{$_} } @{$self->_ordered_columns} ]);
}
sub remove_column { shift->remove_columns(@_); } # DO NOT CHANGE THIS TO GLOB
Modified: DBIx-Class/0.08/trunk/t/60core.t
===================================================================
--- DBIx-Class/0.08/trunk/t/60core.t 2009-01-20 23:11:20 UTC (rev 5328)
+++ DBIx-Class/0.08/trunk/t/60core.t 2009-01-20 23:39:24 UTC (rev 5329)
@@ -7,7 +7,7 @@
my $schema = DBICTest->init_schema();
-plan tests => 84;
+plan tests => 86;
eval { require DateTime::Format::MySQL };
my $NO_DTFM = $@ ? 1 : 0;
@@ -335,10 +335,29 @@
# test remove_columns
{
- is_deeply([$schema->source('CD')->columns], [qw/cdid artist title year genreid single_track/]);
- $schema->source('CD')->remove_columns('year');
- is_deeply([$schema->source('CD')->columns], [qw/cdid artist title genreid single_track/]);
- ok(! exists $schema->source('CD')->_columns->{'year'}, 'year still exists in _columns');
+ is_deeply(
+ [$schema->source('CD')->columns],
+ [qw/cdid artist title year genreid single_track/],
+ 'initial columns',
+ );
+
+ $schema->source('CD')->remove_columns('coolyear'); #should not delete year
+ is_deeply(
+ [$schema->source('CD')->columns],
+ [qw/cdid artist title year genreid single_track/],
+ 'nothing removed when removing a non-existent column',
+ );
+
+ $schema->source('CD')->remove_columns('genreid', 'year');
+ is_deeply(
+ [$schema->source('CD')->columns],
+ [qw/cdid artist title single_track/],
+ 'removed two columns',
+ );
+
+ my $priv_columns = $schema->source('CD')->_columns;
+ ok(! exists $priv_columns->{'year'}, 'year purged from _columns');
+ ok(! exists $priv_columns->{'genreid'}, 'genreid purged from _columns');
}
# test get_inflated_columns with objects
More information about the Bast-commits
mailing list