annotate Lib/IMPL/Web/Handler/TTView.pm @ 232:5c82eec23bb6

Fixed degradations due refactoring
author sergey
date Tue, 09 Oct 2012 20:12:47 +0400
parents 47f77e6409f7
children 3cebcf6fdb9b
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);
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
5 use IMPL::lang qw(:declare :constants);
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 => {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
8 Factory => 'IMPL::Object::Factory',
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
9 HttpResponse => 'IMPL::Web::HttpResponse'
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
10 },
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
11 base => [
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
12 'IMPL::Object' => undef,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
13 'IMPL::Object::Autofill' => '@_',
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
14 'IMPL::Object::Serializable' => undef
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
15 ],
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
16
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
17 props => [
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
18 contentType => PROP_GET | PROP_OWNERSET,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
19 contentCharset => PROP_GET | PROP_OWNERSET,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
20 loader => PROP_GET | PROP_OWNERSET,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
21 selectors => PROP_GET | PROP_LIST | PROP_OWNERSET,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
22 defaultDocument => PROP_ALL,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
23 indexResource => PROP_ALL,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
24 _selectorsCache => PROP_ALL,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
25 _classTemplates => PROP_ALL
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
26 ]
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
27 };
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
28
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
29 sub CTOR {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
30 my ($this) = @_;
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
31
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
32 $this->indexResource('index') unless $this->indexResource;
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
33 }
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
34
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
35 sub Invoke {
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
36 my ( $this, $action, $next ) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
37
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
38 my $result = $next ? $next->($action) : undef;
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 $vars = {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
41 data => $result,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
42 action => $action,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
43 app => $action->application,
205
891c04080658 IMPL::Web::View fixed template selection, release candidate
sergey
parents: 204
diff changeset
44 LoadFactory => sub {
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
45 my $class = shift;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
46
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
47 my $module = $class;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
48
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
49 $module =~ s/::/\//g;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
50 $module .= ".pm";
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
51
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
52 require $module;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
53 return Factory->new($class);
205
891c04080658 IMPL::Web::View fixed template selection, release candidate
sergey
parents: 204
diff changeset
54 }
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
55 };
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
56
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
57 my $doc =
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
58 $this->loader->document( $this->SelectView( $action, ref $result ),
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
59 $vars );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
60
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
61 return HttpResponse->new(
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
62 type => $this->contentType,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
63 charset => $this->contentCharset,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
64 body => $doc->Render($vars)
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
65 );
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
66 }
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
67
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
68 sub SelectView {
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
69 my ( $this, $action, $class ) = @_;
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 my @path = split /\//, $action->query->path_info(), -1;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
72
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
73 shift @path; # remove always empty leading segment
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
74
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
75 my $last = pop @path;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
76 $last =~ s/\.\w+$//;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
77 $last ||= $this->indexResource;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
78 push @path, $last;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
79
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
80 $this->BuildCache unless $this->_selectorsCache;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
81 my $cache = $this->_selectorsCache;
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 @path = reverse @path;
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 foreach
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
86 my $subclass ( $class ? ( _GetHierarchy($class), '-default' ) : '-plain' )
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
87 {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
88 my @results;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
89 push @results,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
90 { result => $this->_classTemplates->{$subclass}, level => 0 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
91 if $this->_classTemplates->{$subclass};
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
92 if ( $cache->{$subclass} ) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
93 my $alternatives =
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
94 [ { selector => $cache->{$subclass}, immediate => 1 } ];
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
95 $alternatives =
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
96 $this->MatchAlternatives( $_, $alternatives, \@results )
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
97 foreach @path;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
98 }
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 if (@results) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
101 @results = sort { $b->{level} <=> $a->{level} } @results;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
102 return ( shift @results )->{result};
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
103 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
104 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
105
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
106 return $this->defaultDocument;
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
107 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
108
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
109 sub _GetHierarchy {
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
110 my ($class) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
111 return unless $class;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
112
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
113 no strict 'refs';
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 return $class, map { _GetHierarchy($_) } @{"${class}::ISA"};
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
116 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
117
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
118 sub BuildCache {
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
119 my ($this) = @_;
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 my @selectors;
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 my $cache = $this->_selectorsCache( {} );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
124 $this->_classTemplates( {} );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
125
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
126 foreach my $selector ( $this->selectors ) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
127 if ( not ref $selector ) {
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 my ( $path, $data ) = split( /\s*=>\s*/, $selector );
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 @path = split( /\s+/, $path );
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 $class;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
134
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
135 # if this selector has a class part
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
136 if ( $path[$#path] =~ m/^\@(.*)/ ) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
137 $class = $1;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
138 pop @path;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
139 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
140 else {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
141 $class = '-default';
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
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
144 #if this selector has a path
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
145 if (@path) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
146 @path = reverse @path;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
147 my $last = pop @path;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
148 my $t = ( $cache->{$class} ||= {} );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
149 my $level = 1;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
150 foreach my $prim (@path) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
151 $t = ( $t->{$prim}->{next} ||= {} );
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
152 $level++;
204
d63f9a92d6d4 +IMPL::Config::Include - simple way to include external config
sergey
parents: 203
diff changeset
153 }
d63f9a92d6d4 +IMPL::Config::Include - simple way to include external config
sergey
parents: 203
diff changeset
154 $t->{$last}->{level} = $level;
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
155 $t->{$last}->{data} = $data;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
156
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
157 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
158 else {
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 # we dont have a selector, only class
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
161
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
162 $this->_classTemplates->{$class} = $data;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
163 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
164
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
165 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
166 }
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
167 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
168
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
169 sub MatchAlternatives {
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
170 my ( $this, $segment, $alternatives, $results ) = @_;
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
171
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
172 my @next;
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
173
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
174 foreach my $alt (@$alternatives) {
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
175 while ( my ( $selector, $match ) = each %{ $alt->{selector} } ) {
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 my $context = {
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
178 vars => \%{ $alt->{vars} || {} },
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
179 selector => $match->{next}
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
180 };
229
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 if ( $selector =~ s/^>// ) {
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
183 $context->{immediate} = 1;
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
184 }
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
185
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
186 if ( my ( $name, $rx ) =
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
187 ( $selector =~ m/^\{(?:(\w+)\:)?(.*)\}$/ ) )
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
188 {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
189
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
190 #this is a regexp
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 ( my @captures = ( $segment =~ m/($rx)/ ) ) {
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
193 $context->{success} = 1;
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
194
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
195 if ($name) {
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
196 $context->{vars}->{$name} = \@captures;
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
197 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
198 }
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
199 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
200 else {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
201
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
202 #this is a segment name
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
203 if ( $segment eq $selector ) {
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
204 $context->{success} = 1;
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
205 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
206 }
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
207
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
208 # test if there were a match
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
209 if ( delete $context->{success} ) {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
210 if ( my $data = $match->{data} ) {
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 # interpolate data
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
213 $data =~ s/{(\w+)(?:\:(\d+))?}/
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
214 my ($name,$index) = ($1,$2 || 0);
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
215
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
216 if ($context->{vars}{$name}) {
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
217 $context->{vars}{$name}[$index];
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
218 } else {
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
219 "";
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
220 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
221 /gex;
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
222
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
223 push @$results,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
224 { level => $match->{level}, result => $data };
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
225 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
226 push @next, $context if $context->{selector};
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
227 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
228 else {
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
229
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
230 #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
231 push @next,
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
232 {
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
233 selector => { $selector, $match },
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
234 vars => $alt->{vars}
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
235 }
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
236 unless $alt->{immediate};
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
237 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
238 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
239 }
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
240
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
241 return \@next;
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
242 }
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
243
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
244 1;
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
245
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
246 __END__
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
247
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
248 =pod
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
249
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
250 =head1 NAME
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
251
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
252 C<IMPL::Web::Handler::TTView> - использует шаблоны для построения представления.
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
253
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
254 =head1 SYNOPSIS
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 =begin code xml
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
257
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
258 <item id="html-view" type="IMPL::Web::Handler::TTView">
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
259 <contentType>text/html</contentType>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
260 <loader id="tt-loader" type="IMPL::Web::View::TTLoader">
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
261 <options type="HASH">
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
262 <INCLUDE_PATH type="IMPL::Config::Reference">
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
263 <target>IMPL::Config</target>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
264 <AppBase>view</AppBase>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
265 </INCLUDE_PATH>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
266 <INTERPOLATE>1</INTERPOLATE>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
267 <POST_CHOMP>1</POST_CHOMP>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
268 <ENCODING>utf-8</ENCODING>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
269 </options>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
270 <ext>.tt</ext>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
271 <initializer>global.tt</initializer>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
272 <layoutBase>layouts</layoutBase>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
273 </loader>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
274 <defaultDocument>default</defaultDocument>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
275 <selectors type="ARRAY">
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
276 <item>@HASH => dump</item>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
277 <item>@My::Data::Product => product/info</item>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
278 <item>{action:.*} @My::Data::Product => product/{action}</item>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
279 </selectors>
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
280 </item>
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
281
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
282 =end code xml
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
283
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
284 =head1 DESCRIPTION
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
285
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
286 Подбирает шаблон для представления результата, полученного при выполнении следующего обработчика. При
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
287 выборе используется принцип похожий на селекторы C<CSS>, основывающийся на именах ресурсов и их типах
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
288 данных.
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
289
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
290 =head1 SELECTORS
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 =begin text
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 [url-template] [class] => template
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
295
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
296 shoes => product/list
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
297 {action:*.} @My::Data::Product => product/{action}
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
298
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 205
diff changeset
299 stuff >list => product/list
204
d63f9a92d6d4 +IMPL::Config::Include - simple way to include external config
sergey
parents: 203
diff changeset
300 details => product/details
203
68a59c3358ff Implemented templates selection mechanism
sergey
parents: 200
diff changeset
301
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
302 =end 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
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
305 =cut
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents:
diff changeset
306