comparison Lib/IMPL/DOM/Transform/QueryToDOM.pm @ 244:a02b110da931

refactoring fixed binding to CGI query parameters with multiple values
author sergey
date Mon, 22 Oct 2012 04:09:27 +0400
parents b8c724f6de36
children 129e48bb5afb
comparison
equal deleted inserted replaced
243:cd2b1f121029 244:a02b110da931
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
20
21 $this->delimiter('[.]'); 20 $this->delimiter('[.]');
22 $this->prefix(''); 21 $this->prefix('');
23 } 22 }
24 23
25 sub TransformCGI { 24 sub TransformCGI {
29 28
30 my $prefix = $this->prefix; 29 my $prefix = $this->prefix;
31 my $delim = $this->delimiter; 30 my $delim = $this->delimiter;
32 31
33 foreach my $param (grep index($_,$prefix) >= 0 , $query->param()) { 32 foreach my $param (grep index($_,$prefix) >= 0 , $query->param()) {
34 length (my $value = $query->param($param)) or next; 33
34 my @value = grep length($_), $query->param($param) or next;
35 35
36 my @parts = split /$delim/,$param; 36 my @parts = split /$delim/,$param;
37 37
38 my $node = $data; 38 my $node = $data;
39 while ( my $part = shift @parts ) { 39 while ( my $part = shift @parts ) {
44 } else { 44 } else {
45 $node = ($node->{$name} ||= {}); 45 $node = ($node->{$name} ||= {});
46 } 46 }
47 } else { 47 } else {
48 if(defined $index) { 48 if(defined $index) {
49 $node->{$name}[$index] = $value; 49 $node->{$name}[$index] = (@value == 1 ? $value[0] : \@value);
50 } else { 50 } else {
51 $node->{$name} = $value; 51 $node->{$name} = (@value == 1 ? $value[0] : \@value);
52 } 52 }
53 } 53 }
54 } 54 }
55 } 55 }
56 } 56 }