[Jifty-commit] r929 - in Jifty-DBI/trunk: lib/Jifty/DBI lib/Jifty/DBI/Filter lib/Jifty/DBI/Record

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Apr 26 01:55:36 EDT 2006


Author: alexmv
Date: Wed Apr 26 01:55:35 2006
New Revision: 929

Added:
   Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Storable.pm
Modified:
   Jifty-DBI/trunk/   (props changed)
   Jifty-DBI/trunk/lib/Jifty/DBI/Filter/base64.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/HasFilters.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Record/Cachable.pm

Log:
 r12624 at zoq-fot-pik:  chmrr | 2006-04-26 01:55:02 -0400
  * Filters and filter fixes


Added: Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Storable.pm
==============================================================================
--- (empty file)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Filter/Storable.pm	Wed Apr 26 01:55:35 2006
@@ -0,0 +1,58 @@
+package Jifty::DBI::Filter::Storable;
+
+use warnings;
+use strict;
+
+use base qw|Jifty::DBI::Filter|;
+use Storable ();
+
+=head1 NAME
+
+Jifty::DBI::Filter::Storable - Encodes arbitrary data using Storable
+
+=head1 DESCRIPTION
+
+This filter allows you to store arbitrary Perl data structures in a
+column of type 'blob', using L<Storable> to serialize them.
+
+=head2 encode
+
+If value is defined, then encodes it using L<Storable/nfreeze>. Does
+nothing if value is not defined.
+
+=cut
+
+sub encode {
+    my $self = shift;
+
+    my $value_ref = $self->value_ref;
+    return unless defined $$value_ref;
+
+    $Storable::Deparse = 1;
+    $$value_ref = Storable::nfreeze($$value_ref);
+}
+
+=head2 decode
+
+If value is defined, then decodes it using L<Storable/thaw>, otherwise
+does nothing.
+
+=cut
+
+sub decode {
+    my $self = shift;
+
+    my $value_ref = $self->value_ref;
+    return unless defined $$value_ref;
+
+    $Storable::Eval = 1;
+    $$value_ref = Storable::thaw($$value_ref);
+}
+
+=head1 SEE ALSO
+
+L<Jifty::DBI::Filter>, L<Storable>
+
+=cut
+
+1;

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Filter/base64.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Filter/base64.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Filter/base64.pm	Wed Apr 26 01:55:35 2006
@@ -0,0 +1,58 @@
+package Jifty::DBI::Filter::base64;
+
+use warnings;
+use strict;
+
+use base qw|Jifty::DBI::Filter|;
+use MIME::Base64 ();
+
+=head1 NAME
+
+Jifty::DBI::Filter::base64 - Encodes data as base64
+
+=head1 DESCRIPTION
+
+This filter allow you to store arbitrary data in a column of type
+'text'.
+
+=head2 encode
+
+If value is defined, then encodes it using
+L<MIME::Base64/encode_base64>. Does nothing if value is not defined.
+
+=cut
+
+sub encode {
+    my $self = shift;
+
+    my $value_ref = $self->value_ref;
+    return unless defined $$value_ref;
+
+    $$value_ref = MIME::Base64::encode_base64($$value_ref);
+
+    return 1;
+}
+
+=head2 decode
+
+If value is defined, then decodes it using
+L<MIME::Base64/decode_base64>, otherwise do nothing.
+
+=cut
+
+sub decode {
+    my $self = shift;
+
+    my $value_ref = $self->value_ref;
+    return unless defined $$value_ref;
+
+    $$value_ref = MIME::Base64::decode_base64($$value_ref);
+}
+
+=head1 SEE ALSO
+
+L<Jifty::DBI::Filter>, L<MIME::Base64>
+
+=cut
+
+1;

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/HasFilters.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/HasFilters.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/HasFilters.pm	Wed Apr 26 01:55:35 2006
@@ -43,10 +43,10 @@
     my $self = shift;
     if (@_) {    # setting
         my @values = map { UNIVERSAL::isa( $_, 'ARRAY' ) ? @$_ : $_ } @_;
-        return $self->_input_filters_accessor(@values);
+        $self->_input_filters_accessor( [@values] );
     }
 
-    return grep $_, $self->_input_filters_accessor;
+    return @{ $self->_input_filters_accessor || [] };
 }
 
 =head2 output_filters
@@ -63,13 +63,14 @@
     my $self = shift;
     if (@_) {    # setting
         my @values = map { UNIVERSAL::isa( $_, 'ARRAY' ) ? @$_ : $_ } @_;
-        $self->_output_filters_accessor(@values);
+        $self->_output_filters_accessor( [@values] );
     }
 
-    my @values = grep $_, $self->_output_filters_accessor;
+    my @values = @{ $self->_output_filters_accessor || [] };
     return @values if @values;
 
-    return reverse $self->input_filters;
+    @values = reverse $self->input_filters;
+    return @values;
 }
 
 =head2 filters FILTERS
@@ -82,9 +83,10 @@
 
 sub filters {
     my $self = shift;
-    return {output => $self->output_filters(@_),
-            input  => $self->input_filters(@_)
-	    };
+    return {
+        output => $self->output_filters(@_),
+        input  => $self->input_filters(@_)
+    };
 }
 
 =head1 SEE ALSO

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Record/Cachable.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Record/Cachable.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Record/Cachable.pm	Wed Apr 26 01:55:35 2006
@@ -211,7 +211,8 @@
     $self->_record_cache->set( $self->_primary_record_cache_key,
         {   values  => $self->{'values'},
             table   => $self->table,
-            fetched => $self->{'fetched'}
+            fetched => $self->{'fetched'},
+            decoded => $self->{'decoded'},
         }
     );
 }


More information about the Jifty-commit mailing list