X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FWindow.pm;h=0289b399e66de60c319e15087629406a6b5e3ba3;hb=049d22341026ead65b36eca2bddac7181f246142;hp=8257c28d46c91213ac9a6cba8a85c62b327be3fa;hpb=f1cd5548dac21719deb3412fbc5d8dadb9338cc3;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/Window.pm b/lib/Reaction/UI/Window.pm index 8257c28..0289b39 100644 --- a/lib/Reaction/UI/Window.pm +++ b/lib/Reaction/UI/Window.pm @@ -6,9 +6,9 @@ use Reaction::UI::FocusStack; use namespace::clean -except => [ qw(meta) ]; -has ctx => (isa => 'Catalyst', is => 'ro', required => 1); +has ctx => (isa => 'Catalyst', is => 'ro', required => 1, weak_ref => 1); has view_name => (isa => 'Str', is => 'ro', lazy_fail => 1); -has content_type => (isa => 'Str', is => 'ro', lazy_fail => 1); +has content_type => (isa => 'Str', is => 'rw', lazy_fail => 1); has title => (isa => 'Str', is => 'rw', default => sub { 'Untitled window' }); has view => ( # XXX compile failure because the Catalyst::View constraint would be @@ -27,6 +27,11 @@ sub _build_view { }; sub flush { my ($self) = @_; + my $res = $self->ctx->res; + if ( $res->status =~ /^3/ || length($res->body) ) { + $res->content_type('text/plain') unless $res->content_type; + return; + } $self->flush_events; $self->flush_view; }; @@ -45,19 +50,30 @@ sub flush_events { foreach my $type (qw/query body/) { my $meth = "${type}_parameters"; - my $param_hash = $ctx->req->$meth; - $self->focus_stack->apply_events($param_hash) - if keys %$param_hash; + my $req_param = $ctx->req->$meth; + my $param_hash = { + map { + $_ =~ m/(^r.+\:\w+)\.(x|y)/ ? # for $req_param->{$_} ) + : ( $_ => $req_param->{$_} ) + } keys %$req_param + }; # yeah, FocusStack deletes it + my @param_keys = keys %$param_hash; + if (@param_keys) { + for (@param_keys) { + utf8::decode($param_hash->{$_}) + unless (utf8::is_utf8($param_hash->{$_})); + } + $self->focus_stack->apply_events($param_hash); + } } }; sub flush_view { my ($self) = @_; my $res = $self->ctx->res; - if ( $res->status =~ /^3/ || length($res->body) ) { - $res->content_type('text/plain') unless $res->content_type; - return; - } - $res->body($self->view->render_window($self)); + my $res_body = $self->view->render_window($self); + utf8::encode($res_body) if utf8::is_utf8($res_body); + $res->body($res_body); $res->content_type($self->content_type); };