annotate Lib/IMPL/Web/RestContract.pm @ 206:c8fe3f84feba

+IMPL::Web::Handlers::ViewSelector +IMPL::Web::Handlers::ErrorHandler *IMPL::Web::Handlers::RestController moved types mappings to ViewSelector
author sergey
date Thu, 03 May 2012 16:48:39 +0400
parents a9dbe534d236
children 292226770180
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',
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
11 },
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
12 base => {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
13 'IMPL::Transform' => sub { my %args = @_; $args{resources} },
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
14 'IMPL::Object::Serializable' => undef
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
15 }
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 sub CTOR {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
19 my ($this) = @_;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
20
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
21 $this->templates->{-plain} = sub { die ForbiddenException->new(); };
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
22 $this->templates->{-default} = sub { die ForbiddenException->new(); };
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
23 $this->templates->{TRestResource} = sub { $_[0] };
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
24 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
25
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
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
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
30
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
31 if (ref $t eq 'HASH') {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
32 my $factory = $t->{factory} || TRestResource;
200
sergey
parents: 199
diff changeset
33 return $factory->new(%$t, target => $obj, contract => $this, %$props);
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
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
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
36 } else {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
37 die InvalidOpException->new();
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
38 }
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
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
43 1;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
44
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
45 __END__
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
46
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
47 =pod
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
48
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
49 =head1 NAME
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
50
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
51 C<IMPL::Web::RestContract> Описывает правила публикации ресурсов.
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
52
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
53 =head1 SYNOPSIS
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
54
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
55 =begin code
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
56
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
57 =end code
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
58
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
59 =cut