[Bast-commits] r9315 - in DBIx-Class/0.08/branches:
filter_column/lib/DBIx/Class filter_column/t/row
resultset-remove-columns/lib/DBIx/Class
frew at dev.catalyst.perl.org
frew at dev.catalyst.perl.org
Fri May 7 02:27:18 GMT 2010
Author: frew
Date: 2010-05-07 03:27:18 +0100 (Fri, 07 May 2010)
New Revision: 9315
Modified:
DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/FilterColumn.pm
DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/InflateColumn.pm
DBIx-Class/0.08/branches/filter_column/t/row/filter_column.t
DBIx-Class/0.08/branches/resultset-remove-columns/lib/DBIx/Class/ResultSet.pm
Log:
no filter and inflate column
Modified: DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/FilterColumn.pm
===================================================================
--- DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/FilterColumn.pm 2010-05-06 14:30:35 UTC (rev 9314)
+++ DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/FilterColumn.pm 2010-05-07 02:27:18 UTC (rev 9315)
@@ -7,6 +7,10 @@
sub filter_column {
my ($self, $col, $attrs) = @_;
+ $self->throw_exception("FilterColumn does not work with InflateColumn")
+ if $self->isa('DBIx::Class::InflateColumn') &&
+ defined $self->column_info($col)->{_inflate_info};
+
$self->throw_exception("No such column $col to filter")
unless $self->has_column($col);
@@ -30,7 +34,7 @@
return $value unless exists $info->{_filter_info};
my $filter = $info->{_filter_info}{filter_from_storage};
- $self->throw_exception("No inflator for $col") unless defined $filter;
+ $self->throw_exception("No filter for $col") unless defined $filter;
return $self->$filter($value);
}
Modified: DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/InflateColumn.pm
===================================================================
--- DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/InflateColumn.pm 2010-05-06 14:30:35 UTC (rev 9314)
+++ DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/InflateColumn.pm 2010-05-07 02:27:18 UTC (rev 9315)
@@ -74,6 +74,11 @@
sub inflate_column {
my ($self, $col, $attrs) = @_;
+
+ $self->throw_exception("InflateColumn does not work with FilterColumn")
+ if $self->isa('DBIx::Class::FilterColumn') &&
+ defined $self->column_info($col)->{_filter_info};
+
$self->throw_exception("No such column $col to inflate")
unless $self->has_column($col);
$self->throw_exception("inflate_column needs attr hashref")
Modified: DBIx-Class/0.08/branches/filter_column/t/row/filter_column.t
===================================================================
--- DBIx-Class/0.08/branches/filter_column/t/row/filter_column.t 2010-05-06 14:30:35 UTC (rev 9314)
+++ DBIx-Class/0.08/branches/filter_column/t/row/filter_column.t 2010-05-07 02:27:18 UTC (rev 9315)
@@ -2,13 +2,14 @@
use warnings;
use Test::More;
+use Test::Exception;
use lib qw(t/lib);
use DBICTest;
my $from_storage_ran = 0;
my $to_storage_ran = 0;
my $schema = DBICTest->init_schema();
-DBICTest::Schema::Artist->load_components('FilterColumn');
+DBICTest::Schema::Artist->load_components(qw(FilterColumn InflateColumn));
DBICTest::Schema::Artist->filter_column(rank => {
filter_from_storage => sub { $from_storage_ran++; $_[1] * 2 },
filter_to_storage => sub { $to_storage_ran++; $_[1] / 2 },
@@ -68,66 +69,87 @@
is $cd->artist->rank, 20, 'artist rank gets correctly filtered w/ MC';
}
-my $expected_from = $from_storage_ran;
-my $expected_to = $to_storage_ran;
+CACHE_TEST: {
+ my $expected_from = $from_storage_ran;
+ my $expected_to = $to_storage_ran;
-# ensure we are creating a fresh obj
-$artist = $schema->resultset('Artist')->single($artist->ident_condition);
+ # ensure we are creating a fresh obj
+ $artist = $schema->resultset('Artist')->single($artist->ident_condition);
-is $from_storage_ran, $expected_from, 'from has not run yet';
-is $to_storage_ran, $expected_to, 'to has not run yet';
+ is $from_storage_ran, $expected_from, 'from has not run yet';
+ is $to_storage_ran, $expected_to, 'to has not run yet';
-$artist->rank;
-cmp_ok (
- $artist->get_filtered_column('rank'),
- '!=',
- $artist->get_column('rank'),
- 'filter/unfilter differ'
-);
-is $from_storage_ran, ++$expected_from, 'from ran once, therefor caches';
-is $to_storage_ran, $expected_to, 'to did not run';
+ $artist->rank;
+ cmp_ok (
+ $artist->get_filtered_column('rank'),
+ '!=',
+ $artist->get_column('rank'),
+ 'filter/unfilter differ'
+ );
+ is $from_storage_ran, ++$expected_from, 'from ran once, therefor caches';
+ is $to_storage_ran, $expected_to, 'to did not run';
-$artist->rank(6);
-is $from_storage_ran, $expected_from, 'from did not run';
-is $to_storage_ran, ++$expected_to, 'to ran once';
+ $artist->rank(6);
+ is $from_storage_ran, $expected_from, 'from did not run';
+ is $to_storage_ran, ++$expected_to, 'to ran once';
-ok ($artist->is_column_changed ('rank'), 'Column marked as dirty');
+ ok ($artist->is_column_changed ('rank'), 'Column marked as dirty');
-$artist->rank;
-is $from_storage_ran, ++$expected_from, 'from ran once';
-is $to_storage_ran, $expected_to, 'to did not run';
+ $artist->rank;
+ is $from_storage_ran, ++$expected_from, 'from ran once';
+ is $to_storage_ran, $expected_to, 'to did not run';
-$artist->rank;
-is $from_storage_ran, $expected_from, 'from did not run';
-is $to_storage_ran, $expected_to, 'to did not run';
+ $artist->rank;
+ is $from_storage_ran, $expected_from, 'from did not run';
+ is $to_storage_ran, $expected_to, 'to did not run';
-$artist->update;
+ $artist->update;
-$artist->set_column(rank => 3);
-ok (! $artist->is_column_changed ('rank'), 'Column not marked as dirty on same set_column value');
-is ($artist->rank, '6', 'Column set properly (cache blown)');
-is $from_storage_ran, ++$expected_from, 'from ran once (set_column blew cache)';
-is $to_storage_ran, $expected_to, 'to did not run';
+ $artist->set_column(rank => 3);
+ ok (! $artist->is_column_changed ('rank'), 'Column not marked as dirty on same set_column value');
+ is ($artist->rank, '6', 'Column set properly (cache blown)');
+ is $from_storage_ran, ++$expected_from, 'from ran once (set_column blew cache)';
+ is $to_storage_ran, $expected_to, 'to did not run';
-$artist->rank(6);
-ok (! $artist->is_column_changed ('rank'), 'Column not marked as dirty on same accessor-set value');
-is ($artist->rank, '6', 'Column set properly');
-is $from_storage_ran, $expected_from, 'from did not run';
-is $to_storage_ran, $expected_to, 'to did not run';
+ $artist->rank(6);
+ ok (! $artist->is_column_changed ('rank'), 'Column not marked as dirty on same accessor-set value');
+ is ($artist->rank, '6', 'Column set properly');
+ is $from_storage_ran, $expected_from, 'from did not run';
+ is $to_storage_ran, $expected_to, 'to did not run';
-$artist->store_column(rank => 4);
-ok (! $artist->is_column_changed ('rank'), 'Column not marked as dirty on differing store_column value');
-is ($artist->rank, '6', 'Filtered column still contains old value (cache not blown)');
-is $from_storage_ran, $expected_from, 'from did not run';
-is $to_storage_ran, $expected_to, 'to did not run';
+ $artist->store_column(rank => 4);
+ ok (! $artist->is_column_changed ('rank'), 'Column not marked as dirty on differing store_column value');
+ is ($artist->rank, '6', 'Filtered column still contains old value (cache not blown)');
+ is $from_storage_ran, $expected_from, 'from did not run';
+ is $to_storage_ran, $expected_to, 'to did not run';
-$artist->set_column(rank => 4);
-TODO: {
- local $TODO = 'There seems to be no way around that much wizardry... which is ok';
- ok ($artist->is_column_changed ('rank'), 'Column marked as dirty on out-of-sync set_column value');
+ $artist->set_column(rank => 4);
+ TODO: {
+ local $TODO = 'There seems to be no way around that much wizardry... which is ok';
+ ok ($artist->is_column_changed ('rank'), 'Column marked as dirty on out-of-sync set_column value');
+ }
+ is ($artist->rank, '8', 'Column set properly (cache blown)');
+ is $from_storage_ran, ++$expected_from, 'from ran once (set_column blew cache)';
+ is $to_storage_ran, $expected_to, 'to did not run';
}
-is ($artist->rank, '8', 'Column set properly (cache blown)');
-is $from_storage_ran, ++$expected_from, 'from ran once (set_column blew cache)';
-is $to_storage_ran, $expected_to, 'to did not run';
+IC_DIE: {
+ dies_ok {
+ DBICTest::Schema::Artist->inflate_column(rank =>
+ { inflate => sub {}, deflate => sub {} }
+ );
+ } q(Can't inflate column after filter column);
+
+ DBICTest::Schema::Artist->inflate_column(name =>
+ { inflate => sub {}, deflate => sub {} }
+ );
+
+ dies_ok {
+ DBICTest::Schema::Artist->filter_column(name => {
+ filter_to_storage => sub {},
+ filter_from_storage => sub {}
+ });
+ } q(Can't filter column after inflate column);
+}
+
done_testing;
Modified: DBIx-Class/0.08/branches/resultset-remove-columns/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/branches/resultset-remove-columns/lib/DBIx/Class/ResultSet.pm 2010-05-06 14:30:35 UTC (rev 9314)
+++ DBIx-Class/0.08/branches/resultset-remove-columns/lib/DBIx/Class/ResultSet.pm 2010-05-07 02:27:18 UTC (rev 9315)
@@ -2809,17 +2809,6 @@
@cols = @{ delete $attrs->{columns}}
} elsif ( defined $attrs->{columns} ) {
@cols = delete $attrs->{columns}
- } elsif ( defined $attrs->{'remove-columns'}) {
- for ($source->columns) {
- # cribbed from http://www.stonehenge.com/merlyn/UnixReview/col11.html
- # Set subtraction
- my %temp = ();
- @temp{$source->columns} = ();
- foreach (@{ $attrs->{'remove-columns'} }) {
- delete $temp{$_};
- }
- @cols = keys %temp;
- }
} else {
@cols = $source->columns
}
@@ -2839,6 +2828,18 @@
}
}
+ if ( defined $attrs->{'remove-columns'}) {
+ for ($attrs->{columns}) {
+ # cribbed from http://www.stonehenge.com/merlyn/UnixReview/col11.html
+ # Set subtraction
+ my %temp = ();
+ @temp{$source->columns} = ();
+ foreach (@{ $attrs->{'remove-columns'} }) {
+ delete $temp{$_};
+ }
+ @cols = keys %temp;
+ }
+ }
# add the additional columns on
foreach (qw{include_columns +columns}) {
if ( $attrs->{$_} ) {
More information about the Bast-commits
mailing list