[Jifty-commit] r7687 - in jifty/trunk/lib/Jifty: Action/Record

Jifty commits jifty-commit at lists.jifty.org
Wed Dec 2 06:10:46 EST 2009


Author: sartak
Date: Wed Dec  2 06:10:45 2009
New Revision: 7687

Modified:
   jifty/trunk/lib/Jifty/Action.pm
   jifty/trunk/lib/Jifty/Action/Record/Create.pm
   jifty/trunk/lib/Jifty/Action/Record/Update.pm

Log:
Allow actions to pass extra validator args

Modified: jifty/trunk/lib/Jifty/Action.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action.pm	(original)
+++ jifty/trunk/lib/Jifty/Action.pm	Wed Dec  2 06:10:45 2009
@@ -961,12 +961,12 @@
     if ( $field_info->{validator}
         and defined &{ $field_info->{validator} } )
     {
-        return $field_info->{validator}->( $self, $value, $self->argument_values );
+        return $field_info->{validator}->( $self, $value, $self->argument_values, $self->_extra_validator_args );
     }
 
     # Check to see if it's the validate_$field method instead and use that
     elsif ( $self->can($default_validator) ) {
-        return $self->$default_validator( $value, $self->argument_values );
+        return $self->$default_validator( $value, $self->argument_values, $self->_extra_validator_args );
     }
 
     # Check if we already have a failure for it, from some other field
@@ -980,6 +980,17 @@
     }
 }
 
+=head2 _extra_validator_args
+
+Returns a list of extra arguments to pass to validators. By default, an empty
+hash reference, but subclasses can override it to pass, say, a better C<for>.
+
+=cut
+
+sub _extra_validator_args {
+    return {};
+}
+
 =head2 _autocomplete_argument ARGUMENT
 
 Get back a list of possible completions for C<ARGUMENT>.  The list

Modified: jifty/trunk/lib/Jifty/Action/Record/Create.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record/Create.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record/Create.pm	Wed Dec  2 06:10:45 2009
@@ -150,6 +150,16 @@
     return grep {not $_->protected} $self->SUPER::possible_columns( @_ );
 }
 
+=head2 _extra_validator_args
+
+Passes C<< for => 'create' >> to validators.
+
+=cut
+
+sub _extra_validator_args {
+    return { for => 'create' };
+}
+
 =head1 SEE ALSO
 
 L<Jifty::Action::Record>, L<Jifty::Record>

Modified: jifty/trunk/lib/Jifty/Action/Record/Update.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record/Update.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record/Update.pm	Wed Dec  2 06:10:45 2009
@@ -227,6 +227,16 @@
     return grep { not $_->protected } $self->SUPER::possible_columns;
 }
 
+=head2 _extra_validator_args
+
+Passes C<< for => 'update' >> to validators.
+
+=cut
+
+sub _extra_validator_args {
+    return { for => 'update' };
+}
+
 =head1 SEE ALSO
 
 L<Jifty::Action::Record>, L<Jifty::Record>


More information about the Jifty-commit mailing list