[Jifty-commit] r4638 - in jifty/trunk: lib/Jifty/Action lib/Jifty/Web/Form

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Dec 7 13:53:18 EST 2007


Author: jesse
Date: Fri Dec  7 13:53:15 2007
New Revision: 4638

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Action/Record.pm
   jifty/trunk/lib/Jifty/Web/Form/Field.pm

Log:
 r72791 at pinglin:  jesse | 2007-12-07 13:53:00 -0500
 * Refactoring around the fact that Scalar::Defer::defer'd variables will never return undef until they're forced.


Modified: jifty/trunk/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record.pm	Fri Dec  7 13:53:15 2007
@@ -160,11 +160,14 @@
 
     for my $field (keys %$arguments) {
             # Load the column object and the record's current value
-            next unless my $function = $self->record->can($field);
 
 
 
-            my $current_value = defer {
+            my $current_value;
+            
+            
+            if ( my $function = $self->record->can($field) ) {
+            $current_value = defer {
                 my $val = $function->( $self->record );
 
                 # If the current value is actually a pointer to
@@ -175,10 +178,10 @@
 
                 return $val;
             };
-
+            }
 
             # The record's current value becomes the widget's default value
-            $arguments->{$field}->{default_value} = $current_value if $self->record->id;
+            $arguments->{$field}->{default_value} = $current_value;
 
 
     }

Modified: jifty/trunk/lib/Jifty/Web/Form/Field.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Field.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Form/Field.pm	Fri Dec  7 13:53:15 2007
@@ -45,6 +45,7 @@
 use base 'Jifty::Web::Form::Element';
 
 use Scalar::Util;
+use Scalar::Defer qw/force/;
 use HTML::Entities;
 
 # We need the anonymous sub because otherwise the method of the base class is
@@ -322,7 +323,10 @@
     if ($self->sticky_value and $self->sticky) {
         return $self->sticky_value;
     } else {
-        return $self->default_value;
+        # the force is here because very often this will be a Scalar::Defer object that we REALLY 
+        # want to be able to check definedness on.
+        # Because of a core limitation in perl, Scalar::Defer can't return undef for an object.
+        return force $self->default_value;
     }
 }
 


More information about the Jifty-commit mailing list