annotate Lib/IMPL/Web/AutoLocator.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 292226770180
children 5c82eec23bb6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
1 package IMPL::Web::AutoLocator;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
2 use strict;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
3
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
4 use IMPL::lang qw(:constants :hash);
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
5 use URI;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
6 use URI::Escape;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
7 use IMPL::declare {
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
8 require => {
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
9 Exception => 'IMPL::Exception',
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
10 ArgumentException => '-IMPL::InvalidArgumentException'
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
11 },
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
12 base => [
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
13 'IMPL::Object' => undef,
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
14 'IMPL::Object::Autofill' => '@_',
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
15 'IMPL::Object::Serializable' => '@_'
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
16 ],
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
17 props => [
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
18 base => PROP_GET | PROP_OWNERSET,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
19 view => PROP_ALL,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
20 query => PROP_ALL,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
21 hash => PROP_ALL
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
22 ]
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
23 };
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
24
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
25 sub Child {
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
26 my $this = shift;
211
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
27 my $child = shift or die ArgumentException->new("a child resource identifier is required");
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
28 die ArgumentException->new("a child resource can't be a reference") if ref $child;
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
29
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
30 # safe
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
31 $child = uri_escape($child);
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
32
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
33 my %args;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
34
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
35 $args{base} = $this->base =~ /\/$/ ? $this->base . $child : $this->base . '/' . $child;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
36 $args{view} = $this->view if $this->view;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
37 $args{hash} = $this->hash if $this->hash;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
38
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
39 if (@_) {
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
40 my $query = shift;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
41
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
42 $args{query} = ref $query eq 'HASH' ? hashMerge($this->query,$query) : $query;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
43 }
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
44
212
292226770180 bugfixes
sergey
parents: 211
diff changeset
45 return $this->new(%args);
211
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
46 }
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
47
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
48 sub SetView {
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
49 my ($this,$newView) = @_;
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
50
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
51 $this->view($newView);
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
52
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
53 return $this;
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
54 }
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
55
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
56 sub url {
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
57 my ($this) = @_;
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
58
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
59 my $url = URI->new($this->view ? $this->base . "." . $this->view : $this->base);
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
60 $url->query_form($this->query);
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
61 $url->fragment($this->hash);
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
62
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
63 return $url;
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
64 }
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
65
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
66 sub AUTOLOAD {
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
67 our $AUTOLOAD;
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
68
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
69 (my $method) = ($AUTOLOAD =~ m/(\w+)$/);
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
70
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
71 return if $method eq 'DESTROY';
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
72
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
73 my $this = shift;
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
74 return $this->Child($method,@_);
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
75 }
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
76
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
77
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
78
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
79 1;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
80
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
81 __END__
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
82
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
83 =head1 NAME
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
84
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
85 C<IMPL::Web::AutoLocator> - Обертка вокруг адреса ресурса.
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
86
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
87 =head1 SYNOPSIS
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
88
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
89 =begin code
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
90
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
91 use IMPL::require {
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
92 Locator => 'IMPL::Web::AutoLocator'
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
93 };
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
94
212
292226770180 bugfixes
sergey
parents: 211
diff changeset
95 my $bugTracker = Locator->new(base => "http://myhost.org/bugzilla")->SetView("cgi");
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
96
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
97 my $bug = $bugTracker->show_bug({id = 1});
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
98
212
292226770180 bugfixes
sergey
parents: 211
diff changeset
99 my $wikiPages = Locator->new(base => "http://myhost.org/wiki/bin/view");
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
100
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
101 my $page = $wiki->Main->HowTo;
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
102
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
103 my $images = Locator->new(base => "http://static.myhost.org/images", view => "png");
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
104
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
105 my $editIco = $images->icons->small->edit;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
106
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
107 =end code
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
108
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
109 =head1 DESCRIPTION
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents:
diff changeset
110
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
111 Для удобстав навигации по ресурсам, полностью отражает классическую структуру
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
112 иерархически организованных ресурсов. позволяет гибко работать с параметрами
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
113 запроса и хешем. Для постоты чтения реализует метод C<AUTOLOAD> для доступа
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
114 к дочерним ресурсам.
211
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
115
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
116 =head1 MEMBERS
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
117
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
118 =head2 C<CTOR(%args)>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
119
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
120 Создает новый объект расположение. Позволяет задать путь, расширение, параметры
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
121 запроса и фрагмент ресурса.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
122
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
123 =over
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
124
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
125 =item * C<base>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
126
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
127 Строка с базовым адресом для дочерних ресурсов.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
128
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
129 =item * C<view>
211
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
130
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
131 Задает суфикс, обозначающий представление ресурса, аналогично расширению у
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
132 файлов. Данный суффикс может использоваться контроллером для выбора
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
133 представления ресурса.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
134
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
135 =item * C<query>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
136
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
137 Ссылка на хеш с параметрами запроса
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
138
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
139 =item * C<hash>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
140
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
141 Часть C<uri> обозначающая фрагмент документа (все, что идет после символа C<#>).
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
142
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
143 =back
211
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
144
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
145 =head2 C<Child($child[,$query])>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
146
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
147 Получает расположение дочернего ресурса. При этом cоздается новый объект адреса ресурса.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
148
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
149 =head2 C<SetView($view)>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
150
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
151 Позволяет указать представление (расширение) у текущего адреса ресурса. Изменяет
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
152 представление и возвращает измененный адрес ресурса.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
153
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
154 =head2 C<[get]base>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
155
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
156 Базовый адрес, относительно которого будут получены дочерние ресурсы.
211
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
157
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
158 =head2 C<[get,set]view>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
159
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
160 Представление для ресурсов, аналогично расширению у файлов.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
161
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
162 =head2 C<[get,set]query>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
163
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
164 Ссылка на хеш с параметрами для C<GET> запроса.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
165
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
166 =head2 C<[get,set]hash>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
167
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
168 Часть адреса ресурса, отвечающая за фрагмент.
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
169
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
170 =head2 C<[get]url>
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
171
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
172 Объект C<URI> для текущего адреса.
211
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
173
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
174 =head2 C<AUTLOAD>
2b9b55cfb79b Completed IMPL::Web::AutoLocator, added tests
cin
parents: 210
diff changeset
175
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 212
diff changeset
176 Перенаправляет вызовы методов в метод C<Child> передавая первым параметром имя метода.
212
292226770180 bugfixes
sergey
parents: 211
diff changeset
177
292226770180 bugfixes
sergey
parents: 211
diff changeset
178 =cut
292226770180 bugfixes
sergey
parents: 211
diff changeset
179