[Jifty-commit] r2892 - in jifty/branches/template-declare: .
lib/Jifty/Action
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sat Mar 3 12:55:58 EST 2007
Author: jesse
Date: Sat Mar 3 12:55:58 2007
New Revision: 2892
Modified:
jifty/branches/template-declare/ (props changed)
jifty/branches/template-declare/lib/Jifty/Action/Record.pm
jifty/branches/template-declare/lib/Jifty/Record.pm
Log:
r52894 at pinglin: jesse | 2007-03-02 18:56:54 +0000
* work on extracting canonicalization and validation so they can get called back
Modified: jifty/branches/template-declare/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/branches/template-declare/lib/Jifty/Action/Record.pm (original)
+++ jifty/branches/template-declare/lib/Jifty/Action/Record.pm Sat Mar 3 12:55:58 2007
@@ -291,12 +291,11 @@
};
}
- my $canonicalize_method = "canonicalize_" . $field;
- if ( $self->record->can($canonicalize_method) ) {
+ if ( $self->record->has_canonicalizer_for_column($field) ) {
$info->{'ajax_canonicalizes'} = 1;
$info->{'canonicalizer'} ||= sub {
my ( $self, $value ) = @_;
- return $self->record->$canonicalize_method($value);
+ return $self->record->run_canonicalization_for_column(column => $field, value => $value);
};
} elsif ( $render_as eq 'date')
{
Modified: jifty/branches/template-declare/lib/Jifty/Record.pm
==============================================================================
--- jifty/branches/template-declare/lib/Jifty/Record.pm (original)
+++ jifty/branches/template-declare/lib/Jifty/Record.pm Sat Mar 3 12:55:58 2007
@@ -54,10 +54,10 @@
=cut
sub create {
- my $class = shift;
+ my $class = shift;
my $self;
- if (ref($class)) {
- ($self,$class) = ($class,undef);
+ if ( ref($class) ) {
+ ( $self, $class ) = ( $class, undef );
} else {
$self = $class->new();
}
@@ -71,47 +71,49 @@
}
foreach my $key ( keys %attribs ) {
- my $attr = $attribs{$key};
- my $method = "canonicalize_$key";
- my $func = $self->can($method) or next;
- $attribs{$key} = $self->$func( $attr);
+ $attribs{$key} = $self->run_canonicalization_for_column(
+ column => $key,
+ value => $attribs{$key}
+ );
}
foreach my $key ( keys %attribs ) {
my $attr = $attribs{$key};
- my $method = "validate_$key";
- if (my $func = $self->can($method)) {
- my ( $val, $msg ) = $func->($self, $attr);
- unless ($val) {
+ my ( $val, $msg ) = $self->run_validation_for_column(
+ column => $key,
+ value => $attribs{$key}
+ );
+ if ( not $val ) {
$self->log->error("There was a validation error for $key");
if ($class) {
- return($self);
+ return ($self);
} else {
return ( $val, $msg );
}
}
- }
+
# remove blank values. We'd rather have nulls
- if ( exists $attribs{$key} and (! defined $attr || ( not ref( $attr) and $attr eq '' ))) {
+ if ( exists $attribs{$key}
+ and ( !defined $attr || ( not ref($attr) and $attr eq '' ) ) )
+ {
delete $attribs{$key};
}
}
-
my $msg = $self->SUPER::create(%attribs);
- if (ref($msg) ) {
+ if ( ref($msg) ) {
+
# It's a Class::ReturnValue
- return $msg ;
+ return $msg;
}
- my ($id, $status) = $msg;
+ my ( $id, $status ) = $msg;
$self->load_by_cols( id => $id ) if ($id);
if ($class) {
return $self;
} else {
- return wantarray ? ($id, $status) : $id;
+ return wantarray ? ( $id, $status ) : $id;
}
}
-
=head2 id
Returns the record id value.
@@ -230,8 +232,7 @@
Internal helper to call L</current_user_can> with C<read>.
-Passes C<column> as a named parameter for the column the user is checking rights
-on.
+Passes C<column> as a named parameter for the column the user is checking rights on.
=cut
More information about the Jifty-commit
mailing list