comparison Lib/IMPL/Web/QueryHandler/JsonFormat.pm @ 173:aaab45153411

minor bugfixes
author sourcer
date Wed, 14 Sep 2011 18:59:01 +0400
parents 4267a2ac3d46
children d1676be8afcc
comparison
equal deleted inserted replaced
172:068acfe903c3 173:aaab45153411
8 8
9 sub Process { 9 sub Process {
10 my ($this,$action,$nextHandler) = @_; 10 my ($this,$action,$nextHandler) = @_;
11 11
12 my $result; 12 my $result;
13 my $t = new IMPL::Transform::Json;
14 13
15 try { 14 try {
16 $result = $nextHandler->(); 15 $result = $nextHandler->();
17 $result = [$result] unless ref $result; 16 $result = [$result] unless ref $result;
18 } otherwise { 17 } otherwise {
19 my $err = shift; 18 my $err = shift;
20 $result = { error => $err }; 19 $result = { error => $err };
21 }; 20 };
21
22 my $t = new IMPL::Transform::Json($action->context->{json});
23
24 if ($action->context->{transactionType} and $action->context->{transactionType} eq 'form') {
25 delete @$result{qw(formData formSchema)};
26 my $errors = @$result{formErrors};
27
28 $result->{formErrors} = [ map $_->Message, @$errors ] if $errors;
29 }
22 30
23 $action->response->contentType('text/javascript'); 31 $action->response->contentType('text/javascript');
24 32
25 my $hout = $action->response->streamBody; 33 my $hout = $action->response->streamBody;
26 print $hout to_json( $t->Transform($result), {pretty => 1} ); 34 print $hout to_json( $t->Transform($result), {pretty => 1} );
39 47
40 my %propListCache; 48 my %propListCache;
41 49
42 our %CTOR = ( 50 our %CTOR = (
43 'IMPL::Transform' => sub { 51 'IMPL::Transform' => sub {
52 my $options = shift;
53 (
54 $options ? %{$options} : ()
55 ),
44 ARRAY => sub { 56 ARRAY => sub {
45 my ($this,$object) = @_; 57 my ($this,$object) = @_;
46 58
47 return [ 59 return [
48 map { $this->Transform($_) } @$object 60 map { $this->Transform($_) } @$object