Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Transform/PostToDOM.pm @ 142:4c9849f0f879
minor changes
author | wizard |
---|---|
date | Wed, 07 Jul 2010 17:30:40 +0400 |
parents | 06a34c197b05 |
children | b56ebc31bf18 |
rev | line source |
---|---|
112 | 1 package IMPL::DOM::Transform::PostToDOM; |
49 | 2 use strict; |
3 use warnings; | |
4 | |
112 | 5 use IMPL::DOM::Navigator::Builder; |
49 | 6 use IMPL::Class::Property; |
7 | |
8 use base qw(IMPL::Transform); | |
9 | |
10 BEGIN { | |
106 | 11 public property documentClass => prop_get | owner_set; |
12 public property documentSchema => prop_get | owner_set; | |
113 | 13 public property prefix => prop_get | owner_set; |
106 | 14 private property _navi => prop_all; |
113 | 15 public property Errors => prop_all | prop_list; |
16 private property _schema => prop_all; | |
49 | 17 } |
18 | |
19 our %CTOR = ( | |
20 'IMPL::Transform' => sub { | |
113 | 21 -plain => \&TransformPlain, |
22 HASH => \&TransformContainer, | |
130
06a34c197b05
Added support for utf-8 and old versions of CGI module
wizard
parents:
126
diff
changeset
|
23 CGI => \&TransformCGI, |
06a34c197b05
Added support for utf-8 and old versions of CGI module
wizard
parents:
126
diff
changeset
|
24 CGIWrapper => \&TransformCGI |
49 | 25 } |
26 ); | |
27 | |
106 | 28 sub CTOR { |
113 | 29 my ($this,$docClass,$docSchema,$prefix) = @_; |
112 | 30 $docClass ||= 'IMPL::DOM::Document'; |
31 | |
32 $this->_navi( | |
33 IMPL::DOM::Navigator::Builder->new( | |
34 $docClass, | |
35 $docSchema | |
36 ) | |
37 ); | |
113 | 38 $this->_schema($docSchema); |
39 $this->prefix($prefix) if $prefix; | |
106 | 40 } |
41 | |
113 | 42 sub TransformContainer { |
49 | 43 my ($this,$data) = @_; |
44 | |
112 | 45 my $navi = $this->_navi; |
113 | 46 |
49 | 47 while (my ($key,$value) = each %$data) { |
113 | 48 |
49 $navi->NavigateCreate($key); | |
50 | |
51 $this->Transform($value); | |
52 | |
53 $navi->Back(); | |
49 | 54 } |
55 | |
113 | 56 return $navi->Current; |
57 } | |
58 | |
59 sub TransformPlain { | |
60 my ($this,$data) = @_; | |
61 | |
62 $this->_navi->Current->nodeValue( $this->_navi->inflateValue($data) ); | |
49 | 63 } |
64 | |
113 | 65 sub TransformCGI { |
66 my ($this,$query) = @_; | |
126 | 67 |
113 | 68 my $data={}; |
69 | |
70 my $prefix = $this->prefix; | |
71 $prefix = qr/$prefix/; | |
72 | |
73 foreach my $param (grep $_=~/$prefix/, $query->param()) { | |
74 my $value = $query->param($param); | |
75 | |
76 my @parts = split /\//,$param; | |
77 | |
78 my $node = $data; | |
79 while ( my $part = shift @parts ) { | |
80 if (@parts) { | |
81 $node = ($node->{$part} ||= {}); | |
82 } else { | |
83 $node->{$part} = $value; | |
84 } | |
85 } | |
86 } | |
87 | |
88 my $doc = $this->Transform($data); | |
89 $this->Errors->Append( $this->_navi->BuildErrors); | |
90 $this->Errors->Append( $this->_schema->Validate($doc)); | |
91 return $doc; | |
106 | 92 } |
49 | 93 |
94 1; |