annotate Lib/IMPL/Web/Application/CustomResource.pm @ 330:fe725fad2d90

Added access checking to web resources
author sergey
date Tue, 04 Jun 2013 19:25:54 +0400
parents 9b25e1f50144
children 04a093f0a5a6
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
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
114 =end code
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
115
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
116 =head1 MEMBERS
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
117
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
118 =head2 C<[static]contractFactory>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
119
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
120 Фабрика, используемая для получения контракта ресурса. По умолчанию
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
121 C<IMPL::Web::Application::CustomResourceContract>.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
122
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
123 =head2 C<[static]contractInstance>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
124
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
125 Экземпляр контракта для ресурса. Создается при первом обращении при помощи
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
126 метода C<InitContract()>.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
127
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
128 =head2 C<[static]InitContract()>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
129
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
130 Создает новый экземпляр контракта, используя фабрику из свойства C<contractFactory>.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
131
248
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
132 =head2 C<[static]CreateContract(%args)>
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
133
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
134 Создает новый контракт, который при создании ресурсов будет передавать им в
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
135 конструкторе параметры C<%args>. Реализуется при помощи C<IMPL::Object::Factory>
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
136 которой задается параметр ссылка на C<%args>, т.о. при создании ресурса, ему в
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
137 конструкторе будет передан список из ключей и значений хеша C<%args>, а затем
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
138 остальные аргументы.
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
139
295
cin
parents: 248
diff changeset
140 =head2 C<[static]CreateResource(%args)>
cin
parents: 248
diff changeset
141
cin
parents: 248
diff changeset
142 Создает контракт по-умолчанию и вызывает у него метод C<CreateResource(%args)>.
cin
parents: 248
diff changeset
143
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
144 =head2 C<[static]GetChildResources()>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
145
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
146 Статический метод, который должны переопределять новые классы ресурсов, у
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
147 которых есть дочерние ресурсы.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
148
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
149 =begin code
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
150
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
151 package MyApp::Web::MyResource
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
152
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
153 sub GetChildResources {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
154 my $self = shift;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
155 return
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
156 $self->SUPER::GetChildResources(),
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
157 {
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
158 name => 'info',
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
159 contract => $contractInfo
229
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
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
163 =end code
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
164
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
165 Метод возвращает список из хешей, которые будут переданы в качестве параметра
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
166 C<resources> контракту данного ресурса.
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
167
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
168 =cut