[Jifty-commit] r1852 - jifty/trunk/lib/Jifty/Web/Form

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Aug 23 21:41:47 EDT 2006


Author: nelhage
Date: Wed Aug 23 21:41:46 2006
New Revision: 1852

Modified:
   jifty/trunk/lib/Jifty/Web/Form/Clickable.pm
   jifty/trunk/lib/Jifty/Web/Form/Element.pm

Log:
More thorough normalization of the submit parameter to Javascript
handlers

Modified: jifty/trunk/lib/Jifty/Web/Form/Clickable.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Clickable.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Form/Clickable.pm	Wed Aug 23 21:41:46 2006
@@ -541,8 +541,7 @@
             if ( $hook->{submit} ) {
                 $self->{submit} ||= [];
                 $hook->{submit} = [ $hook->{submit} ] unless ref $hook->{submit} eq "ARRAY";
-                push @{ $self->{submit} },
-                    map { ref $_ ? $_->moniker : $_ } @{ $hook->{submit} };
+                push @{ $self->{submit} }, @{ $hook->{submit} };
             }
         }
     }

Modified: jifty/trunk/lib/Jifty/Web/Form/Element.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Element.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Form/Element.pm	Wed Aug 23 21:41:46 2006
@@ -148,13 +148,16 @@
 
     my ($arg) = @_;
 
-    if (ref($arg) eq 'ARRAY') {
-	for (@$arg) {
-	    $_->{submit} = $_->{submit}->moniker
-		if UNIVERSAL::can($_->{submit}, 'moniker');
-	}
+    # Normalize actions to monikers to prevent circular references,
+    # since Jifty::Action caches instances of Jifty::Web::Form::Clickable.
+    for my $hook ( ref($arg) eq 'ARRAY' ? @$arg : $arg ) {
+        next unless ref $hook eq 'HASH';
+        next unless $hook->{submit};
+        $hook->{submit} = [ $hook->{submit} ] unless ref $hook->{submit} eq "ARRAY";
+        $hook->{submit} = [ map { ref $_ ? $_->moniker : $_ } @{ $hook->{submit} } ];
     }
 
+
     $self->_onclick($arg);
 }
 
@@ -182,8 +185,7 @@
 
             # Submit action
             if ( $hook->{submit} ) {
-                $hook->{submit} = [ $hook->{submit} ] unless ref $hook->{submit} eq "ARRAY";
-                push @actions, map { ref $_ ? $_->moniker : $_ } @{ $hook->{submit} };
+                push @actions, @{ $hook->{submit} };
             }
 
             $hook->{region} ||= Jifty->web->qualified_region;


More information about the Jifty-commit mailing list