Mercurial > pub > Impl
annotate Lib/IMPL/Web/AutoLocator.pm @ 241:f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
*TTDocuments now storing creation parameters
*TTControls automatically propagating layout and title meta to their attributes
+Added UnauthorizaedException web exception
*minor fixes
author | sergey |
---|---|
date | Thu, 18 Oct 2012 04:49:55 +0400 |
parents | 5c82eec23bb6 |
children | a02b110da931 |
rev | line source |
---|---|
210 | 1 package IMPL::Web::AutoLocator; |
2 use strict; | |
3 | |
232 | 4 use IMPL::Const qw(:prop); |
5 use IMPL::lang qw( :hash ); | |
210 | 6 use URI; |
7 use URI::Escape; | |
8 use IMPL::declare { | |
9 require => { | |
10 Exception => 'IMPL::Exception', | |
11 ArgumentException => '-IMPL::InvalidArgumentException' | |
12 }, | |
13 base => [ | |
14 'IMPL::Object' => undef, | |
15 'IMPL::Object::Autofill' => '@_', | |
16 'IMPL::Object::Serializable' => '@_' | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
17 ], |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
18 props => [ |
232 | 19 base => PROP_RO, |
20 view => PROP_RW, | |
21 query => PROP_RW, | |
22 hash => PROP_RW | |
210 | 23 ] |
24 }; | |
25 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
26 sub Child { |
210 | 27 my $this = shift; |
211 | 28 my $child = shift or die ArgumentException->new("a child resource identifier is required"); |
29 die ArgumentException->new("a child resource can't be a reference") if ref $child; | |
210 | 30 |
31 # safe | |
32 $child = uri_escape($child); | |
33 | |
34 my %args; | |
35 | |
36 $args{base} = $this->base =~ /\/$/ ? $this->base . $child : $this->base . '/' . $child; | |
37 $args{view} = $this->view if $this->view; | |
38 $args{hash} = $this->hash if $this->hash; | |
39 | |
40 if (@_) { | |
41 my $query = shift; | |
42 | |
43 $args{query} = ref $query eq 'HASH' ? hashMerge($this->query,$query) : $query; | |
44 } | |
45 | |
212 | 46 return $this->new(%args); |
211 | 47 } |
48 | |
49 sub SetView { | |
50 my ($this,$newView) = @_; | |
51 | |
52 $this->view($newView); | |
53 | |
54 return $this; | |
55 } | |
56 | |
57 sub url { | |
58 my ($this) = @_; | |
59 | |
60 my $url = URI->new($this->view ? $this->base . "." . $this->view : $this->base); | |
61 $url->query_form($this->query); | |
62 $url->fragment($this->hash); | |
63 | |
64 return $url; | |
65 } | |
66 | |
67 sub AUTOLOAD { | |
68 our $AUTOLOAD; | |
69 | |
70 (my $method) = ($AUTOLOAD =~ m/(\w+)$/); | |
71 | |
72 return if $method eq 'DESTROY'; | |
73 | |
74 my $this = shift; | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
75 return $this->Child($method,@_); |
210 | 76 } |
77 | |
78 | |
79 | |
80 1; | |
81 | |
82 __END__ | |
83 | |
84 =head1 NAME | |
85 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
86 C<IMPL::Web::AutoLocator> - Обертка вокруг адреса ресурса. |
210 | 87 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
88 =head1 SYNOPSIS |
210 | 89 |
90 =begin code | |
91 | |
92 use IMPL::require { | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
93 Locator => 'IMPL::Web::AutoLocator' |
210 | 94 }; |
95 | |
212 | 96 my $bugTracker = Locator->new(base => "http://myhost.org/bugzilla")->SetView("cgi"); |
210 | 97 |
98 my $bug = $bugTracker->show_bug({id = 1}); | |
99 | |
212 | 100 my $wikiPages = Locator->new(base => "http://myhost.org/wiki/bin/view"); |
210 | 101 |
102 my $page = $wiki->Main->HowTo; | |
103 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
104 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
|
105 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
106 my $editIco = $images->icons->small->edit; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
107 |
210 | 108 =end code |
109 | |
110 =head1 DESCRIPTION | |
111 | |
229
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 иерархически организованных ресурсов. позволяет гибко работать с параметрами |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
114 запроса и хешем. Для постоты чтения реализует метод C<AUTOLOAD> для доступа |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
115 к дочерним ресурсам. |
211 | 116 |
117 =head1 MEMBERS | |
118 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
119 =head2 C<CTOR(%args)> |
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 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
124 =over |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
125 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
126 =item * C<base> |
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 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
130 =item * C<view> |
211 | 131 |
229
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 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
136 =item * C<query> |
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 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
140 =item * C<hash> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
141 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
142 Часть C<uri> обозначающая фрагмент документа (все, что идет после символа C<#>). |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
143 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
144 =back |
211 | 145 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
146 =head2 C<Child($child[,$query])> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
147 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
148 Получает расположение дочернего ресурса. При этом cоздается новый объект адреса ресурса. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
149 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
150 =head2 C<SetView($view)> |
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 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
155 =head2 C<[get]base> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
156 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
157 Базовый адрес, относительно которого будут получены дочерние ресурсы. |
211 | 158 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
159 =head2 C<[get,set]view> |
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 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
163 =head2 C<[get,set]query> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
164 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
165 Ссылка на хеш с параметрами для C<GET> запроса. |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
166 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
167 =head2 C<[get,set]hash> |
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 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
171 =head2 C<[get]url> |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
172 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
173 Объект C<URI> для текущего адреса. |
211 | 174 |
175 =head2 C<AUTLOAD> | |
176 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
212
diff
changeset
|
177 Перенаправляет вызовы методов в метод C<Child> передавая первым параметром имя метода. |
212 | 178 |
179 =cut | |
180 |