Mercurial > pub > Impl
annotate Lib/IMPL/Web/Handler/TTView.pm @ 235:a4d9126edcbb
code cleaning
author | sergey |
---|---|
date | Fri, 12 Oct 2012 02:08:51 +0400 |
parents | 3cebcf6fdb9b |
children | abc7c26bf615 |
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 => { |
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 => [ |
233 | 18 contentType => PROP_RO, |
19 contentCharset => PROP_RO, | |
20 loader => PROP_RO, | |
21 selectors => PROP_RO | PROP_LIST, | |
22 defaultDocument => PROP_RW, | |
23 indexResource => PROP_RW, | |
24 _selectorsCache => PROP_RW, | |
25 _classTemplates => PROP_RW | |
229
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 | 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 = { |
235 | 41 model => $result, |
229
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, |
235 | 44 ImportClass => 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 | 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 | 107 } |
108 | |
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 | 116 } |
117 | |
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 | 167 } |
168 | |
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 | 172 my @next; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
173 |
203 | 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 | 177 my $context = { |
178 vars => \%{ $alt->{vars} || {} }, | |
179 selector => $match->{next} | |
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 | 183 $context->{immediate} = 1; |
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 | 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 | 193 $context->{success} = 1; |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
194 |
203 | 195 if ($name) { |
196 $context->{vars}->{$name} = \@captures; | |
197 } | |
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 | 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 | 204 $context->{success} = 1; |
205 } | |
206 } | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
207 |
203 | 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 | 212 # interpolate data |
213 $data =~ s/{(\w+)(?:\:(\d+))?}/ | |
214 my ($name,$index) = ($1,$2 || 0); | |
215 | |
216 if ($context->{vars}{$name}) { | |
217 $context->{vars}{$name}[$index]; | |
218 } else { | |
219 ""; | |
220 } | |
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 | 225 } |
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 | 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 | 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 | 237 } |
238 } | |
239 } | |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
206
diff
changeset
|
240 |
203 | 241 return \@next; |
242 } | |
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 | 258 <item id="html-view" type="IMPL::Web::Handler::TTView"> |
259 <contentType>text/html</contentType> | |
260 <loader id="tt-loader" type="IMPL::Web::View::TTLoader"> | |
261 <options type="HASH"> | |
262 <INCLUDE_PATH type="IMPL::Config::Reference"> | |
263 <target>IMPL::Config</target> | |
264 <AppBase>view</AppBase> | |
265 </INCLUDE_PATH> | |
266 <INTERPOLATE>1</INTERPOLATE> | |
267 <POST_CHOMP>1</POST_CHOMP> | |
268 <ENCODING>utf-8</ENCODING> | |
269 </options> | |
270 <ext>.tt</ext> | |
271 <initializer>global.tt</initializer> | |
272 <layoutBase>layouts</layoutBase> | |
273 </loader> | |
274 <defaultDocument>default</defaultDocument> | |
275 <selectors type="ARRAY"> | |
276 <item>@HASH => dump</item> | |
277 <item>@My::Data::Product => product/info</item> | |
278 <item>{action:.*} @My::Data::Product => product/{action}</item> | |
279 </selectors> | |
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 | 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 | 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 | 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 |