# HG changeset patch # User sergey # Date 1369320026 -14400 # Node ID b56b1ec33b59c610a215e5a9b5999df79bbf83c4 # Parent cca158327c477198a8349bbcd70110efbac29e95 minor changes to support JSON in transformation from a query to an object diff -r cca158327c47 -r b56b1ec33b59 Lib/IMPL/DOM/Transform/QueryToDOM.pm --- a/Lib/IMPL/DOM/Transform/QueryToDOM.pm Tue May 21 10:04:11 2013 +0400 +++ b/Lib/IMPL/DOM/Transform/QueryToDOM.pm Thu May 23 18:40:26 2013 +0400 @@ -16,6 +16,7 @@ my ($this) = @_; $this->templates->{'CGI'} = 'TransformCGI'; + $this->templates->{'IMPL::Web::Application::Action'} = 'TransformAction'; $this->delimiter('[.]'); $this->prefix(''); @@ -41,7 +42,7 @@ sub TransformCGI { my ($this,$query) = @_; - + my $data={}; my $prefix = $this->prefix; @@ -76,6 +77,12 @@ return $this->Transform($data); } +sub TransformAction { + my ($this,$action) = @_; + + return $this->Transform($action->isJson ? $action->jsonData : $action->query); +} + 1; __END__ diff -r cca158327c47 -r b56b1ec33b59 Lib/IMPL/Web/Application/Action.pm --- a/Lib/IMPL/Web/Application/Action.pm Tue May 21 10:04:11 2013 +0400 +++ b/Lib/IMPL/Web/Application/Action.pm Thu May 23 18:40:26 2013 +0400 @@ -14,7 +14,16 @@ 'IMPL::Object::Autofill' => '@_' ], props => [ - application => PROP_RO, + application => { + get => sub { + carp "Action->application is deprecated use Resource->application instead."; + shift->_app(); + }, + set => sub { + shift->_app(@_); + } + }, + _app => PROP_RW, query => PROP_RO, context => PROP_RW, _jsonData => PROP_RW, @@ -43,6 +52,10 @@ shift->query->https ? 1 : 0; } +sub isJson { + return shift->contentType =~ m{^application/json} ? 1 : 0; +} + sub param { my ($this,$name,$rx) = @_; @@ -87,7 +100,7 @@ sub jsonData { my ($this) = @_; - if ($this->contentType =~ m{^application/json} ) { + if ($this->isJson ) { my $data = $this->_jsonData; unless($data) { $data = JSON->new()->decode($this->rawData('decode encoding')); diff -r cca158327c47 -r b56b1ec33b59 Lib/IMPL/Web/BadRequestException.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Web/BadRequestException.pm Thu May 23 18:40:26 2013 +0400 @@ -0,0 +1,30 @@ +package IMPL::Web::BadRequestException; +use strict; + +use IMPL::declare { + base => { + 'IMPL::Web::Exception' => '@_' + } +}; + +use IMPL::Resources::Strings { + message => "The request could not be understood due to malformed syntax" +}; + +sub status { + "400 Bad Request"; +} + +1; + +__END__ + +=pod + +=head1 NAME + +C - 400 Bad Request + +=head1 DESCRIPTION + +=cut \ No newline at end of file diff -r cca158327c47 -r b56b1ec33b59 Lib/IMPL/Web/Exception.pm --- a/Lib/IMPL/Web/Exception.pm Tue May 21 10:04:11 2013 +0400 +++ b/Lib/IMPL/Web/Exception.pm Thu May 23 18:40:26 2013 +0400 @@ -34,7 +34,7 @@ =begin code use IMPL::require { - WebException => 'IMPL::Web::WebException' + WebException => 'IMPL::Web::Exception' }; sub MyWebHandler {