Mercurial > pub > Impl
comparison Lib/IMPL/DOM/Transform/PostToDOM.pm @ 112:0ed8e2541b1c
Form processing mechanism
author | wizard |
---|---|
date | Tue, 18 May 2010 17:59:31 +0400 |
parents | 83e356614c1e |
children | 7b14e0122b79 |
comparison
equal
deleted
inserted
replaced
111:6c25ea91c985 | 112:0ed8e2541b1c |
---|---|
1 package IMPL::DOM::PostToDOM; | 1 package IMPL::DOM::Transform::PostToDOM; |
2 use strict; | 2 use strict; |
3 use warnings; | 3 use warnings; |
4 | 4 |
5 use IMPL::DOM::Navigator; | 5 use IMPL::DOM::Navigator::Builder; |
6 use IMPL::Class::Property; | 6 use IMPL::Class::Property; |
7 | 7 |
8 use base qw(IMPL::Transform); | 8 use base qw(IMPL::Transform); |
9 | 9 |
10 BEGIN { | 10 BEGIN { |
19 } | 19 } |
20 ); | 20 ); |
21 | 21 |
22 sub CTOR { | 22 sub CTOR { |
23 my ($this,$docClass,$docSchema) = @_; | 23 my ($this,$docClass,$docSchema) = @_; |
24 $docClass ||= 'IMPL::DOM::Document' | 24 $docClass ||= 'IMPL::DOM::Document'; |
25 | |
26 $this->_navi( | |
27 IMPL::DOM::Navigator::Builder->new( | |
28 $docClass, | |
29 $docSchema | |
30 ) | |
31 ); | |
25 } | 32 } |
26 | 33 |
27 sub TransformPostData { | 34 sub TransformPostData { |
28 my ($this,$data) = @_; | 35 my ($this,$data) = @_; |
29 | 36 |
30 my $navi = $this->Navigator; | 37 my $navi = $this->_navi; |
38 | |
39 my % | |
31 | 40 |
32 while (my ($key,$value) = each %$data) { | 41 while (my ($key,$value) = each %$data) { |
33 # TODO: review | 42 # TODO: review |
43 $navi->save; | |
34 my $node = $navi->Navigate(split /\//, $key); | 44 my $node = $navi->Navigate(split /\//, $key); |
35 $node->nodeValue($value); | 45 $node->nodeValue($value); |
46 $navi->resore; | |
36 } | 47 } |
37 | 48 |
38 return $navi->Document; | 49 return $navi->Document; |
39 } | 50 } |
40 | 51 |
41 package IMPL::DOM::PostToDOM::Navigator; | 52 sub |
42 use base qw(IMPL::DOM::Navigator::Builder); | |
43 | 53 |
44 __PACKAGE__->PassThroughArgs; | 54 sub TransformErrors { |
45 | 55 return $_[0]->_navi->BuildErrors; |
46 sub Navigate { | |
47 my ($this,@path) = @_; | |
48 | |
49 if (@path > 1) { | |
50 my $node; | |
51 foreach my $query (@path) { | |
52 unless($this->dosafe(sub { | |
53 $node = $this->SUPER::Navigate($query); | |
54 })) { | |
55 $node = $this->NavigateCreate($query); | |
56 } | |
57 } | |
58 } else { | |
59 die new IMPL::InvalidArgumentException("A path is a required parameter"); | |
60 } | |
61 } | 56 } |
62 | 57 |
63 1; | 58 1; |