[Rt-commit] r3859 - in Jifty-DBI/trunk: . lib/Jifty/DBI lib/Jifty/DBI/Filter

jesse at bestpractical.com jesse at bestpractical.com
Sat Sep 17 15:41:03 EDT 2005


Author: jesse
Date: Sat Sep 17 15:41:02 2005
New Revision: 3859

Added:
   Jifty-DBI/trunk/lib/Jifty/DBI/Filter/
   Jifty-DBI/trunk/lib/Jifty/DBI/Filter.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Filter/DateTime.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Filter/JiftyRecord.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Filter/base64.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Filter/utf8.pm
Modified:
   Jifty-DBI/trunk/   (props changed)
   Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm
Log:
 r15790 at hualien:  jesse | 2005-09-17 15:40:34 -0400
 * First pass of filters API. Not hooked up yet.
 


Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm	Sat Sep 17 15:41:02 2005
@@ -5,13 +5,20 @@
 
 use base qw/Class::Accessor/;
 
-__PACKAGE__->mk_accessors qw/name type default validator 
+__PACKAGE__->mk_accessors qw/
+    name 
+    type 
+    default 
+    validator 
     boolean 
     readable writable 
     length 
     refers_to_collection_class
     refers_to_record_class
     alias_for_column 
+    filters
+    input_filters
+    output_filters
     /;
 
 =head1 NAME
@@ -49,4 +56,43 @@
 *read = \&readable;
 *write = \&writable;
 
+
+sub decode_value {
+    my $self = shift;
+    my $value_ref = shift;
+    $self->_apply_filters( value_ref => $value_ref, 
+                           filters  => (reverse $self->filters, $self->output_filters),
+                           action => 'decode'
+                        );
+}
+
+
+sub encode_value {
+    my $self = shift;
+    my $value_ref = shift;
+    $self->_apply_filters( value_ref => $value_ref, 
+                           filters  => ($self->input_filters, $self->filters),
+                           action => 'encode'
+                        );
+}
+
+
+sub _apply_filters {
+    my $self = shift;
+    my %args = (
+        value_ref => undef,
+        filters   => undef,
+        action    => undef,
+        @_
+    );
+    my $action = $args{'action'};
+    foreach my $filter_class ( @{ $args{filters} } ) {
+        $filter_class->require();
+
+        # XXX TODO error proof this
+        $filter_class->$action( $args{value_ref} );
+    }
+}
+
+
 1;

Added: Jifty-DBI/trunk/lib/Jifty/DBI/Filter.pm
==============================================================================
--- (empty file)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Filter.pm	Sat Sep 17 15:41:02 2005
@@ -0,0 +1,84 @@
+use warnings;
+use strict;
+
+package Jifty::DBI::Filter;
+
+
+sub new {
+    my $class = shift;
+    my $self = {};
+    bless $self, $class;
+    return ($self);
+
+}
+
+=head2 encode
+
+C<encode> takes data that users are handing to us and marshals it into
+a form suitable for sticking it in the database. This could be anything
+from flattening a L<DateTime> object into an ISO date to making sure
+that data is utf8 clean.
+
+
+C<encode> takes two named parameters:
+
+=over
+
+=item value_ref
+
+A reference to the current value you're going to be massaging. C<encode> works in place, massaging whatever value_ref refers to.
+
+=item column
+
+A L<Jifty::DBI::Column> object, whatever sort of column we're working with here.
+
+=back
+
+
+
+=cut
+
+
+sub encode {
+    my $self = shift;
+    my %args = ( value_ref => undef,
+                 column => undef,
+                 @_);
+
+}
+
+=head2 decode
+
+C<decode> takes data that the database is handing back to us and gets it into a form that's OK to hand back to the user. This could be anything
+from flattening a L<DateTime> object into an ISO date to making sure
+that data is utf8 clean.
+
+
+C<decode> takes two named parameters:
+
+=over
+
+=item value_ref
+
+A reference to the current value you're going to be massaging. C<decode> works in place, massaging whatever value_ref refers to.
+
+=item column
+
+A L<Jifty::DBI::Column> object, whatever sort of column we're working with here.
+
+=back
+
+
+
+=cut
+
+sub decode {
+    my $self = shfit;
+    my %args = ( value_ref => undef,
+                 column => undef,
+                 @_);
+
+}
+
+
+1;

Added: Jifty-DBI/trunk/lib/Jifty/DBI/Filter/DateTime.pm
==============================================================================

Added: Jifty-DBI/trunk/lib/Jifty/DBI/Filter/JiftyRecord.pm
==============================================================================

Added: Jifty-DBI/trunk/lib/Jifty/DBI/Filter/base64.pm
==============================================================================

Added: Jifty-DBI/trunk/lib/Jifty/DBI/Filter/utf8.pm
==============================================================================


More information about the Rt-commit mailing list