annotate Lib/IMPL/Web/Handler/TTView.pm @ 245:7c517134c42f

Added Unsupported media type Web exception corrected resourceLocation setting in the resource Implemented localizable resources for text messages fixed TT view scopings, INIT block in controls now sets globals correctly.
author sergey
date Mon, 29 Oct 2012 03:15:22 +0400
parents a02b110da931
children 32aceba4ee6d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 229
diff changeset
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
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 229
diff changeset
20 contentType => PROP_RO,
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 229
diff changeset
21 contentCharset => PROP_RO,
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 229
diff changeset
22 loader => PROP_RO,
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 229
diff changeset
23 selectors => PROP_RO | PROP_LIST,
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 229
diff changeset
24 defaultDocument => PROP_RW,
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 229
diff changeset
25 indexResource => PROP_RW,
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 229
diff changeset
26 _selectorsCache => PROP_RW,
3cebcf6fdb9b refactoring, cleaning code
sergey
parents: 229
diff changeset
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
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
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
a02b110da931 refactoring
sergey
parents: 243
diff changeset
51 $view->location($action->context->{resourceLocation}) unless $view->location;
a02b110da931 refactoring
sergey
parents: 243
diff changeset
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
a4d9126edcbb code cleaning
sergey
parents: 233
diff changeset
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 =
243
cd2b1f121029 *TTView: fixed template selection based on the model type
sergey
parents: 241
diff changeset
68 $this->loader->document( $this->SelectView( $action, ref $model ),
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
69 $vars );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
70
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
71 return HttpResponse->new(
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
72 type => $this->contentType,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
73 charset => $this->contentCharset,
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 240
diff changeset
74 body => $doc->Render()
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
75 );
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
76 }
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
77
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
78 sub SelectView {
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
79 my ( $this, $action, $class ) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
80
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
81 my @path = split /\//, $action->query->path_info(), -1;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
82
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
83 shift @path; # remove always empty leading segment
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
84
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
85 my $last = pop @path;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
86 $last =~ s/\.\w+$//;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
87 $last ||= $this->indexResource;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
88 push @path, $last;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
89
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
90 $this->BuildCache unless $this->_selectorsCache;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
91 my $cache = $this->_selectorsCache;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
92
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
93 @path = reverse @path;
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 foreach
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
96 my $subclass ( $class ? ( _GetHierarchy($class), '-default' ) : '-plain' )
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 my @results;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
99 push @results,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
100 { result => $this->_classTemplates->{$subclass}, level => 0 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
101 if $this->_classTemplates->{$subclass};
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
102 if ( $cache->{$subclass} ) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
103 my $alternatives =
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
104 [ { selector => $cache->{$subclass}, immediate => 1 } ];
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
105 $alternatives =
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
106 $this->MatchAlternatives( $_, $alternatives, \@results )
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
107 foreach @path;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
108 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
109
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
110 if (@results) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
111 @results = sort { $b->{level} <=> $a->{level} } @results;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
112 return ( shift @results )->{result};
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
113 }
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 return $this->defaultDocument;
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
117 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
118
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
119 sub _GetHierarchy {
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
120 my ($class) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
121 return unless $class;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
122
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
123 no strict 'refs';
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
124
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
125 return $class, map { _GetHierarchy($_) } @{"${class}::ISA"};
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
126 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
127
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
128 sub BuildCache {
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
129 my ($this) = @_;
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 my @selectors;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
132
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
133 my $cache = $this->_selectorsCache( {} );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
134 $this->_classTemplates( {} );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
135
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
136 foreach my $selector ( $this->selectors ) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
137 if ( not ref $selector ) {
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 ( $path, $data ) = split( /\s*=>\s*/, $selector );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
140
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
141 my @path = split( /\s+/, $path );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
142
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
143 my $class;
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 # if this selector has a class part
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
146 if ( $path[$#path] =~ m/^\@(.*)/ ) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
147 $class = $1;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
148 pop @path;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
149 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
150 else {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
151 $class = '-default';
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
152 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
153
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
154 #if this selector has a path
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
155 if (@path) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
156 @path = reverse @path;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
157 my $last = pop @path;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
158 my $t = ( $cache->{$class} ||= {} );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
159 my $level = 1;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
160 foreach my $prim (@path) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
161 $t = ( $t->{$prim}->{next} ||= {} );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
162 $level++;
204
d63f9a92d6d4 +IMPL::Config::Include - simple way to include external config
sergey
parents: 203
diff changeset
163 }
d63f9a92d6d4 +IMPL::Config::Include - simple way to include external config
sergey
parents: 203
diff changeset
164 $t->{$last}->{level} = $level;
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
165 $t->{$last}->{data} = $data;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
166
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
167 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
168 else {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
169
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
170 # we dont have a selector, only class
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
171
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
172 $this->_classTemplates->{$class} = $data;
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
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 }
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
177 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
178
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
179 sub MatchAlternatives {
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
180 my ( $this, $segment, $alternatives, $results ) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
181
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
182 my @next;
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
183
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
184 foreach my $alt (@$alternatives) {
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
185 while ( my ( $selector, $match ) = each %{ $alt->{selector} } ) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
186
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
187 my $context = {
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
188 vars => \%{ $alt->{vars} || {} },
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
189 selector => $match->{next}
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
190 };
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
191
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
192 if ( $selector =~ s/^>// ) {
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
193 $context->{immediate} = 1;
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
194 }
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
195
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
196 if ( my ( $name, $rx ) =
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
197 ( $selector =~ m/^\{(?:(\w+)\:)?(.*)\}$/ ) )
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
198 {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
199
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
200 #this is a regexp
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 @captures = ( $segment =~ m/($rx)/ ) ) {
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
203 $context->{success} = 1;
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
204
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
205 if ($name) {
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
206 $context->{vars}->{$name} = \@captures;
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
207 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
208 }
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
209 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
210 else {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
211
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
212 #this is a segment name
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
213 if ( $segment eq $selector ) {
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
214 $context->{success} = 1;
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
215 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
216 }
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
217
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
218 # test if there were a match
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
219 if ( delete $context->{success} ) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
220 if ( my $data = $match->{data} ) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
221
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
222 # interpolate data
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
223 $data =~ s/{(\w+)(?:\:(\d+))?}/
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
224 my ($name,$index) = ($1,$2 || 0);
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
225
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
226 if ($context->{vars}{$name}) {
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
227 $context->{vars}{$name}[$index];
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
228 } else {
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
229 "";
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
230 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
231 /gex;
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
232
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
233 push @$results,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
234 { level => $match->{level}, result => $data };
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
235 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
236 push @next, $context if $context->{selector};
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
237 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
238 else {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
239
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
240 #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
241 push @next,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
242 {
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
243 selector => { $selector, $match },
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
244 vars => $alt->{vars}
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
245 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
246 unless $alt->{immediate};
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
247 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
248 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
249 }
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
250
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
251 return \@next;
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
252 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
253
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
254 1;
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
255
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
256 __END__
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
257
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
258 =pod
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
259
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
260 =head1 NAME
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 C<IMPL::Web::Handler::TTView> - использует шаблоны для построения представления.
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 =head1 SYNOPSIS
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 =begin code xml
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
267
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
268 <item id="html-view" type="IMPL::Web::Handler::TTView">
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
269 <contentType>text/html</contentType>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
270 <loader id="tt-loader" type="IMPL::Web::View::TTLoader">
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
271 <options type="HASH">
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
272 <INCLUDE_PATH type="IMPL::Config::Reference">
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
273 <target>IMPL::Config</target>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
274 <AppBase>view</AppBase>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
275 </INCLUDE_PATH>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
276 <INTERPOLATE>1</INTERPOLATE>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
277 <POST_CHOMP>1</POST_CHOMP>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
278 <ENCODING>utf-8</ENCODING>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
279 </options>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
280 <ext>.tt</ext>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
281 <initializer>global.tt</initializer>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
282 <layoutBase>layouts</layoutBase>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
283 </loader>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
284 <defaultDocument>default</defaultDocument>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
285 <selectors type="ARRAY">
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
286 <item>@HASH => dump</item>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
287 <item>@My::Data::Product => product/info</item>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
288 <item>{action:.*} @My::Data::Product => product/{action}</item>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
289 </selectors>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
290 </item>
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
291
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
292 =end code xml
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
293
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
294 =head1 DESCRIPTION
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
295
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
296 Подбирает шаблон для представления результата, полученного при выполнении следующего обработчика. При
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
297 выборе используется принцип похожий на селекторы C<CSS>, основывающийся на именах ресурсов и их типах
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
298 данных.
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 SELECTORS
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 =begin text
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
303
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
304 [url-template] [class] => template
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
305
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
306 shoes => product/list
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
307 {action:*.} @My::Data::Product => product/{action}
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
308
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
309 stuff >list => product/list
204
d63f9a92d6d4 +IMPL::Config::Include - simple way to include external config
sergey
parents: 203
diff changeset
310 details => product/details
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
311
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
312 =end text
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
313
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
314
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
315 =cut
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
316