annotate Lib/IMPL/Web/Application/CustomResource.pm @ 323:b56b1ec33b59

minor changes to support JSON in transformation from a query to an object
author sergey
date Thu, 23 May 2013 18:40:26 +0400
parents 9b25e1f50144
children fe725fad2d90
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' => '@_'
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
13 ]
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
14 };
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
15
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
16 __PACKAGE__->static_accessor(contractFactory => CustomResourceContract );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
17 __PACKAGE__->static_accessor_own(_contractInstance => undef);
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 sub contractInstance {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
20 my ($self) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
21
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
22 $self = ref $self || $self;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
23 $self->_contractInstance ? $self->_contractInstance : $self->InitContract();
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
24 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
25
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
26 sub InitContract {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
27 my ($self) = @_;
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
28 $self->_contractInstance(
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
29 $self->contractFactory->new(
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
30 resourceFactory => $self,
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
31 resources => [ $self->GetChildResources() ]
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
32 )
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
33 );
229
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
248
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
36 sub CreateContract {
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
37 my ($self, %args) = @_;
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
38
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
39 $self->contractFactory->new(
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
40 resourceFactory => Factory->new(
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
41 $self,
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
42 \%args
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
43 ),
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
44 resources => [ $self->GetChildResources() ]
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
45 )
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
46 }
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
47
295
cin
parents: 248
diff changeset
48 sub CreateResource {
cin
parents: 248
diff changeset
49 my ($self,%args) = @_;
cin
parents: 248
diff changeset
50
cin
parents: 248
diff changeset
51 $self->CreateContract()->CreateResource(%args);
cin
parents: 248
diff changeset
52 }
cin
parents: 248
diff changeset
53
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
54 sub GetChildResources {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
55
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
56 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
57
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
58
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
59 1;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
60
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
61 __END__
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
62
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
63 =pod
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
64
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
65 =head1 NAME
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
66
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
67 C<IMPL::Web::Application::CustomResource> - базовый класс для ресурсов,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
68 реальзуемых в коде.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
69
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
70 =head1 SYNOPSIS
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
71
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
72 =begin code
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
73
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
74 package MyApp::Web::Resources::ProfileResource;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
75 use IMPL::declare {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
76 base => [
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
77 'IMPL::Web::Application::CustomResource' => '@_'
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 }
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 sub HttpGet {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
82 my ($this) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
83 return $this->model;
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
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
86 sub HttpPut {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
87 my ($this,$action) = @_;
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 my $form = MyApp::Web::Schema::UpdateUser->new();
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
90
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
91 $this->model->update( $form->Bind($action) );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
92 }
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 =end code
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
95
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
96 =head1 MEMBERS
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
97
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
98 =head2 C<[static]contractFactory>
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 C<IMPL::Web::Application::CustomResourceContract>.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
102
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
103 =head2 C<[static]contractInstance>
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 метода C<InitContract()>.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
107
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
108 =head2 C<[static]InitContract()>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
109
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
110 Создает новый экземпляр контракта, используя фабрику из свойства C<contractFactory>.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
111
248
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
112 =head2 C<[static]CreateContract(%args)>
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
113
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
114 Создает новый контракт, который при создании ресурсов будет передавать им в
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
115 конструкторе параметры C<%args>. Реализуется при помощи C<IMPL::Object::Factory>
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
116 которой задается параметр ссылка на C<%args>, т.о. при создании ресурса, ему в
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
117 конструкторе будет передан список из ключей и значений хеша C<%args>, а затем
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
118 остальные аргументы.
814d755e5d12 Minor fixes
sergey
parents: 240
diff changeset
119
295
cin
parents: 248
diff changeset
120 =head2 C<[static]CreateResource(%args)>
cin
parents: 248
diff changeset
121
cin
parents: 248
diff changeset
122 Создает контракт по-умолчанию и вызывает у него метод C<CreateResource(%args)>.
cin
parents: 248
diff changeset
123
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
124 =head2 C<[static]GetChildResources()>
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 Статический метод, который должны переопределять новые классы ресурсов, у
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
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
129 =begin code
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 package MyApp::Web::MyResource
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 sub GetChildResources {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
134 my $self = shift;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
135 return
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
136 $self->SUPER::GetChildResources(),
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
137 {
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
138 name => 'info',
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
139 contract => $contractInfo
229
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 }
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 =end code
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents:
diff changeset
144
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
145 Метод возвращает список из хешей, которые будут переданы в качестве параметра
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 229
diff changeset
146 C<resources> контракту данного ресурса.
229
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 =cut