annotate Lib/IMPL/DOM/Transform/PostToDOM.pm @ 114:7084af955c57

minor changes, more strict code, no bugs fixed, no features added
author wizard
date Tue, 25 May 2010 01:26:42 +0400
parents 7b14e0122b79
children c8dfbbdd8005
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
1 package IMPL::DOM::Transform::PostToDOM;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
4
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
5 use IMPL::DOM::Navigator::Builder;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
6 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
7
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
8 use base qw(IMPL::Transform);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
9
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
10 BEGIN {
106
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 79
diff changeset
11 public property documentClass => prop_get | owner_set;
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 79
diff changeset
12 public property documentSchema => prop_get | owner_set;
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
13 public property prefix => prop_get | owner_set;
106
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 79
diff changeset
14 private property _navi => prop_all;
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
15 public property Errors => prop_all | prop_list;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
16 private property _schema => prop_all;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
17 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
18
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
19 our %CTOR = (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
20 'IMPL::Transform' => sub {
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
21 -plain => \&TransformPlain,
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
22 HASH => \&TransformContainer,
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
23 CGI => \&TransformCGI
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
24 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
25 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
26
106
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 79
diff changeset
27 sub CTOR {
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
28 my ($this,$docClass,$docSchema,$prefix) = @_;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
29 $docClass ||= 'IMPL::DOM::Document';
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
30
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
31 $this->_navi(
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
32 IMPL::DOM::Navigator::Builder->new(
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
33 $docClass,
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
34 $docSchema
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
35 )
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
36 );
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
37 $this->_schema($docSchema);
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
38 $this->prefix($prefix) if $prefix;
106
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 79
diff changeset
39 }
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 79
diff changeset
40
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
41 sub TransformContainer {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
42 my ($this,$data) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
43
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 106
diff changeset
44 my $navi = $this->_navi;
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
45
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
46 while (my ($key,$value) = each %$data) {
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
47
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
48 $navi->NavigateCreate($key);
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
49
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
50 $this->Transform($value);
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
51
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
52 $navi->Back();
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
53 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
54
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
55 return $navi->Current;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
56 }
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
57
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
58 sub TransformPlain {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
59 my ($this,$data) = @_;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
60
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
61 $this->_navi->Current->nodeValue( $this->_navi->inflateValue($data) );
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
62 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
63
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
64 sub TransformCGI {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
65 my ($this,$query) = @_;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
66
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
67 my $data={};
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
68
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
69 my $prefix = $this->prefix;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
70 $prefix = qr/$prefix/;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
71
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
72 foreach my $param (grep $_=~/$prefix/, $query->param()) {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
73 my $value = $query->param($param);
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
74
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
75 my @parts = split /\//,$param;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
76
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
77 my $node = $data;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
78 while ( my $part = shift @parts ) {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
79 if (@parts) {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
80 $node = ($node->{$part} ||= {});
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
81 } else {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
82 $node->{$part} = $value;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
83 }
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
84 }
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
85 }
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
86
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
87 my $doc = $this->Transform($data);
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
88 $this->Errors->Append( $this->_navi->BuildErrors);
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
89 $this->Errors->Append( $this->_schema->Validate($doc));
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
90 return $doc;
106
83e356614c1e DOM Builder now is a navigator like SimpleBuilder
wizard
parents: 79
diff changeset
91 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
92
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
93 1;