annotate Lib/IMPL/DOM/Transform/QueryToDOM.pm @ 237:61db68166c37

refactoring QueryToDOM
author sergey
date Mon, 15 Oct 2012 17:39:12 +0400
parents
children b8c724f6de36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
237
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
1 package IMPL::DOM::Transform::QueryToDOM;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
2 use strict;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
3
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
4 use IMPL::Const qw(:prop);
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
5 use IMPL::declare {
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
6 base => [
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
7 'IMPL::DOM::Transform::ObjectToDOM' => '@_'
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
8 ],
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
9 props => [
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
10 prefix => PROP_RO,
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
11 delimier => PROP_RO
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
12 ]
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
13 };
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
14
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
15 sub CTOR {
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
16 my ($this) = @_;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
17
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
18 $this->templates->{'CGI'} = \&TransformCGI;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
19 $this->templates->{'CGIWrapper'} = \&TransformCGI;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
20
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
21 $this->delimier('.');
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
22 }
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
23
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
24 sub TransformCGI {
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
25 my ($this,$query) = @_;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
26
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
27 my $data={};
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
28
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
29 my $prefix = $this->prefix;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
30 my $delim = $this->delimiter;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
31
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
32 foreach my $param (grep index($_,$prefix) >= 0 , $query->param()) {
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
33 length (my $value = $query->param($param)) or next;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
34
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
35 my @parts = split /\//,$param;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
36
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
37 my $node = $data;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
38 while ( my $part = shift @parts ) {
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
39 if (@parts) {
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
40 $node = ($node->{$part} ||= {});
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
41 } else {
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
42 $node->{$part} = $value;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
43 }
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
44 }
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
45 }
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
46
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
47 if (keys %$data > 1) {
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
48 $data = { document => $data };
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
49 }
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
50
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
51 return $this->Transform($data);
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
52 }