[Bast-commits] r9311 - in DBIx-Class/0.08/branches/filter_column:
lib/DBIx/Class t/row
frew at dev.catalyst.perl.org
frew at dev.catalyst.perl.org
Wed May 5 23:49:25 GMT 2010
Author: frew
Date: 2010-05-06 00:49:25 +0100 (Thu, 06 May 2010)
New Revision: 9311
Modified:
DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/FilterColumn.pm
DBIx-Class/0.08/branches/filter_column/t/row/filter_column.t
Log:
test caching
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-05 12:56:37 UTC (rev 9310)
+++ DBIx-Class/0.08/branches/filter_column/lib/DBIx/Class/FilterColumn.pm 2010-05-05 23:49:25 UTC (rev 9311)
@@ -62,6 +62,15 @@
return $self->{_filtered_column}{$col} = $self->_column_from_storage($col, $val);
}
+sub set_column {
+ my ($self, $col) = (shift, @_);
+
+ # blow cache
+ delete $self->{_filtered_column}{$col};
+
+ $self->next::method(@_);
+}
+
sub set_filtered_column {
my ($self, $col, $filtered) = @_;
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-05 12:56:37 UTC (rev 9310)
+++ DBIx-Class/0.08/branches/filter_column/t/row/filter_column.t 2010-05-05 23:49:25 UTC (rev 9311)
@@ -5,11 +5,13 @@
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->filter_column(rank => {
- filter_from_storage => sub { $_[1] * 2 },
- filter_to_storage => sub { $_[1] / 2 },
+ filter_from_storage => sub { $from_storage_ran++; $_[1] * 2 },
+ filter_to_storage => sub { $to_storage_ran++; $_[1] / 2 },
});
Class::C3->reinitialize();
@@ -66,4 +68,51 @@
is $cd->artist->rank, 20, 'artist rank gets correctly filtered w/ MC';
}
+my $initial_from = $from_storage_ran;
+my $initial_to = $to_storage_ran;
+
+# ensure we are creating a fresh obj
+$artist = $schema->resultset('Artist')->single($artist->ident_condition);
+
+is $initial_from, $from_storage_ran, 'from has not run yet';
+is $initial_from, $from_storage_ran, 'to has not run yet';
+
+$artist->rank;
+$artist->get_filtered_column('rank');
+$artist->get_column('rank');
+
+is $from_storage_ran, $initial_from + 1, 'from ran once, therefor caches';
+is $to_storage_ran, $initial_to, 'to ran none';
+$initial_from = $from_storage_ran;
+$initial_to = $to_storage_ran;
+
+$artist->rank(1);
+
+is $from_storage_ran, $initial_from, 'from ran none';
+is $to_storage_ran, $initial_to + 1, 'to ran once';
+$initial_from = $from_storage_ran;
+$initial_to = $to_storage_ran;
+
+$artist->rank;
+
+is $from_storage_ran, $initial_from + 1, 'from ran once';
+is $to_storage_ran, $initial_to, 'to ran none';
+$initial_from = $from_storage_ran;
+$initial_to = $to_storage_ran;
+
+$artist->rank;
+
+is $from_storage_ran, $initial_from, 'from ran none';
+is $to_storage_ran, $initial_to, 'to ran none';
+$initial_from = $from_storage_ran;
+$initial_to = $to_storage_ran;
+
+$artist->set_column(rank => 1);
+$artist->rank;
+
+is $from_storage_ran, $initial_from + 1, 'from ran once (set column blows cache)';
+is $to_storage_ran, $initial_to, 'to ran none';
+$initial_from = $from_storage_ran;
+$initial_to = $to_storage_ran;
+
done_testing;
More information about the Bast-commits
mailing list