annotate Lib/IMPL/Web/Application/CustomResource.pm @ 333:cd6409f66a5f

small fixes, request environment is deprecated
author cin
date Tue, 11 Jun 2013 20:22:52 +0400
parents 04a093f0a5a6
children 71221d79e6b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
1 package IMPL::Web::Application::CustomResource;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
2 use strict;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
3
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
4 use IMPL::Const qw(:prop);
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
5
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
6 use IMPL::declare {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
7 require => {
248
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
8 Factory => 'IMPL::Object::Factory',
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
9 CustomResourceContract => 'IMPL::Web::Application::CustomResourceContract'
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
10 },
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
11 base => [
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
12 'IMPL::Web::Application::Resource' => '@_'
330
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
13 ],
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
14 props => [
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
15 accessCheck => PROP_RW
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
16 ]
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
17 };
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
18
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
19 __PACKAGE__->static_accessor(contractFactory => CustomResourceContract );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
20 __PACKAGE__->static_accessor_own(_contractInstance => undef);
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
21
330
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
22 sub CTOR {
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
23 my ($this,%args) = @_;
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
24
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
25 $this->accessCheck($args{accessCheck})
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
26 if $args{accessCheck};
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
27 }
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
28
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
29 sub contractInstance {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
30 my ($self) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
31
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
32 $self = ref $self || $self;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
33 $self->_contractInstance ? $self->_contractInstance : $self->InitContract();
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
34 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
35
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
36 sub InitContract {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
37 my ($self) = @_;
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
38 $self->_contractInstance(
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
39 $self->contractFactory->new(
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
40 resourceFactory => $self,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
41 resources => [ $self->GetChildResources() ]
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
42 )
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
43 );
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
44 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
45
248
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
46 sub CreateContract {
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
47 my ($self, %args) = @_;
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
48
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
49 $self->contractFactory->new(
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
50 resourceFactory => Factory->new(
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
51 $self,
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
52 \%args
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
53 ),
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
54 resources => [ $self->GetChildResources() ]
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
55 )
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
56 }
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
57
295
cin
parents: 248
diff changeset
58 sub CreateResource {
cin
parents: 248
diff changeset
59 my ($self,%args) = @_;
cin
parents: 248
diff changeset
60
cin
parents: 248
diff changeset
61 $self->CreateContract()->CreateResource(%args);
cin
parents: 248
diff changeset
62 }
cin
parents: 248
diff changeset
63
330
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
64 sub AccessCheck {
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
65 my ($this,$verb) = @_;
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
66
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
67 my $handler = $this->accessCheck;
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
68
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
69 if(ref($handler) eq 'CODE') {
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
70 &$handler($this,$verb);
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
71 }
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
72 }
fe725fad2d90 Added access checking to web resources
sergey
parents: 295
diff changeset
73
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
74 sub GetChildResources {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
75
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
76 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
77
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
78
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
79 1;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
80
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
81 __END__
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
82
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
83 =pod
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
84
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
85 =head1 NAME
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
86
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
87 C<IMPL::Web::Application::CustomResource> - базовый класс для ресурсов,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
88 реальзуемых в коде.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
89
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
90 =head1 SYNOPSIS
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
91
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
92 =begin code
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
93
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
94 package MyApp::Web::Resources::ProfileResource;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
95 use IMPL::declare {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
96 base => [
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
97 'IMPL::Web::Application::CustomResource' => '@_'
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
98 ]
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
99 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
100
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
101 sub HttpGet {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
102 my ($this) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
103 return $this->model;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
104 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
105
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
106 sub HttpPut {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
107 my ($this,$action) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
108
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
109 my $form = MyApp::Web::Schema::UpdateUser->new();
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
110
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
111 $this->model->update( $form->Bind($action) );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
112 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
113
332
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
114 our %COMPONENTS = (
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
115 item => {
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
116 verbs => {
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
117 get => sub {
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
118 shift->model;
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
119 }
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
120 },
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
121 resources => [
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
122 edit =>
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
123 ]
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
124 }
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
125 );
04a093f0a5a6 IMPL::Web::Application refactoring: resources are created per client request
cin
parents: 330
diff changeset
126
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
127 =end code
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
128
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
129 =head1 MEMBERS
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
130
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
131 =head2 C<[static]contractFactory>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
132
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
133 Фабрика, используемая для получения контракта ресурса. По умолчанию
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
134 C<IMPL::Web::Application::CustomResourceContract>.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
135
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
136 =head2 C<[static]contractInstance>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
137
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
138 Экземпляр контракта для ресурса. Создается при первом обращении при помощи
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
139 метода C<InitContract()>.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
140
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
141 =head2 C<[static]InitContract()>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
142
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
143 Создает новый экземпляр контракта, используя фабрику из свойства C<contractFactory>.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
144
248
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
145 =head2 C<[static]CreateContract(%args)>
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
146
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
147 Создает новый контракт, который при создании ресурсов будет передавать им в
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
148 конструкторе параметры C<%args>. Реализуется при помощи C<IMPL::Object::Factory>
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
149 которой задается параметр ссылка на C<%args>, т.о. при создании ресурса, ему в
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
150 конструкторе будет передан список из ключей и значений хеша C<%args>, а затем
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
151 остальные аргументы.
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
152
295
cin
parents: 248
diff changeset
153 =head2 C<[static]CreateResource(%args)>
cin
parents: 248
diff changeset
154
cin
parents: 248
diff changeset
155 Создает контракт по-умолчанию и вызывает у него метод C<CreateResource(%args)>.
cin
parents: 248
diff changeset
156
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
157 =head2 C<[static]GetChildResources()>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
158
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
159 Статический метод, который должны переопределять новые классы ресурсов, у
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
160 которых есть дочерние ресурсы.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
161
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
162 =begin code
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
163
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
164 package MyApp::Web::MyResource
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
165
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
166 sub GetChildResources {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
167 my $self = shift;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
168 return
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
169 $self->SUPER::GetChildResources(),
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
170 {
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
171 name => 'info',
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
172 contract => $contractInfo
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
173 };
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
174 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
175
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
176 =end code
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
177
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
178 Метод возвращает список из хешей, которые будут переданы в качестве параметра
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
179 C<resources> контракту данного ресурса.
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
180
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
181 =cut