106
|
1 package IMPL::DOM::PostToDOM;
|
49
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
|
5 use IMPL::DOM::Navigator;
|
|
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;
|
|
13 private property _navi => prop_all;
|
49
|
14 }
|
|
15
|
|
16 our %CTOR = (
|
|
17 'IMPL::Transform' => sub {
|
106
|
18 HASH => \&TransfromPostData
|
49
|
19 }
|
|
20 );
|
|
21
|
106
|
22 sub CTOR {
|
|
23 my ($this,$docClass,$docSchema) = @_;
|
|
24 $docClass ||= 'IMPL::DOM::Document'
|
|
25 }
|
|
26
|
49
|
27 sub TransformPostData {
|
|
28 my ($this,$data) = @_;
|
|
29
|
|
30 my $navi = $this->Navigator;
|
|
31
|
|
32 while (my ($key,$value) = each %$data) {
|
79
|
33 # TODO: review
|
106
|
34 my $node = $navi->Navigate(split /\//, $key);
|
49
|
35 $node->nodeValue($value);
|
|
36 }
|
|
37
|
|
38 return $navi->Document;
|
|
39 }
|
|
40
|
106
|
41 package IMPL::DOM::PostToDOM::Navigator;
|
|
42 use base qw(IMPL::DOM::Navigator::Builder);
|
|
43
|
|
44 __PACKAGE__->PassThroughArgs;
|
|
45
|
|
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 }
|
49
|
62
|
|
63 1;
|