[Jifty-commit] r1303 - in Jifty-DBI/trunk: lib/Jifty/DBI
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Jun 15 15:13:00 EDT 2006
Author: alexmv
Date: Thu Jun 15 15:12:55 2006
New Revision: 1303
Modified:
Jifty-DBI/trunk/ (props changed)
Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
Log:
r13979 at zoq-fot-pik: chmrr | 2006-06-15 16:00:18 -0400
* Only set a validator if we are actually doing something
* warn -> carp
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm Thu Jun 15 15:12:55 2006
@@ -258,12 +258,8 @@
*{ $package . "::" . "set_" . $column_name } = $subref;
}
- if ( not $column->validator and not $self->can( "validate_" . $column_name ) ) {
- # Validator
- *{ $package . "::" . "validate_" . $column_name }
- = sub { return ( $_[0]->_validate( $column_name, $_[1] ) ) };
- }
- $column->validator( $self->can( "validate_" . $column_name ) ) unless $column->validator;
+ $column->validator( $self->can( "validate_" . $column_name ) )
+ if not $column->validator and $self->can("validate_" . $column_name );
}
@@ -602,17 +598,19 @@
}
}
- my $method = "validate_" . $column->name;
- my ( $ok, $msg ) = $self->$method( $args{'value'} );
- unless ($ok) {
- $ret->as_array( 0, 'Illegal value for ' . $column->name );
- $ret->as_error(
- errno => 3,
- do_backtrace => 0,
- message => "Illegal value for " . $column->name
- );
- return ( $ret->return_value );
+ if ( my $sub = $column->validator ) {
+ my ( $ok, $msg ) = $sub->( $self, $args{'value'} );
+ unless ($ok) {
+ $ret->as_array( 0, 'Illegal value for ' . $column->name );
+ $ret->as_error(
+ errno => 3,
+ do_backtrace => 0,
+ message => "Illegal value for " . $column->name
+ );
+ return ( $ret->return_value );
+ }
}
+
# Implement 'is distinct' checking
if ( $column->distinct ) {
@@ -663,32 +661,6 @@
return ( $ret->return_value );
}
-=head2 _validate column VALUE
-
-Validate that value will be an acceptable value for column.
-
-Currently, this routine does nothing whatsoever.
-
-If it succeeds (which is always the case right now), returns true. Otherwise returns false.
-
-=cut
-
-sub _validate {
- my $self = shift;
- my $column = shift;
- my $value = shift;
-
- #Check type of input
- #If it's null, are nulls permitted?
- #If it's an int, check the # of bits
- #If it's a string,
- #check length
- #check for nonprintables
- #If it's a blob, check for length
- #In an ideal world, if this is a link to another table, check the dependency.
- return (1);
-}
-
=head2 load
Takes a single argument, $id. Calls load_by_cols to retrieve the row whose primary key
@@ -910,7 +882,7 @@
}
if (not defined $attribs{$column->name} and $column->mandatory and $column->type ne "serial" ) {
# Enforce "mandatory"
- warn "Did not supply value for mandatory column ".$column->name;
+ Carp::carp "Did not supply value for mandatory column ".$column->name;
return ( 0 );
}
}
More information about the Jifty-commit
mailing list