annotate lib/IMPL/Web/Application/ResourceInterface.pm @ 417:3ed0c58e9da3 ref20150831

working on di container, tests
author cin
date Mon, 02 Nov 2015 01:56:53 +0300
parents c6e90e02dd17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::Web::Application::ResourceInterface;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4 use IMPL::require {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 Exception => 'IMPL::Exception',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 NotImplException => '-IMPL::NotImplementedException'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 sub InvokeHttpVerb {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 die NotImplException->new();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13 sub FetchChildResource {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 die NotImplException->new();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 __END__
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 =pod
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23 =head1 NAME
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25 C<IMPL::Web::Application::ResourceInterface> - Интерфейс для Web-ресурса.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 =head1 SYNOPSIS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29 =begin code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31 package MyApp::Web::Resource;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32 use IMPL::Const qw(:prop);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33 use IMPL::declare {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34 require => {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35 NotAllowedException => 'IMPL::Web::NotAllowedException'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 },
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37 base => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38 'IMPL::Object' => undef,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 'IMPL::Web::Application::ResourceInterface' => undef
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40 ],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41 props => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42 model => PROP_ALL
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43 ]
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46 sub InvokeHttpVerb {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47 my ($this,$verb,$action) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49 if($verb eq 'GET') {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50 return $this->model;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52 die NotAllowedException->new(allow => 'GET');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56 sub FetchChildResource {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57 # no child resources
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58 return;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61 =end code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
63 =head1 DESCRIPTION
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
64
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
65 Данный модуль объявляет только интерфейс, тоесть в нем есть заглушки для функций
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66 которые необходимо реализовать.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
68 Для создания класса, который может быть использоваться для создания Web-ресурсов
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
69 нужно унаследовать данный интерфейс и реализовать его методы.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
70
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
71 =head1 MEMBERS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
72
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
73 =head2 C<InvokeHttpVerb($verb,$action)>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
74
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
75 Выполняет операцию над ресурсом и возвращает результат ее выполнения.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
76 Результатом может быть произвольный объект, который будет передан по цепочке
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
77 обработчиков приложения для формирования ответа вервера, либо
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
78 C<IMPL::Web::HttpResponse>, который описывает (не обязательно полностью) ответ.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
79 В любом случае результат будет передан далее в цепочку обработчиков и может
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
80 быть изменен.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
81
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
82 =head2 C<FetchChildResource($childId)>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
83
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
84 Используется для получения дочернего ресурса (который содержится в данном
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
85 контейнере). Метод должен возвращать либо Web-ресурс
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
86 C<IMPL::Web::Application::ResourceInterface>, либо C<undef> если дочерний ресурс
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
87 не найден.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
88
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
89 =cut