Mercurial > pub > Impl
comparison Lib/IMPL/DOM/Transform/PostToDOM.pm @ 113:7b14e0122b79
Updated PostToDOM transformation
added selectSingleNode method to IMPL::DOM::Node
Implemented FormWrapper in the Web::Application::ControllerUnit
author | wizard |
---|---|
date | Fri, 21 May 2010 02:38:11 +0400 |
parents | 0ed8e2541b1c |
children | c8dfbbdd8005 |
comparison
equal
deleted
inserted
replaced
112:0ed8e2541b1c | 113:7b14e0122b79 |
---|---|
8 use base qw(IMPL::Transform); | 8 use base qw(IMPL::Transform); |
9 | 9 |
10 BEGIN { | 10 BEGIN { |
11 public property documentClass => prop_get | owner_set; | 11 public property documentClass => prop_get | owner_set; |
12 public property documentSchema => prop_get | owner_set; | 12 public property documentSchema => prop_get | owner_set; |
13 public property prefix => prop_get | owner_set; | |
13 private property _navi => prop_all; | 14 private property _navi => prop_all; |
15 public property Errors => prop_all | prop_list; | |
16 private property _schema => prop_all; | |
14 } | 17 } |
15 | 18 |
16 our %CTOR = ( | 19 our %CTOR = ( |
17 'IMPL::Transform' => sub { | 20 'IMPL::Transform' => sub { |
18 HASH => \&TransfromPostData | 21 -plain => \&TransformPlain, |
22 HASH => \&TransformContainer, | |
23 CGI => \&TransformCGI | |
19 } | 24 } |
20 ); | 25 ); |
21 | 26 |
22 sub CTOR { | 27 sub CTOR { |
23 my ($this,$docClass,$docSchema) = @_; | 28 my ($this,$docClass,$docSchema,$prefix) = @_; |
24 $docClass ||= 'IMPL::DOM::Document'; | 29 $docClass ||= 'IMPL::DOM::Document'; |
25 | 30 |
26 $this->_navi( | 31 $this->_navi( |
27 IMPL::DOM::Navigator::Builder->new( | 32 IMPL::DOM::Navigator::Builder->new( |
28 $docClass, | 33 $docClass, |
29 $docSchema | 34 $docSchema |
30 ) | 35 ) |
31 ); | 36 ); |
37 $this->_schema($docSchema); | |
38 $this->prefix($prefix) if $prefix; | |
32 } | 39 } |
33 | 40 |
34 sub TransformPostData { | 41 sub TransformContainer { |
35 my ($this,$data) = @_; | 42 my ($this,$data) = @_; |
36 | 43 |
37 my $navi = $this->_navi; | 44 my $navi = $this->_navi; |
38 | 45 |
39 my % | |
40 | |
41 while (my ($key,$value) = each %$data) { | 46 while (my ($key,$value) = each %$data) { |
42 # TODO: review | 47 |
43 $navi->save; | 48 $navi->NavigateCreate($key); |
44 my $node = $navi->Navigate(split /\//, $key); | 49 |
45 $node->nodeValue($value); | 50 $this->Transform($value); |
46 $navi->resore; | 51 |
52 $navi->Back(); | |
47 } | 53 } |
48 | 54 |
49 return $navi->Document; | 55 return $navi->Current; |
50 } | 56 } |
51 | 57 |
52 sub | 58 sub TransformPlain { |
59 my ($this,$data) = @_; | |
60 | |
61 $this->_navi->Current->nodeValue( $this->_navi->inflateValue($data) ); | |
62 } | |
53 | 63 |
54 sub TransformErrors { | 64 sub TransformCGI { |
55 return $_[0]->_navi->BuildErrors; | 65 my ($this,$query) = @_; |
66 | |
67 my $data={}; | |
68 | |
69 my $prefix = $this->prefix; | |
70 $prefix = qr/$prefix/; | |
71 | |
72 foreach my $param (grep $_=~/$prefix/, $query->param()) { | |
73 my $value = $query->param($param); | |
74 | |
75 my @parts = split /\//,$param; | |
76 | |
77 my $node = $data; | |
78 while ( my $part = shift @parts ) { | |
79 if (@parts) { | |
80 $node = ($node->{$part} ||= {}); | |
81 } else { | |
82 $node->{$part} = $value; | |
83 } | |
84 } | |
85 } | |
86 | |
87 my $doc = $this->Transform($data); | |
88 $this->Errors->Append( $this->_navi->BuildErrors); | |
89 $this->Errors->Append( $this->_schema->Validate($doc)); | |
90 return $doc; | |
56 } | 91 } |
57 | 92 |
58 1; | 93 1; |