237
|
1 package IMPL::DOM::Transform::QueryToDOM;
|
|
2 use strict;
|
|
3
|
|
4 use IMPL::Const qw(:prop);
|
|
5 use IMPL::declare {
|
|
6 base => [
|
|
7 'IMPL::DOM::Transform::ObjectToDOM' => '@_'
|
|
8 ],
|
|
9 props => [
|
|
10 prefix => PROP_RO,
|
238
|
11 delimiter => PROP_RO
|
237
|
12 ]
|
|
13 };
|
|
14
|
|
15 sub CTOR {
|
|
16 my ($this) = @_;
|
|
17
|
|
18 $this->templates->{'CGI'} = \&TransformCGI;
|
244
|
19
|
238
|
20 $this->delimiter('[.]');
|
|
21 $this->prefix('');
|
237
|
22 }
|
|
23
|
|
24 sub TransformCGI {
|
|
25 my ($this,$query) = @_;
|
|
26
|
|
27 my $data={};
|
|
28
|
|
29 my $prefix = $this->prefix;
|
|
30 my $delim = $this->delimiter;
|
|
31
|
|
32 foreach my $param (grep index($_,$prefix) >= 0 , $query->param()) {
|
244
|
33
|
|
34 my @value = grep length($_), $query->param($param) or next;
|
237
|
35
|
238
|
36 my @parts = split /$delim/,$param;
|
237
|
37
|
|
38 my $node = $data;
|
|
39 while ( my $part = shift @parts ) {
|
238
|
40 if (my ($name,$index) = ($part =~ m/^(\w+)(?:\[(\d+)\])?$/) ) {
|
|
41 if (@parts) {
|
|
42 if(defined $index) {
|
|
43 $node = ($node->{$name}[$index] ||= {});
|
|
44 } else {
|
|
45 $node = ($node->{$name} ||= {});
|
|
46 }
|
|
47 } else {
|
|
48 if(defined $index) {
|
244
|
49 $node->{$name}[$index] = (@value == 1 ? $value[0] : \@value);
|
238
|
50 } else {
|
244
|
51 $node->{$name} = (@value == 1 ? $value[0] : \@value);
|
238
|
52 }
|
|
53 }
|
237
|
54 }
|
|
55 }
|
|
56 }
|
|
57
|
|
58 return $this->Transform($data);
|
238
|
59 }
|
|
60
|
|
61 1; |