annotate Lib/IMPL/Web/RestContract.pm @ 198:2ffe6f661605

Implemented IMPL::Web::Handler::RestController fixes in IMPL::Serialization completed IMPL::Web::Application::RestResource added IMPL::Web::Handler::JSONView added IMPL::Web::RestContract
author cin
date Fri, 20 Apr 2012 16:06:36 +0400
parents
children e743a8481327
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 {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
27 my ($this,$t,$obj,@args) = @_;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
28
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
29 if (ref $t eq 'HASH') {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
30 my $factory = $t->{factory} || TRestResource;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
31 return $factory->new(%$t, target => $obj);
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
32 } elsif (ref $t eq 'CODE') {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
33 return $this->$t($obj,@args);
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
34 } else {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
35 die InvalidOpException->new();
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
36 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
37 }
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 1;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
42
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
43 __END__
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
44
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
45 =pod
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
46
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
47 =head1 NAME
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
48
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
49 C<IMPL::Web::RestContract> Описывает правила публикации ресурсов.
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
50
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
51 =head1 SYNOPSIS
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
52
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
53 =begin code
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
54
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
55 =end code
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
56
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents:
diff changeset
57 =cut