comparison Lib/IMPL/Web/Application/Action.pm @ 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
comparison
equal deleted inserted replaced
322:cca158327c47 323:b56b1ec33b59
12 base => [ 12 base => [
13 'IMPL::Object' => undef, 13 'IMPL::Object' => undef,
14 'IMPL::Object::Autofill' => '@_' 14 'IMPL::Object::Autofill' => '@_'
15 ], 15 ],
16 props => [ 16 props => [
17 application => PROP_RO, 17 application => {
18 get => sub {
19 carp "Action->application is deprecated use Resource->application instead.";
20 shift->_app();
21 },
22 set => sub {
23 shift->_app(@_);
24 }
25 },
26 _app => PROP_RW,
18 query => PROP_RO, 27 query => PROP_RO,
19 context => PROP_RW, 28 context => PROP_RW,
20 _jsonData => PROP_RW, 29 _jsonData => PROP_RW,
21 ] 30 ]
22 }; 31 };
39 $this->query->https ? $this->query->https($header) : $this->query->http($header); 48 $this->query->https ? $this->query->https($header) : $this->query->http($header);
40 } 49 }
41 50
42 sub isSecure { 51 sub isSecure {
43 shift->query->https ? 1 : 0; 52 shift->query->https ? 1 : 0;
53 }
54
55 sub isJson {
56 return shift->contentType =~ m{^application/json} ? 1 : 0;
44 } 57 }
45 58
46 sub param { 59 sub param {
47 my ($this,$name,$rx) = @_; 60 my ($this,$name,$rx) = @_;
48 61
85 } 98 }
86 99
87 sub jsonData { 100 sub jsonData {
88 my ($this) = @_; 101 my ($this) = @_;
89 102
90 if ($this->contentType =~ m{^application/json} ) { 103 if ($this->isJson ) {
91 my $data = $this->_jsonData; 104 my $data = $this->_jsonData;
92 unless($data) { 105 unless($data) {
93 $data = JSON->new()->decode($this->rawData('decode encoding')); 106 $data = JSON->new()->decode($this->rawData('decode encoding'));
94 $this->_jsonData($data); 107 $this->_jsonData($data);
95 } 108 }