Mercurial > pub > Impl
annotate Lib/IMPL/Web/RestContract.pm @ 212:292226770180
bugfixes
| author | sergey |
|---|---|
| date | Fri, 29 Jun 2012 19:24:15 +0400 |
| parents | a9dbe534d236 |
| children | d6e2ea24af08 |
| 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', | |
| 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 | |
| 60 =cut |
