Mercurial > pub > Impl
annotate Lib/IMPL/Web/Handler/TTView.pm @ 280:c6d0f889ef87
+IMPL::declare now supports meta attributes
*bugfixes related to the typeof() operator
author | cin |
---|---|
date | Wed, 06 Feb 2013 02:15:48 +0400 |
parents | 89179bb8c388 |
children | a8dbddf491dd |
rev | line source |
---|---|
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
1 package IMPL::Web::Handler::TTView; |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
2 use strict; |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
3 |
204
d63f9a92d6d4
+IMPL::Config::Include - simple way to include external config
sergey
parents:
203
diff
changeset
|
4 use List::Util qw(first); |
233 | 5 use IMPL::Const qw(:prop); |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
6 use IMPL::declare { |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
7 require => { |
240
abc7c26bf615
+Added ObjectFactory for templates with static members support
sergey
parents:
235
diff
changeset
|
8 Factory => 'IMPL::Web::View::ObjectFactory', |
241
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
9 HttpResponse => 'IMPL::Web::HttpResponse', |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
10 Loader => 'IMPL::Code::Loader', |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
11 ViewResult => '-IMPL::Web::ViewResult' |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
12 }, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
13 base => [ |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
14 'IMPL::Object' => undef, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
15 'IMPL::Object::Autofill' => '@_', |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
16 'IMPL::Object::Serializable' => undef |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
17 ], |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
18 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
19 props => [ |
233 | 20 contentType => PROP_RO, |
21 contentCharset => PROP_RO, | |
22 loader => PROP_RO, | |
23 selectors => PROP_RO | PROP_LIST, | |
24 defaultDocument => PROP_RW, | |
25 indexResource => PROP_RW, | |
26 _selectorsCache => PROP_RW, | |
27 _classTemplates => PROP_RW | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
28 ] |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
29 }; |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
30 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
31 sub CTOR { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
32 my ($this) = @_; |
203 | 33 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
34 $this->indexResource('index') unless $this->indexResource; |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
35 } |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
36 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
37 sub Invoke { |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
38 my ( $this, $action, $next ) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
39 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
40 my $result = $next ? $next->($action) : undef; |
241
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
41 |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
42 my ($model,$view); |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
43 if( ref $result and eval { $result->isa(ViewResult) } ) { |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
44 $model = $result->model; |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
45 $view = $result; |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
46 } else { |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
47 $model = $result; |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
48 $view = ViewResult->new(model => $model); |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
49 } |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
50 |
244 | 51 $view->location($action->context->{resourceLocation}) unless $view->location; |
52 | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
53 my $vars = { |
241
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
54 view => $view, |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
55 model => $model, |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
56 action => $action, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
57 app => $action->application, |
235 | 58 ImportClass => sub { |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
59 my $class = shift; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
60 |
241
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
61 $class = Loader->safe->Require($class); |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
62 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
63 return Factory->new($class); |
205
891c04080658
IMPL::Web::View fixed template selection, release candidate
sergey
parents:
204
diff
changeset
|
64 } |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
65 }; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
66 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
67 my $doc = |
256
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
244
diff
changeset
|
68 $this->loader->document( eval { $view->template } || $this->SelectView( $action, ref $model ), |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
69 $vars ); |
256
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
244
diff
changeset
|
70 |
266
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
71 $doc->location($action->context->{resourceLocation}); |
256
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
244
diff
changeset
|
72 |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
244
diff
changeset
|
73 my %responseParams = ( |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
74 type => $this->contentType, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
75 charset => $this->contentCharset, |
241
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
240
diff
changeset
|
76 body => $doc->Render() |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
77 ); |
256
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
244
diff
changeset
|
78 |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
244
diff
changeset
|
79 $responseParams{status} = $view->status if $view->status; |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
244
diff
changeset
|
80 $responseParams{cookies} = $view->cookies if ref $view->cookies eq 'HASH'; |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
244
diff
changeset
|
81 $responseParams{headers} = $view->headers if ref $view->headers eq 'HASH'; |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
244
diff
changeset
|
82 |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
244
diff
changeset
|
83 return HttpResponse->new( |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
244
diff
changeset
|
84 %responseParams |
32aceba4ee6d
corrected ViewHandlers to handle cookies and headers.
sergey
parents:
244
diff
changeset
|
85 ); |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
86 } |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
87 |
203 | 88 sub SelectView { |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
89 my ( $this, $action, $class ) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
90 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
91 my @path = split /\//, $action->query->path_info(), -1; |
266
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
92 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
93 shift @path; # remove always empty leading segment |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
94 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
95 $this->BuildCache unless $this->_selectorsCache; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
96 my $cache = $this->_selectorsCache; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
97 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
98 @path = reverse @path; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
99 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
100 foreach |
266
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
101 my $subclass ( $class ? ( _GetHierarchy($class), '-default' ) : '-default' ) |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
102 { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
103 my @results; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
104 push @results, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
105 { result => $this->_classTemplates->{$subclass}, level => 0 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
106 if $this->_classTemplates->{$subclass}; |
266
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
107 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
108 if ( $cache->{$subclass} ) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
109 my $alternatives = |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
110 [ { selector => $cache->{$subclass}, immediate => 1 } ]; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
111 $alternatives = |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
112 $this->MatchAlternatives( $_, $alternatives, \@results ) |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
113 foreach @path; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
114 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
115 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
116 if (@results) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
117 @results = sort { $b->{level} <=> $a->{level} } @results; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
118 return ( shift @results )->{result}; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
119 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
120 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
121 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
122 return $this->defaultDocument; |
203 | 123 } |
124 | |
125 sub _GetHierarchy { | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
126 my ($class) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
127 return unless $class; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
128 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
129 no strict 'refs'; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
130 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
131 return $class, map { _GetHierarchy($_) } @{"${class}::ISA"}; |
203 | 132 } |
133 | |
134 sub BuildCache { | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
135 my ($this) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
136 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
137 my @selectors; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
138 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
139 my $cache = $this->_selectorsCache( {} ); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
140 $this->_classTemplates( {} ); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
141 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
142 foreach my $selector ( $this->selectors ) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
143 if ( not ref $selector ) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
144 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
145 my ( $path, $data ) = split( /\s*=>\s*/, $selector ); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
146 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
147 my @path = split( /\s+/, $path ); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
148 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
149 my $class; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
150 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
151 # if this selector has a class part |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
152 if ( $path[$#path] =~ m/^\@(.*)/ ) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
153 $class = $1; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
154 pop @path; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
155 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
156 else { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
157 $class = '-default'; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
158 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
159 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
160 #if this selector has a path |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
161 if (@path) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
162 @path = reverse @path; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
163 my $last = pop @path; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
164 my $t = ( $cache->{$class} ||= {} ); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
165 my $level = 1; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
166 foreach my $prim (@path) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
167 $t = ( $t->{$prim}->{next} ||= {} ); |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
168 $level++; |
204
d63f9a92d6d4
+IMPL::Config::Include - simple way to include external config
sergey
parents:
203
diff
changeset
|
169 } |
d63f9a92d6d4
+IMPL::Config::Include - simple way to include external config
sergey
parents:
203
diff
changeset
|
170 $t->{$last}->{level} = $level; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
171 $t->{$last}->{data} = $data; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
172 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
173 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
174 else { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
175 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
176 # we dont have a selector, only class |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
177 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
178 $this->_classTemplates->{$class} = $data; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
179 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
180 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
181 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
182 } |
203 | 183 } |
184 | |
185 sub MatchAlternatives { | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
186 my ( $this, $segment, $alternatives, $results ) = @_; |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
187 |
203 | 188 my @next; |
266
89179bb8c388
*corrected TTView to handle plain (and undefined) values
cin
parents:
256
diff
changeset
|
189 |
203 | 190 foreach my $alt (@$alternatives) { |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
191 while ( my ( $selector, $match ) = each %{ $alt->{selector} } ) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
192 |
203 | 193 my $context = { |
194 vars => \%{ $alt->{vars} || {} }, | |
195 selector => $match->{next} | |
196 }; | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
197 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
198 if ( $selector =~ s/^>// ) { |
203 | 199 $context->{immediate} = 1; |
200 } | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
201 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
202 if ( my ( $name, $rx ) = |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
203 ( $selector =~ m/^\{(?:(\w+)\:)?(.*)\}$/ ) ) |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
204 { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
205 |
203 | 206 #this is a regexp |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
207 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
208 if ( my @captures = ( $segment =~ m/($rx)/ ) ) { |
203 | 209 $context->{success} = 1; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
210 |
203 | 211 if ($name) { |
212 $context->{vars}->{$name} = \@captures; | |
213 } | |
214 } | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
215 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
216 else { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
217 |
203 | 218 #this is a segment name |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
219 if ( $segment eq $selector ) { |
203 | 220 $context->{success} = 1; |
221 } | |
222 } | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
223 |
203 | 224 # test if there were a match |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
225 if ( delete $context->{success} ) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
226 if ( my $data = $match->{data} ) { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
227 |
203 | 228 # interpolate data |
229 $data =~ s/{(\w+)(?:\:(\d+))?}/ | |
230 my ($name,$index) = ($1,$2 || 0); | |
231 | |
232 if ($context->{vars}{$name}) { | |
233 $context->{vars}{$name}[$index]; | |
234 } else { | |
235 ""; | |
236 } | |
237 /gex; | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
238 |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
239 push @$results, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
240 { level => $match->{level}, result => $data }; |
203 | 241 } |
242 push @next, $context if $context->{selector}; | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
243 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
244 else { |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
245 |
203 | 246 #repeat current alternative if it's not required to be immediate |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
247 push @next, |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
248 { |
203 | 249 selector => { $selector, $match }, |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
250 vars => $alt->{vars} |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
251 } |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
252 unless $alt->{immediate}; |
203 | 253 } |
254 } | |
255 } | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
256 |
203 | 257 return \@next; |
258 } | |
259 | |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
260 1; |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
261 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
262 __END__ |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
263 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
264 =pod |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
265 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
266 =head1 NAME |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
267 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
268 C<IMPL::Web::Handler::TTView> - использует шаблоны для построения представления. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
269 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
270 =head1 SYNOPSIS |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
271 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
272 =begin code xml |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
273 |
206 | 274 <item id="html-view" type="IMPL::Web::Handler::TTView"> |
275 <contentType>text/html</contentType> | |
276 <loader id="tt-loader" type="IMPL::Web::View::TTLoader"> | |
277 <options type="HASH"> | |
278 <INCLUDE_PATH type="IMPL::Config::Reference"> | |
279 <target>IMPL::Config</target> | |
280 <AppBase>view</AppBase> | |
281 </INCLUDE_PATH> | |
282 <INTERPOLATE>1</INTERPOLATE> | |
283 <POST_CHOMP>1</POST_CHOMP> | |
284 <ENCODING>utf-8</ENCODING> | |
285 </options> | |
286 <ext>.tt</ext> | |
287 <initializer>global.tt</initializer> | |
288 <layoutBase>layouts</layoutBase> | |
289 </loader> | |
290 <defaultDocument>default</defaultDocument> | |
291 <selectors type="ARRAY"> | |
292 <item>@HASH => dump</item> | |
293 <item>@My::Data::Product => product/info</item> | |
294 <item>{action:.*} @My::Data::Product => product/{action}</item> | |
295 </selectors> | |
296 </item> | |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
297 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
298 =end code xml |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
299 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
300 =head1 DESCRIPTION |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
301 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
302 Подбирает шаблон для представления результата, полученного при выполнении следующего обработчика. При |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
303 выборе используется принцип похожий на селекторы C<CSS>, основывающийся на именах ресурсов и их типах |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
304 данных. |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
305 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
306 =head1 SELECTORS |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
307 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
308 =begin text |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
309 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
310 [url-template] [class] => template |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
311 |
206 | 312 shoes => product/list |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
313 {action:*.} @My::Data::Product => product/{action} |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
314 |
206 | 315 stuff >list => product/list |
204
d63f9a92d6d4
+IMPL::Config::Include - simple way to include external config
sergey
parents:
203
diff
changeset
|
316 details => product/details |
203 | 317 |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
318 =end text |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
319 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
320 |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
321 =cut |
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
diff
changeset
|
322 |