comparison Lib/IMPL/DOM/Transform/PostToDOM.pm @ 106:83e356614c1e

DOM Builder now is a navigator like SimpleBuilder PostToDOM transformation
author wizard
date Wed, 12 May 2010 17:52:12 +0400
parents 2d1c3f713280
children 0ed8e2541b1c
comparison
equal deleted inserted replaced
105:a6e9759ff88a 106:83e356614c1e
1 package IMPL::DOM::Post2DOM; 1 package IMPL::DOM::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;
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 {
11 public property Navigator => prop_get | owner_set; 11 public property documentClass => prop_get | owner_set;
12 public property documentSchema => prop_get | owner_set;
13 private property _navi => prop_all;
12 } 14 }
13 15
14 our %CTOR = ( 16 our %CTOR = (
15 'IMPL::Transform' => sub { 17 'IMPL::Transform' => sub {
16 return ( 18 HASH => \&TransfromPostData
17 HASH => \&TransfromPostData
18 );
19 } 19 }
20 ); 20 );
21
22 sub CTOR {
23 my ($this,$docClass,$docSchema) = @_;
24 $docClass ||= 'IMPL::DOM::Document'
25 }
21 26
22 sub TransformPostData { 27 sub TransformPostData {
23 my ($this,$data) = @_; 28 my ($this,$data) = @_;
24 29
25 my $navi = $this->Navigator; 30 my $navi = $this->Navigator;
26 31
27 while (my ($key,$value) = each %$data) { 32 while (my ($key,$value) = each %$data) {
28 # TODO: review 33 # TODO: review
29 my $node = $navi->Navigate($key); 34 my $node = $navi->Navigate(split /\//, $key);
30 $node->nodeValue($value); 35 $node->nodeValue($value);
31 } 36 }
32 37
33 return $navi->Document; 38 return $navi->Document;
34 } 39 }
35 40
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 }
36 62
37 1; 63 1;