annotate Lib/IMPL/Web/RestContract.pm @ 212:292226770180

bugfixes
author sergey
date Fri, 29 Jun 2012 19:24:15 +0400
parents a9dbe534d236
children d6e2ea24af08
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
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
4 use IMPL::lang qw(:declare :constants);
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
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
60 =cut