annotate Lib/IMPL/Web/RestContract.pm @ 298:78f767765706

TT view refactoring
author cin
date Tue, 19 Mar 2013 02:02:37 +0400
parents 77a9934a44af
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
1 package IMPL::Web::RestContract;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
2 use strict;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
3
213
sergey
parents: 212
diff changeset
4 use IMPL::lang qw(:declare);
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
5 use IMPL::declare {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
6 require => {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
7 Exception => 'IMPL::Exception',
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
8 InvalidOpException => '-IMPL::InvalidOperationException',
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
9 ForbiddenException => 'IMPL::Web::ForbiddenException',
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
10 TRestResource => 'IMPL::Web::Application::RestResource',
212
292226770180 bugfixes
sergey
parents: 200
diff changeset
11 RestBaseResource => 'IMPL::Web::Application::RestBaseResource',
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
12 },
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
13 base => {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
14 'IMPL::Transform' => sub { my %args = @_; $args{resources} },
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
15 'IMPL::Object::Serializable' => undef
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
16 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
17 };
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
18
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
19 sub CTOR {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
20 my ($this) = @_;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
21
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
22 $this->templates->{-plain} = sub { die ForbiddenException->new(); };
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
23 $this->templates->{-default} = sub { die ForbiddenException->new(); };
212
292226770180 bugfixes
sergey
parents: 200
diff changeset
24 $this->templates->{&RestBaseResource} = sub { $_[1] };
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
25 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
26
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
27 sub ProcessTemplate {
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents: 198
diff changeset
28 my ($this,$t,$obj,$props) = @_;
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents: 198
diff changeset
29
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents: 198
diff changeset
30 $props ||= {};
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
31
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
32 if (ref $t eq 'HASH') {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
33 my $factory = $t->{factory} || TRestResource;
200
sergey
parents: 199
diff changeset
34 return $factory->new(%$t, target => $obj, contract => $this, %$props);
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
35 } elsif (ref $t eq 'CODE') {
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents: 198
diff changeset
36 return $this->$t($obj,$props);
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
37 } else {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
38 die InvalidOpException->new();
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
39 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
40 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
41
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
42 1;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
43
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
44 __END__
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
45
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
46 =pod
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
47
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
48 =head1 NAME
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
49
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
50 C<IMPL::Web::RestContract> Описывает правила публикации ресурсов.
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
51
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
52 =head1 SYNOPSIS
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
53
212
292226770180 bugfixes
sergey
parents: 200
diff changeset
54
292226770180 bugfixes
sergey
parents: 200
diff changeset
55
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
56 =begin code
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
57
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
58 =end code
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
59
213
sergey
parents: 212
diff changeset
60 =head1 DESCRIPTION
sergey
parents: 212
diff changeset
61
sergey
parents: 212
diff changeset
62 Контракт представляет собой отображение модели предметной области на модель
sergey
parents: 212
diff changeset
63 ресурсов. Контракт описывает дерево ресурсов начиная с корневого ресурса,
sergey
parents: 212
diff changeset
64 и далее.
sergey
parents: 212
diff changeset
65
215
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
66 Ресурсы состоят из нескольких описаний: C<ResourceContract>, C<OperationContract>
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
67 которые описываю отображение самих ресурсов и операций над ресурсами в предметную
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
68 область.
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
69
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
70 C<ResourceContract> представляет собой описание того, какой ресурс и с какими
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
71 параметрами должен быть создан. Например, может быть создан ресурс публикующий
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
72 методы родительского ресурса, или же ресурс может слжить контроллером для
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
73 работы с объектами предметной области.
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
74
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
75 C<OperationContract> описывает связь между методом объекта предметной области и
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
76 операцией возможной над ресурсом. Операция сводится к преобразованию запроса в
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
77 аргументы метода, затем вызову метода и преобразованию результата в ответ на запрос.
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
78
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
79 Ответ на запрос может быть как сформирован полностью в виде C<HTTP> ответа, так и
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
80 в виде объекта, который будет в дальнейшем обработан нижележащими обработчиками
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
81 приложения.
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
82
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
83
77a9934a44af sync, migrating to XML::Compile
cin
parents: 213
diff changeset
84
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
85 =cut