Mercurial > pub > Impl
diff Lib/IMPL/Web/Application/ResourceContract.pm @ 332:04a093f0a5a6
IMPL::Web::Application refactoring: resources are created per client request
author | cin |
---|---|
date | Sun, 09 Jun 2013 21:48:57 +0400 |
parents | 2ff1726c066c |
children |
line wrap: on
line diff
--- a/Lib/IMPL/Web/Application/ResourceContract.pm Wed Jun 05 18:21:11 2013 +0400 +++ b/Lib/IMPL/Web/Application/ResourceContract.pm Sun Jun 09 21:48:57 2013 +0400 @@ -121,32 +121,18 @@ my $contract = ResourceContract->new( verbs => { - get => OperationContract->new( + get => sub { + my ($resource,$action) = @_; + return "Hello!"; + }, + post => OperationContract->new( binding => sub { my ($resource,$action) = @_; - return "Hello!"; - } - ), - post => OperationContract->new( - parameters => [ - IMPL::Transform::DataToModel->new() # создаем преобразование для формы - ], - binding => sub { - my ($resource,$action,$data) = @_; - return $resource->model->AddItem($data); - }, - success => sub { - my ($resource,$action,$result) = @_; + my $data = My::App::ModelBinder->new($resource->ds)->Bind($action); return IMPL::Web::HttpResponse->Redirect( location => $resource->location->Child($result->id) ) - }, - error => sub { - my ($resource,$action,$error) = @_; - $action->errors->Append($error); - return $resource->model; } - ), }, resources => [ @@ -155,16 +141,15 @@ binding => sub { return $_[0]->model->info; }, - contract => ResourceContract->new( + contract => { verbs => { - # using method references is also possible get => sub { my ($resource,$action) = @_; return $resource->model; } } - ) + } } ] ) @@ -172,6 +157,7 @@ my $obj = My::App::Data->fetch('something'); my $resource = $contract->CreateResource( + request => $currentRequest, model => $obj, parent => $prentResource, id => 'item-something'