[Jifty-commit] r1077 - in jifty/trunk: lib/Jifty lib/Jifty/Request
lib/Jifty/Web/Form
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu May 18 13:22:16 EDT 2006
Author: alexmv
Date: Thu May 18 13:22:15 2006
New Revision: 1077
Modified:
jifty/trunk/ (props changed)
jifty/trunk/META.yml
jifty/trunk/lib/Jifty/Request.pm
jifty/trunk/lib/Jifty/Request/Mapper.pm
jifty/trunk/lib/Jifty/Web.pm
jifty/trunk/lib/Jifty/Web/Form/Clickable.pm
jifty/trunk/lib/Jifty/Web/Form/Element.pm
Log:
r13053 at zoq-fot-pik: chmrr | 2006-05-18 13:22:10 -0400
* Region argument mapping fixes
Modified: jifty/trunk/META.yml
==============================================================================
--- jifty/trunk/META.yml (original)
+++ jifty/trunk/META.yml Thu May 18 13:22:15 2006
@@ -40,7 +40,7 @@
Hash::Merge: 0
Hook::LexWrap: 0
JSON::Syck: 0.12
- Jifty::DBI: 0.16
+ Jifty::DBI: 0.21
LWP::UserAgent: 0
Locale::Maketext::Extract: 0.20
Locale::Maketext::Lexicon: 0.60
Modified: jifty/trunk/lib/Jifty/Request.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Request.pm (original)
+++ jifty/trunk/lib/Jifty/Request.pm Thu May 18 13:22:15 2006
@@ -708,13 +708,13 @@
for (keys %{$self->arguments}) {
my ($key, $value) = Jifty::Request::Mapper->map(destination => $_, source => $self->arguments->{$_}, %args);
- next unless $key ne $_;
+ next unless $key ne $_ or not defined $value or $value ne $self->argument($_);
delete $self->arguments->{$_};
$self->argument($key => $value);
}
for ($self->state_variables) {
my ($key, $value) = Jifty::Request::Mapper->map(destination => $_->key, source => $_->value, %args);
- next unless $key ne $_;
+ next unless $key ne $_->key or not defined $value or $value ne $_->value;
$self->remove_state_variable($_->key);
$self->add_state_variable(key => $key, 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 Thu May 18 13:22:15 2006
@@ -136,7 +136,14 @@
@_
);
- return ( $args{destination} => $args{source} )
+ my @original = ($args{destination} => $args{source});
+
+ # In case the source is a harhref, we force ourselves to go the
+ # *other* direction first.
+ ($args{destination}, $args{source}) = $class->query_parameters($args{destination} => $args{source});
+
+ # Bail unless it's a mapping
+ return ( @original )
unless $args{destination} =~ /^J:M-(.*)/;
my $destination = $1;
@@ -144,16 +151,22 @@
my @bits = split( /\`/, $args{source} );
if ( $bits[0] ) {
if ( $bits[0] eq "A" and @bits == 3 ) {
- return ( $destination => undef ) unless $args{request}->action( $bits[1] );
- return ( $destination => $args{request}->action( $bits[1] )->argument( $bits[2] ) );
+ # No such action -- value is undef
+ return ( $destination => undef ) unless $args{request}->top_request->action( $bits[1] );
+ # We have a value
+ return ( $destination => $args{request}->top_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] );
+ # No such action -- value is undef
+ return ( $destination => undef ) unless $args{request}->top_request->action( $bits[1] );
+ # Action exists but hasn't run yet -- defer until later
+ return ( @original ) unless $args{response}->result( $bits[1] );
+ # We have a value
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] } );
}
}
+ # As a fallback, just set it to the value
return ( $destination => $args{source} );
}
Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm (original)
+++ jifty/trunk/lib/Jifty/Web.pm Thu May 18 13:22:15 2006
@@ -986,12 +986,22 @@
for $f (reverse @regions) {
my $new = $self->get_region( join '-', grep {$_} $self->qualified_region, $f->name );
+
+ # Arguments can be complex mapped hash values. Get their
+ # real values by mapping.
+ my %defaults = %{$f->arguments};
+ for (keys %defaults) {
+ my ($key, $value) = Jifty::Request::Mapper->map(destination => $_, source => $defaults{$_});
+ delete $defaults{$_};
+ $defaults{$key} = $value;
+ }
+
$new ||= Jifty::Web::PageRegion->new(
name => $f->name,
path => $f->path,
region_wrapper => $f->wrapper,
parent => Jifty->web->current_region,
- defaults => $f->arguments,
+ defaults => \%defaults,
);
$new->enter;
}
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 Thu May 18 13:22:15 2006
@@ -231,7 +231,6 @@
sub parameter {
my $self = shift;
my ( $key, $value ) = @_;
- ($key, $value) = Jifty::Request::Mapper->query_parameters($key => $value);
$self->{parameters}{$key} = $value;
}
@@ -289,11 +288,22 @@
if ( $defaults and $value eq $defaults->default_argument($argument) ) {
$self->state_variable( "region-$name.$argument" => undef, $value );
} else {
- $self->state_variable( Jifty::Request::Mapper->query_parameters( "region-$name.$argument" => $value ) );
+ $self->state_variable( "region-$name.$argument" => $value );
}
}
+# Query-map any complex structures
+sub _map {
+ my %args = @_;
+ for (keys %args) {
+ my ($key, $value) = Jifty::Request::Mapper->query_parameters($_ => $args{$_});
+ delete $args{$_};
+ $args{$key} = $value;
+ }
+ return %args;
+}
+
=head2 parameters
Returns the generic list of parameters attached to the link as a hash.
@@ -318,7 +328,7 @@
%parameters = %{ $self->{parameters} };
}
- %parameters = ( %{$self->{state_variable} || {}}, %parameters );
+ %parameters = _map( %{$self->{state_variable} || {}}, %parameters );
$parameters{"J:CALL"} = $self->call
if $self->call;
@@ -339,10 +349,14 @@
sub post_parameters {
my $self = shift;
- my %parameters = ( %{ $self->{fallback} || {} }, $self->parameters );
+ my %parameters = ( _map( %{ $self->{fallback} || {} } ), $self->parameters );
my ($root) = $ENV{'REQUEST_URI'} =~ /([^\?]*)/;
+ # Submit actions should only show up once
+ my %uniq;
+ $self->submit([grep {not $uniq{$_}++} @{$self->submit}]) if $self->submit;
+
# Add a redirect, if this isn't to the right page
if ( $self->url ne $root and not $self->returns ) {
require Jifty::Action::Redirect;
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 Thu May 18 13:22:15 2006
@@ -188,7 +188,16 @@
}
# Arguments
- $args{args} = {Jifty::Request::Mapper->query_parameters( %{ $hook->{args} || {} } )};
+ $args{args} = $hook->{args} || {};
+
+ # We're going to pass complex query mapping structures
+ # as-is to the server, but we need to make sure we're not
+ # trying to pass around Actions, merely their monikers.
+ for my $key (keys %{$args{args}}) {
+ next unless ref $args{args}{$key} eq "HASH";
+ $args{args}{$key}{$_} = $args{args}{$key}{$_}->moniker
+ for grep {ref $args{args}{$key}{$_}} keys %{$args{args}{$key}};
+ }
# Effects
$args{$_} = $hook->{$_} for grep {exists $hook->{$_}} qw/effect effect_args/;
More information about the Jifty-commit
mailing list