annotate Lib/IMPL/DOM/Transform/QueryToDOM.pm @ 239:23daf2fae33a

*security subsytem bugfixes *HttpResponse: cookies which values are set to undefined will be deleted from browser
author sergey
date Tue, 16 Oct 2012 20:14:11 +0400
parents b8c724f6de36
children a02b110da931
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,
238
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
11 delimiter => PROP_RO
237
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
238
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
21 $this->delimiter('[.]');
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
22 $this->prefix('');
237
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
23 }
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
24
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
25 sub TransformCGI {
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
26 my ($this,$query) = @_;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
27
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
28 my $data={};
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
29
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
30 my $prefix = $this->prefix;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
31 my $delim = $this->delimiter;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
32
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
33 foreach my $param (grep index($_,$prefix) >= 0 , $query->param()) {
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
34 length (my $value = $query->param($param)) or next;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
35
238
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
36 my @parts = split /$delim/,$param;
237
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
37
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
38 my $node = $data;
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
39 while ( my $part = shift @parts ) {
238
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
40 if (my ($name,$index) = ($part =~ m/^(\w+)(?:\[(\d+)\])?$/) ) {
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
41 if (@parts) {
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
42 if(defined $index) {
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
43 $node = ($node->{$name}[$index] ||= {});
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
44 } else {
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
45 $node = ($node->{$name} ||= {});
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
46 }
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
47 } else {
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
48 if(defined $index) {
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
49 $node->{$name}[$index] = $value;
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
50 } else {
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
51 $node->{$name} = $value;
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
52 }
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
53 }
237
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
54 }
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
55 }
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
56 }
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
57
61db68166c37 refactoring QueryToDOM
sergey
parents:
diff changeset
58 return $this->Transform($data);
238
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
59 }
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
60
b8c724f6de36 DOM model refactoring
sergey
parents: 237
diff changeset
61 1;