no filter and inflate column
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / FilterColumn.pm
index 2f9b4f1..a6bda53 100644 (file)
@@ -7,6 +7,10 @@ use base qw/DBIx::Class::Row/;
 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 @@ sub _column_from_storage {
   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);
 }
@@ -74,9 +78,16 @@ sub set_column {
 sub set_filtered_column {
   my ($self, $col, $filtered) = @_;
 
-  $self->set_column($col, $self->_column_to_storage($col, $filtered));
+  # do not blow up the cache via set_column unless necessary
+  # (filtering may be expensive!)
+  if (exists $self->{_filtered_column}{$col}) {
+    return $filtered
+      if ($self->_eq_column_values ($col, $filtered, $self->{_filtered_column}{$col} ) );
 
-  delete $self->{_filtered_column}{$col};
+    $self->make_column_dirty ($col); # so the comparison won't run again
+  }
+
+  $self->set_column($col, $self->_column_to_storage($col, $filtered));
 
   return $filtered;
 }
@@ -163,11 +174,3 @@ Returns the filtered value of the column
  $obj->set_filtered_column(colname => 'new_value')
 
 Sets the filtered value of the column
-
-=head2 update
-
-Just overridden to filter changed columns through this component
-
-=head2 new
-
-Just overridden to filter columns through this component