Mercurial > pub > Impl
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 |
rev | line source |
---|---|
210 | 1 package IMPL::Web::AutoLocator; |
2 use strict; | |
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 | 5 use URI; |
6 use URI::Escape; | |
7 use IMPL::declare { | |
8 require => { | |
9 Exception => 'IMPL::Exception', | |
10 ArgumentException => '-IMPL::InvalidArgumentException' | |
11 }, | |
12 base => [ | |
13 'IMPL::Object' => undef, | |
14 'IMPL::Object::Autofill' => '@_', | |
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 | 22 ] |
23 }; | |
24 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
25 sub Child { |
210 | 26 my $this = shift; |
211 | 27 my $child = shift or die ArgumentException->new("a child resource identifier is required"); |
28 die ArgumentException->new("a child resource can't be a reference") if ref $child; | |
210 | 29 |
30 # safe | |
31 $child = uri_escape($child); | |
32 | |
33 my %args; | |
34 | |
35 $args{base} = $this->base =~ /\/$/ ? $this->base . $child : $this->base . '/' . $child; | |
36 $args{view} = $this->view if $this->view; | |
37 $args{hash} = $this->hash if $this->hash; | |
38 | |
39 if (@_) { | |
40 my $query = shift; | |
41 | |
42 $args{query} = ref $query eq 'HASH' ? hashMerge($this->query,$query) : $query; | |
43 } | |
44 | |
212 | 45 return $this->new(%args); |
211 | 46 } |
47 | |
48 sub SetView { | |
49 my ($this,$newView) = @_; | |
50 | |
51 $this->view($newView); | |
52 | |
53 return $this; | |
54 } | |
55 | |
56 sub url { | |
57 my ($this) = @_; | |
58 | |
59 my $url = URI->new($this->view ? $this->base . "." . $this->view : $this->base); | |
60 $url->query_form($this->query); | |
61 $url->fragment($this->hash); | |
62 | |
63 return $url; | |
64 } | |
65 | |
66 sub AUTOLOAD { | |
67 our $AUTOLOAD; | |
68 | |
69 (my $method) = ($AUTOLOAD =~ m/(\w+)$/); | |
70 | |
71 return if $method eq 'DESTROY'; | |
72 | |
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 | 75 } |
76 | |
77 | |
78 | |
79 1; | |
80 | |
81 __END__ | |
82 | |
83 =head1 NAME | |
84 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
85 C<IMPL::Web::AutoLocator> - Обертка вокруг адреса ресурса. |
210 | 86 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
87 =head1 SYNOPSIS |
210 | 88 |
89 =begin code | |
90 | |
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 | 93 }; |
94 | |
212 | 95 my $bugTracker = Locator->new(base => "http://myhost.org/bugzilla")->SetView("cgi"); |
210 | 96 |
97 my $bug = $bugTracker->show_bug({id = 1}); | |
98 | |
212 | 99 my $wikiPages = Locator->new(base => "http://myhost.org/wiki/bin/view"); |
210 | 100 |
101 my $page = $wiki->Main->HowTo; | |
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 | 107 =end code |
108 | |
109 =head1 DESCRIPTION | |
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 | 115 |
116 =head1 MEMBERS | |
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 | 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 | 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 | 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 | 173 |
174 =head2 C<AUTLOAD> | |
175 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
176 Перенаправляет вызовы методов в метод C<Child> передавая первым параметром имя метода. |
212 | 177 |
178 =cut | |
179 |