[Jifty-commit] r5623 - in jifty/trunk: lib/Jifty

Jifty commits jifty-commit at lists.jifty.org
Thu Jul 31 16:52:34 EDT 2008


Author: sartak
Date: Thu Jul 31 16:52:34 2008
New Revision: 5623

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Action.pm

Log:
 r68184 at onn:  sartak | 2008-07-31 16:49:59 -0400
 Extract the validation of valid_values into a method which is overridable


Modified: jifty/trunk/lib/Jifty/Action.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action.pm	(original)
+++ jifty/trunk/lib/Jifty/Action.pm	Thu Jul 31 16:52:34 2008
@@ -950,17 +950,8 @@
     }
 
     # If we have a set of allowed values, let's check that out.
-    # XXX TODO this should be a validate_valid_values sub
     if ( $value && $field_info->{valid_values} ) {
-
-        # If you're not on the list, you can't come to the party
-        unless ( grep {defined $_->{'value'} and $_->{'value'} eq $value}
-            @{ $self->valid_values($field) } ) {
-
-            return $self->validation_error(
-                $field => _("That doesn't look like a correct value") );
-        }
-
+        $self->_validate_valid_values($field => $value);
    # ... but still check through a validator function even if it's in the list
     }
 
@@ -1052,6 +1043,22 @@
     $self->_values_for_field( $field => 'valid' );
 }
 
+sub _validate_valid_values {
+    my $self  = shift;
+    my $field = shift;
+    my $value = shift;
+
+    # If you're not on the list, you can't come to the party
+    unless ( grep {defined $_->{'value'} and $_->{'value'} eq $value}
+        @{ $self->valid_values($field) } ) {
+
+        return $self->validation_error(
+            $field => _("That doesn't look like a correct value") );
+    }
+
+    return 1;
+}
+
 =head2 available_values ARGUMENT
 
 Just like L<valid_values>, but if our action has a set of available


More information about the Jifty-commit mailing list