comparison Lib/IMPL/DOM/Transform/QueryToDOM.pm @ 238:b8c724f6de36

DOM model refactoring TT view refactoring, controls are no longer derived from DOM nodes bugfixes
author sergey
date Tue, 16 Oct 2012 01:33:06 +0400
parents 61db68166c37
children a02b110da931
comparison
equal deleted inserted replaced
237:61db68166c37 238:b8c724f6de36
6 base => [ 6 base => [
7 'IMPL::DOM::Transform::ObjectToDOM' => '@_' 7 'IMPL::DOM::Transform::ObjectToDOM' => '@_'
8 ], 8 ],
9 props => [ 9 props => [
10 prefix => PROP_RO, 10 prefix => PROP_RO,
11 delimier => PROP_RO 11 delimiter => PROP_RO
12 ] 12 ]
13 }; 13 };
14 14
15 sub CTOR { 15 sub CTOR {
16 my ($this) = @_; 16 my ($this) = @_;
17 17
18 $this->templates->{'CGI'} = \&TransformCGI; 18 $this->templates->{'CGI'} = \&TransformCGI;
19 $this->templates->{'CGIWrapper'} = \&TransformCGI; 19 $this->templates->{'CGIWrapper'} = \&TransformCGI;
20 20
21 $this->delimier('.'); 21 $this->delimiter('[.]');
22 $this->prefix('');
22 } 23 }
23 24
24 sub TransformCGI { 25 sub TransformCGI {
25 my ($this,$query) = @_; 26 my ($this,$query) = @_;
26 27
30 my $delim = $this->delimiter; 31 my $delim = $this->delimiter;
31 32
32 foreach my $param (grep index($_,$prefix) >= 0 , $query->param()) { 33 foreach my $param (grep index($_,$prefix) >= 0 , $query->param()) {
33 length (my $value = $query->param($param)) or next; 34 length (my $value = $query->param($param)) or next;
34 35
35 my @parts = split /\//,$param; 36 my @parts = split /$delim/,$param;
36 37
37 my $node = $data; 38 my $node = $data;
38 while ( my $part = shift @parts ) { 39 while ( my $part = shift @parts ) {
39 if (@parts) { 40 if (my ($name,$index) = ($part =~ m/^(\w+)(?:\[(\d+)\])?$/) ) {
40 $node = ($node->{$part} ||= {}); 41 if (@parts) {
41 } else { 42 if(defined $index) {
42 $node->{$part} = $value; 43 $node = ($node->{$name}[$index] ||= {});
44 } else {
45 $node = ($node->{$name} ||= {});
46 }
47 } else {
48 if(defined $index) {
49 $node->{$name}[$index] = $value;
50 } else {
51 $node->{$name} = $value;
52 }
53 }
43 } 54 }
44 } 55 }
45 } 56 }
46 57
47 if (keys %$data > 1) {
48 $data = { document => $data };
49 }
50
51 return $this->Transform($data); 58 return $this->Transform($data);
52 } 59 }
60
61 1;