Mercurial > pub > Impl
annotate Lib/IMPL/Web/RestContract.pm @ 200:a9dbe534d236
sync
| author | sergey |
|---|---|
| date | Tue, 24 Apr 2012 02:34:49 +0400 |
| parents | e743a8481327 |
| children | 292226770180 |
| rev | line source |
|---|---|
| 198 | 1 package IMPL::Web::RestContract; |
| 2 use strict; | |
| 3 | |
| 4 use IMPL::lang qw(:declare :constants); | |
| 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', | |
| 11 }, | |
| 12 base => { | |
| 13 'IMPL::Transform' => sub { my %args = @_; $args{resources} }, | |
| 14 'IMPL::Object::Serializable' => undef | |
| 15 } | |
| 16 }; | |
| 17 | |
| 18 sub CTOR { | |
| 19 my ($this) = @_; | |
| 20 | |
| 21 $this->templates->{-plain} = sub { die ForbiddenException->new(); }; | |
| 22 $this->templates->{-default} = sub { die ForbiddenException->new(); }; | |
| 23 $this->templates->{TRestResource} = sub { $_[0] }; | |
| 24 } | |
| 25 | |
| 26 sub ProcessTemplate { | |
|
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
27 my ($this,$t,$obj,$props) = @_; |
|
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
28 |
|
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
29 $props ||= {}; |
| 198 | 30 |
| 31 if (ref $t eq 'HASH') { | |
| 32 my $factory = $t->{factory} || TRestResource; | |
| 200 | 33 return $factory->new(%$t, target => $obj, contract => $this, %$props); |
| 198 | 34 } elsif (ref $t eq 'CODE') { |
|
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
198
diff
changeset
|
35 return $this->$t($obj,$props); |
| 198 | 36 } else { |
| 37 die InvalidOpException->new(); | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 | |
| 42 | |
| 43 1; | |
| 44 | |
| 45 __END__ | |
| 46 | |
| 47 =pod | |
| 48 | |
| 49 =head1 NAME | |
| 50 | |
| 51 C<IMPL::Web::RestContract> Описывает правила публикации ресурсов. | |
| 52 | |
| 53 =head1 SYNOPSIS | |
| 54 | |
| 55 =begin code | |
| 56 | |
| 57 =end code | |
| 58 | |
| 59 =cut |
