[Jifty-commit] r526 - in jifty/trunk: . inc/Module lib/Jifty lib/Jifty/Web/Form t/Mapper/lib/Mapper/Action t/Mapper/t t/Mapper/web/templates

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Jan 24 21:08:29 EST 2006


Author: alexmv
Date: Tue Jan 24 21:08:28 2006
New Revision: 526

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/inc/Module/Install.pm
   jifty/trunk/lib/Jifty/Record.pm
   jifty/trunk/lib/Jifty/Request/Mapper.pm
   jifty/trunk/lib/Jifty/Web.pm
   jifty/trunk/lib/Jifty/Web/Form/Field.pm
   jifty/trunk/t/Mapper/lib/Mapper/Action/CrossBridge.pm
   jifty/trunk/t/Mapper/t/02-api.t
   jifty/trunk/t/Mapper/web/templates/index.html

Log:
 r8777 at zoq-fot-pik:  chmrr | 2006-01-24 21:07:50 -0500
  * Mapping of arguments of actions


Modified: jifty/trunk/inc/Module/Install.pm
==============================================================================
--- jifty/trunk/inc/Module/Install.pm	(original)
+++ jifty/trunk/inc/Module/Install.pm	Tue Jan 24 21:08:28 2006
@@ -1,4 +1,4 @@
-#line 1 "/home/chmrr/work/rt/local/jifty/inc/Module/Install.pm - /usr/lib/perl5/site_perl/5.8.7/Module/Install.pm"
+#line 1 "/home/chmrr/work/rt/local/jifty-trunk/inc/Module/Install.pm - /usr/lib/perl5/site_perl/5.8.7/Module/Install.pm"
 package Module::Install;
 
 use 5.004;

Modified: jifty/trunk/lib/Jifty/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Record.pm	Tue Jan 24 21:08:28 2006
@@ -218,7 +218,7 @@
         return (undef);
     }
     my $value = $self->SUPER::_value(@_);
-    utf8::upgrade($value);
+    utf8::upgrade($value) if defined $value;
     $value;
 }
 

Modified: jifty/trunk/lib/Jifty/Request/Mapper.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Request/Mapper.pm	(original)
+++ jifty/trunk/lib/Jifty/Request/Mapper.pm	Tue Jan 24 21:08:28 2006
@@ -144,16 +144,14 @@
     my @bits = split( /\|/, $args{source} );
     if ( $bits[0] ) {
         if ( $bits[0] eq "A" and @bits == 3 ) {
-            return ( $destination => $args{request}->action( $bits[1] )
-                ? $args{request}->action( $bits[1] )->argument( $bits[2] )
-                : undef );
-        } elsif ( $bits[0] eq "R" and @bits == 3 ) {
-            return ( $destination => $args{response}->result( $bits[1] )
-                ? $args{response}->result( $bits[1] )->content( $bits[2] )
-                : undef );
+            return ( $destination => undef ) unless $args{request}->action( $bits[1] );
+            return ( $destination => $args{request}->action( $bits[1] )->argument( $bits[2] ) );
+        } elsif ( $bits[0] eq "R" and @bits == 3 ) { 
+            return ( $destination => undef ) unless $args{request}->action( $bits[1] );
+            return ( $args{destination} => $args{source} ) unless $args{response}->result( $bits[1] );
+            return ( $destination => $args{response}->result( $bits[1] )->content( $bits[2] ) );
         } elsif ( $bits[0] eq "A" and @bits == 2 ) {
-            return (
-                $destination => $args{request}->arguments->{ $bits[1] } );
+            return ( $destination => $args{request}->arguments->{ $bits[1] } );
         }
     }
     return ( $destination => $args{source} );

Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm	(original)
+++ jifty/trunk/lib/Jifty/Web.pm	Tue Jan 24 21:08:28 2006
@@ -243,24 +243,39 @@
             next;
         }
 
+        # Make sure we can instantiate the action
         my $action = $self->new_action_from_request($request_action);
         next unless $action;
+
+        # Try validating -- note that this is just the first pass; as
+        # actions are run, they may fill in values which alter
+        # validation of later actions
         $self->response->result( $action->moniker => $action->result );
+        $action->validate;
 
-        eval { push @valid_actions, $action if $action->validate; };
-        if ( my $err = $@ ) {
-            $self->log->fatal($err);
-        }
+        push @valid_actions, $request_action;
     }
     $self->save_continuation;
 
     unless ( $self->request->just_validating ) {
-        for my $action (@valid_actions) {
-            eval { $action->run; };
+        for my $request_action (@valid_actions) {
 
+            # Pull the action out of the request (again, since
+            # mappings may have affected parameters)
+            my $action = $self->new_action_from_request($request_action);
+            next unless $action;
+
+            # Try validating again
+            $action->result(Jifty::Result->new);
+            $self->response->result( $action->moniker => $action->result );
+            eval { $action->run if $action->validate; };
             if ( my $err = $@ ) {
                 $self->log->fatal($err);
             }
+
+            # Fill in the request with any results that that action
+            # may have yielded.
+            $self->request->do_mapping;
         }
     }
     $self->session->set_cookie();

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	Tue Jan 24 21:08:28 2006
@@ -84,6 +84,15 @@
         $self->$field( $args{$field} ) if exists $args{$field};
     }
 
+    # If they key and/or value imply that this argument is going to be
+    # a mapped argument, then do the mapping and mark the field as hidden.
+    my ($key, $value) = Jifty::Request::Mapper->query_parameters($self->input_name, $self->default_value);
+    if ($key ne $self->input_name) {
+        require Jifty::Web::Form::Field::Hidden;
+        bless $self, "Jifty::Web::Form::Field::Hidden";
+        $self->input_name($key);
+        $self->default_value($value);
+    }
 
     # now that the form field has been instantiated, register the action with the form.
     if ($self->action and not (Jifty->web->form->has_action($self->action))) {

Modified: jifty/trunk/t/Mapper/lib/Mapper/Action/CrossBridge.pm
==============================================================================
--- jifty/trunk/t/Mapper/lib/Mapper/Action/CrossBridge.pm	(original)
+++ jifty/trunk/t/Mapper/lib/Mapper/Action/CrossBridge.pm	Tue Jan 24 21:08:28 2006
@@ -13,8 +13,8 @@
 sub validate_quest {
     my $self = shift;
     my $value = shift || '';
-    if ($value !~ /grail/i) {
-        return $self->validation_error( quest => "Something about the grail" );
+    if ($value !~ /grail|Aaaaaargh/i) {
+        return $self->validation_error( quest => "Something about the grail or castle aaargh" );
     }
     return $self->validation_ok( 'quest' );
 }

Modified: jifty/trunk/t/Mapper/t/02-api.t
==============================================================================
--- jifty/trunk/t/Mapper/t/02-api.t	(original)
+++ jifty/trunk/t/Mapper/t/02-api.t	Tue Jan 24 21:08:28 2006
@@ -11,7 +11,7 @@
 
 BEGIN {chdir "t/Mapper"}
 use lib '../../lib';
-use Jifty::Test no_plan => 1;
+use Jifty::Test tests => 8;
 
 use_ok('Jifty::Test::WWW::Mechanize');
 
@@ -29,6 +29,11 @@
 $mech->get("$URL/index.html?J:A-grail=GetGrail");
 $mech->content_like(qr/got the grail/, "Running the action produces the expected result");
 
+# Feeding the first action into the second should cause both to run
+$mech->form(2);
+ok($mech->click_button(value => "Do both"));
+$mech->content_like(qr/got the grail/i, "Got the grail");
+$mech->content_like(qr/crossed the bridge/i, "And crossed the bridge");
 
 
 1;

Modified: jifty/trunk/t/Mapper/web/templates/index.html
==============================================================================
--- jifty/trunk/t/Mapper/web/templates/index.html	(original)
+++ jifty/trunk/t/Mapper/web/templates/index.html	Tue Jan 24 21:08:28 2006
@@ -5,3 +5,12 @@
 <% Jifty->web->form->submit( label => 'Get the holy grail') %>
 
 <% Jifty->web->form->end %>
+
+
+<% Jifty->web->form->start %>
+% my $grail  = Jifty->web->form->add_action( class => 'GetGrail',    order => 1 );
+% my $bridge = Jifty->web->new_action( class => 'CrossBridge', order => 2 );
+<% $bridge->form_field( 'quest',  default_value => { result_of => $grail, name => 'castle' } ) %>
+<% $bridge->form_field( 'colour', default_value => 'Green' ) %>
+<% Jifty->web->form->submit( label => 'Do both') %>
+<% Jifty->web->form->end %>


More information about the Jifty-commit mailing list