Mercurial > pub > Impl
diff Lib/IMPL/Web/Handler/JSONView.pm @ 297:52aae1b85084
Added transformations support to JSONView
author | cin |
---|---|
date | Mon, 11 Mar 2013 01:22:24 +0400 |
parents | 32aceba4ee6d |
children |
line wrap: on
line diff
--- a/Lib/IMPL/Web/Handler/JSONView.pm Tue Mar 05 01:46:32 2013 +0400 +++ b/Lib/IMPL/Web/Handler/JSONView.pm Mon Mar 11 01:22:24 2013 +0400 @@ -3,15 +3,20 @@ use JSON; use IMPL::lang qw(is); +use IMPL::Const qw(:prop); use IMPL::declare { require => { HttpResponse => 'IMPL::Web::HttpResponse', - ViewResult => '-IMPL::Web::ViewResult' + ViewResult => '-IMPL::Web::ViewResult', + Loader => 'IMPL::Code::Loader' }, base => [ 'IMPL::Object' => undef, 'IMPL::Object::Serializable' => undef, 'IMPL::Object::Autofill' => '@_' + ], + props => [ + transform => PROP_RW ] }; @@ -31,6 +36,12 @@ $model = [$model] unless ref $model; + if (my $factory = $this->transform) { + Loader->safe->Require($factory) unless ref $factory; + my $t = $this->transform->new(); + $model = $t->Transform($model); + } + my %params = ( type => $this->contentType, charset => 'utf-8',