Mercurial > pub > Impl
comparison Lib/IMPL/Web/Application/CustomResource.pm @ 229:47f77e6409f7
heavily reworked the resource model of the web application:
*some ResourcesContraact functionality moved to Resource
+Added CustomResource
*Corrected action handlers
author | sergey |
---|---|
date | Sat, 29 Sep 2012 02:34:47 +0400 |
parents | |
children | 6d8092d8ce1b |
comparison
equal
deleted
inserted
replaced
228:431db7034a88 | 229:47f77e6409f7 |
---|---|
1 package IMPL::Web::Application::CustomResource; | |
2 use strict; | |
3 | |
4 use IMPL::lang qw(:constants); | |
5 | |
6 use IMPL::declare { | |
7 require => { | |
8 CustomResourceContract => 'IMPL::Web::Application::CustomResourceContract' | |
9 }, | |
10 base => [ | |
11 'IMPL::Web::Application::Resource' => '@_' | |
12 ] | |
13 }; | |
14 | |
15 __PACKAGE__->static_accessor(contractFactory => CustomResourceContract ); | |
16 __PACKAGE__->static_accessor_own(_contractInstance => undef); | |
17 | |
18 sub contractInstance { | |
19 my ($self) = @_; | |
20 | |
21 $self = ref $self || $self; | |
22 $self->_contractInstance ? $self->_contractInstance : $self->InitContract(); | |
23 } | |
24 | |
25 sub InitContract { | |
26 my ($self) = @_; | |
27 | |
28 $self->_contractInstance( $self->contractFactory->new(resourceFactory => $self ) ); | |
29 } | |
30 | |
31 sub GetChildResources { | |
32 | |
33 } | |
34 | |
35 | |
36 1; | |
37 | |
38 __END__ | |
39 | |
40 =pod | |
41 | |
42 =head1 NAME | |
43 | |
44 C<IMPL::Web::Application::CustomResource> - базовый класс для ресурсов, | |
45 реальзуемых в коде. | |
46 | |
47 =head1 SYNOPSIS | |
48 | |
49 =begin code | |
50 | |
51 package MyApp::Web::Resources::ProfileResource; | |
52 use IMPL::declare { | |
53 base => [ | |
54 'IMPL::Web::Application::CustomResource' => '@_' | |
55 ] | |
56 } | |
57 | |
58 sub HttpGet { | |
59 my ($this) = @_; | |
60 return $this->model; | |
61 } | |
62 | |
63 sub HttpPut { | |
64 my ($this,$action) = @_; | |
65 | |
66 my $form = MyApp::Web::Schema::UpdateUser->new(); | |
67 | |
68 $this->model->update( $form->Bind($action) ); | |
69 } | |
70 | |
71 =end code | |
72 | |
73 =head1 MEMBERS | |
74 | |
75 =head2 C<[static]contractFactory> | |
76 | |
77 Фабрика, используемая для получения контракта ресурса. По умолчанию | |
78 C<IMPL::Web::Application::CustomResourceContract>. | |
79 | |
80 =head2 C<[static]contractInstance> | |
81 | |
82 Экземпляр контракта для ресурса. Создается при первом обращении при помощи | |
83 метода C<InitContract()>. | |
84 | |
85 =head2 C<[static]InitContract()> | |
86 | |
87 Создает новый экземпляр контракта, используя фабрику из свойства C<contractFactory>. | |
88 | |
89 =head2 C<[static]GetChildResources()> | |
90 | |
91 Статический метод, который должны переопределять новые классы ресурсов, у | |
92 которых есть дочерние ресурсы. | |
93 | |
94 =begin code | |
95 | |
96 package MyApp::Web::MyResource | |
97 | |
98 sub GetChildResources { | |
99 my $self = shift; | |
100 return | |
101 $self->SUPER::GetChildResources(), | |
102 { | |
103 | |
104 } | |
105 { | |
106 | |
107 }; | |
108 } | |
109 | |
110 =end code | |
111 | |
112 | |
113 =cut |