[Jifty-commit] r4991 - in jifty/trunk: . lib/Jifty lib/Jifty/View/Declare lib/Jifty/View/Mason

Jifty commits jifty-commit at lists.jifty.org
Mon Feb 4 16:13:34 EST 2008


Author: alexmv
Date: Mon Feb  4 16:13:20 2008
New Revision: 4991

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/META.yml
   jifty/trunk/lib/Jifty/Dispatcher.pm
   jifty/trunk/lib/Jifty/Request.pm
   jifty/trunk/lib/Jifty/View/Declare/Handler.pm
   jifty/trunk/lib/Jifty/View/Declare/Helpers.pm
   jifty/trunk/lib/Jifty/View/Mason/Handler.pm
   jifty/trunk/t/03-form-protocol.t

Log:
 r27443 at zoq-fot-pik:  chmrr | 2008-02-04 16:10:36 -0500
 THE FOLLOWING CHANGE BREAKS BACK COMPATABILITY:
 
  * 'set' in T::D templates and the dispatcher no longer alters the
    values in the request itself.  It alters values that are not stored
    if the request is saved as a continuation.  This saves us from
    contiuation bloat due to objects getting stored in the
    continuation.  This does not lose us much, because any arguments
    set via 'set' will get a chance to be set again when the
    continuation is called.
 
    Due to the implementation, however, 'set' cannot be used any more
    to alter or add actions, state variables, or the like.  Some might
    view this new restriction as a feature, though, given how much of a
    kludge it felt like before.


Modified: jifty/trunk/META.yml
==============================================================================
--- jifty/trunk/META.yml	(original)
+++ jifty/trunk/META.yml	Mon Feb  4 16:13:20 2008
@@ -137,6 +137,7 @@
   Test::WWW::Selenium: 0
   UNIVERSAL::require: 0
   URI: 1.31
+  URI::Escape: 0
   WWW::Mechanize: 1.3
   XML::Simple: 0
   XML::Writer: 0.601

Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm	(original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm	Mon Feb  4 16:13:20 2008
@@ -296,7 +296,7 @@
 sub default ($$@) { _ret @_ }    # set parameter if it's not yet set
 sub set ($$@)     { _ret @_ }    # set parameter
 sub del ($@)      { _ret @_ }    # remove parameter
-sub get ($) { request->argument( $_[0] ) }
+sub get ($) { request->template_argument( $_[0] ) || request->argument( $_[0] ) }
 
 sub _qualify ($@);
 sub GET ($)     { _qualify method => @_ }
@@ -800,7 +800,7 @@
 sub _do_set {
     my ( $self, $key, $value ) = @_;
     $self->log->debug("Setting argument $key to ".($value||''));
-    request->argument($key, $value);
+    request->template_argument($key, $value);
 }
 
 sub _do_del {
@@ -812,8 +812,8 @@
 sub _do_default {
     my ( $self, $key, $value ) = @_;
     $self->log->debug("Setting argument default $key to ".($value||''));
-    request->argument($key, $value)
-        unless defined request->argument($key);
+    request->template_argument($key, $value)
+        unless defined request->argument($key) or defined request->template_argument($key);
 }
 
 =head2 _do_dispatch [PATH]

Modified: jifty/trunk/lib/Jifty/Request.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Request.pm	(original)
+++ jifty/trunk/lib/Jifty/Request.pm	Mon Feb  4 16:13:20 2008
@@ -4,7 +4,7 @@
 package Jifty::Request;
 
 use base qw/Jifty::Object Class::Accessor::Fast/;
-__PACKAGE__->mk_accessors(qw(_top_request arguments just_validating path continuation_id continuation_type continuation_path));
+__PACKAGE__->mk_accessors(qw(_top_request arguments template_arguments just_validating path continuation_id continuation_type continuation_path));
 
 use Jifty::JSON;
 use Jifty::YAML;
@@ -80,6 +80,7 @@
     $self->{'state_variables'} = {};
     $self->{'fragments'} = {};
     $self->arguments({});
+    $self->template_arguments({});
 
     my %args = @_;
     for (keys %args) {
@@ -359,6 +360,27 @@
     $val;
 }
 
+=head2 template_argument KEY [=> VALUE]
+
+Sets an argument for the current template.  Template arguments, unlike
+values set via L</argument>, B<cannot> add actions, change action
+argument, or change state variables.  They are also not stored in
+continuations.
+
+=cut
+
+sub template_argument {
+    my $self = shift;
+
+    my $key = shift;
+    if (@_) {
+        my $value = shift;
+        $self->template_arguments->{$key} = $value;
+    }
+    defined(my $val = $self->template_arguments->{$key}) or return undef;
+    $val;
+}
+
 =head2 delete KEY
 
 Removes the argument supplied -- this is the opposite of L</argument>,
@@ -370,6 +392,10 @@
     my $self = shift;
 
     my $key = shift;
+    if (exists $self->template_arguments->{$key}) {
+        delete $self->template_arguments->{$key};
+        return;
+    }
     delete $self->arguments->{$key};
     if ($key =~ /^J:A-(?:(\d+)-)?(.+)/s) {
         $self->remove_action($2);
@@ -532,6 +558,10 @@
     # continuation" into the continuation!
     $self->continuation_path(undef);
 
+    # Clear out the (locally-set) template arguments, which would
+    # bloat the continuation, and can be entirely re-generated.
+    $self->template_arguments({});
+
     my $c = Jifty::Continuation->new(
         request  => $self,
         response => Jifty->web->response,

Modified: jifty/trunk/lib/Jifty/View/Declare/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Declare/Handler.pm	(original)
+++ jifty/trunk/lib/Jifty/View/Declare/Handler.pm	Mon Feb  4 16:13:20 2008
@@ -75,7 +75,7 @@
         goto &Template::Declare::Tags::outs_raw;
     };
     
-    my $content = Template::Declare::Tags::show_page( $template, Jifty->web->request->arguments );
+    my $content = Template::Declare::Tags::show_page( $template, { %{Jifty->web->request->template_arguments}, %{Jifty->web->request->arguments} } );
     return unless defined $content;
 
     my $r = Jifty->handler->apache;

Modified: jifty/trunk/lib/Jifty/View/Declare/Helpers.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Declare/Helpers.pm	(original)
+++ jifty/trunk/lib/Jifty/View/Declare/Helpers.pm	Mon Feb  4 16:13:20 2008
@@ -234,9 +234,9 @@
 
 sub get {
     if (wantarray) {
-        map { request->argument($_) } @_;
+        map { request->template_argument($_) || request->argument($_) } @_;
     } else {
-        request->argument( $_[0] );
+        request->template_argument($_[0]) || request->argument( $_[0] );
     }
 }
 
@@ -251,7 +251,7 @@
 
 sub set {
     while ( my ( $arg, $val ) = splice(@_, 0, 2) ) {
-        request->argument( $arg => $val );
+        request->template_argument( $arg => $val );
     }
 
 }

Modified: jifty/trunk/lib/Jifty/View/Mason/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Mason/Handler.pm	(original)
+++ jifty/trunk/lib/Jifty/View/Mason/Handler.pm	Mon Feb  4 16:13:20 2008
@@ -231,7 +231,7 @@
 =cut
 
 sub request_args {
-    return %{Jifty->web->request->arguments};
+    return %{Jifty->web->request->template_arguments}, %{Jifty->web->request->arguments};
 }
 
 ###########################################################

Modified: jifty/trunk/t/03-form-protocol.t
==============================================================================
--- jifty/trunk/t/03-form-protocol.t	(original)
+++ jifty/trunk/t/03-form-protocol.t	Mon Feb  4 16:13:20 2008
@@ -26,6 +26,7 @@
   J:A:F-id-mymoniker: 23
   J:A:F-something-mymoniker: else
   J:ACTIONS: mymoniker
+template_arguments: {}
 fragments: {}
 === two actions
 --- form
@@ -64,6 +65,7 @@
   J:A:F-id-second: 42
   J:A:F-something-second: bla
   J:ACTIONS: mymoniker!second
+template_arguments: {}
 fragments: {}
 === two different actions
 --- form
@@ -102,6 +104,7 @@
   J:A:F-id-second: 42
   J:A:F-something-second: bla
   J:ACTIONS: mymoniker!second
+template_arguments: {}
 fragments: {}
 === ignore arguments without actions
 --- form
@@ -130,6 +133,7 @@
   J:A:F-id-second: 42
   J:A:F-something-second: bla
   J:ACTIONS: mymoniker!second
+template_arguments: {}
 fragments: {}
 === one active, one inactive action
 --- form
@@ -168,6 +172,7 @@
   J:A:F-id-second: 42
   J:A:F-something-second: bla
   J:ACTIONS: second
+template_arguments: {}
 fragments: {}
 === two actions, no J:ACTIONS
 --- form
@@ -204,6 +209,7 @@
   J:A-second: DoThat
   J:A:F-id-second: 42
   J:A:F-something-second: bla
+template_arguments: {}
 fragments: {}
 === ignore totally random stuff
 --- form
@@ -248,6 +254,7 @@
   J:A-second: DoThat
   J:A:F-id-second: 42
   J:A:F-something-second: bla
+template_arguments: {}
 fragments: {}
 === order doesn't matter
 --- form
@@ -284,6 +291,7 @@
   J:A-second: DoThat
   J:A:F-something-mymoniker: else
   J:A-mymoniker: DoSomething
+template_arguments: {}
 fragments: {}
 === fallbacks being ignored
 --- form
@@ -310,6 +318,7 @@
   J:A:F:F-id-mymoniker: 96
   J:A:F-something-mymoniker: else
   J:ACTIONS: mymoniker
+template_arguments: {}
 fragments: {}
 === fallbacks being ignored (other order)
 --- form
@@ -336,6 +345,7 @@
   J:A:F-id-mymoniker: 23
   J:A:F-something-mymoniker: else
   J:ACTIONS: mymoniker
+template_arguments: {}
 fragments: {}
 === fallbacks being used
 --- form
@@ -360,6 +370,7 @@
   J:A:F:F-id-mymoniker: 96
   J:A:F-something-mymoniker: else
   J:ACTIONS: mymoniker
+template_arguments: {}
 fragments: {}
 === two different actions, one with fallback, one without
 --- form
@@ -400,6 +411,7 @@
   J:A:F-id-second: 42
   J:A:F-something-second: feepy
   J:ACTIONS: mymoniker!second
+template_arguments: {}
 fragments: {}
 === just validating
 ---- form
@@ -441,4 +453,5 @@
   J:A:F-id-second: 42
   J:A:F-something-second: bla
   J:ACTIONS: mymoniker!second
+template_arguments: {}
 fragments: {}


More information about the Jifty-commit mailing list