Mercurial > pub > Impl
annotate Lib/IMPL/Web/RestContract.pm @ 214:4683002758aa
sync
author | sergey |
---|---|
date | Mon, 06 Aug 2012 17:27:47 +0400 |
parents | d6e2ea24af08 |
children | 77a9934a44af |
rev | line source |
---|---|
198 | 1 package IMPL::Web::RestContract; |
2 use strict; | |
3 | |
213 | 4 use IMPL::lang qw(:declare); |
198 | 5 use IMPL::declare { |
6 require => { | |
7 Exception => 'IMPL::Exception', | |
8 InvalidOpException => '-IMPL::InvalidOperationException', | |
9 ForbiddenException => 'IMPL::Web::ForbiddenException', | |
10 TRestResource => 'IMPL::Web::Application::RestResource', | |
212 | 11 RestBaseResource => 'IMPL::Web::Application::RestBaseResource', |
198 | 12 }, |
13 base => { | |
14 'IMPL::Transform' => sub { my %args = @_; $args{resources} }, | |
15 'IMPL::Object::Serializable' => undef | |
16 } | |
17 }; | |
18 | |
19 sub CTOR { | |
20 my ($this) = @_; | |
21 | |
22 $this->templates->{-plain} = sub { die ForbiddenException->new(); }; | |
23 $this->templates->{-default} = sub { die ForbiddenException->new(); }; | |
212 | 24 $this->templates->{&RestBaseResource} = sub { $_[1] }; |
198 | 25 } |
26 | |
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 | 31 |
32 if (ref $t eq 'HASH') { | |
33 my $factory = $t->{factory} || TRestResource; | |
200 | 34 return $factory->new(%$t, target => $obj, contract => $this, %$props); |
198 | 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 | 37 } else { |
38 die InvalidOpException->new(); | |
39 } | |
40 } | |
41 | |
42 1; | |
43 | |
44 __END__ | |
45 | |
46 =pod | |
47 | |
48 =head1 NAME | |
49 | |
50 C<IMPL::Web::RestContract> Описывает правила публикации ресурсов. | |
51 | |
52 =head1 SYNOPSIS | |
53 | |
212 | 54 |
55 | |
198 | 56 =begin code |
57 | |
58 =end code | |
59 | |
213 | 60 =head1 DESCRIPTION |
61 | |
62 Контракт представляет собой отображение модели предметной области на модель | |
63 ресурсов. Контракт описывает дерево ресурсов начиная с корневого ресурса, | |
64 и далее. | |
65 | |
198 | 66 =cut |