changeset 323:b56b1ec33b59

minor changes to support JSON in transformation from a query to an object
author sergey
date Thu, 23 May 2013 18:40:26 +0400
parents cca158327c47
children b1e7b55b4a38
files Lib/IMPL/DOM/Transform/QueryToDOM.pm Lib/IMPL/Web/Application/Action.pm Lib/IMPL/Web/BadRequestException.pm Lib/IMPL/Web/Exception.pm
diffstat 4 files changed, 54 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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__
--- 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'));
--- /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<IMPL::Web::BadRequestException> - 400 Bad Request
+
+=head1 DESCRIPTION
+
+=cut
\ No newline at end of file
--- 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 {