diff 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
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Transform/PostToDOM.pm	Tue May 11 02:59:49 2010 +0400
+++ b/Lib/IMPL/DOM/Transform/PostToDOM.pm	Wed May 12 17:52:12 2010 +0400
@@ -1,4 +1,4 @@
-package IMPL::DOM::Post2DOM;
+package IMPL::DOM::PostToDOM;
 use strict;
 use warnings;
 
@@ -8,17 +8,22 @@
 use base qw(IMPL::Transform);
 
 BEGIN {
-    public property Navigator => prop_get | owner_set;
+    public property documentClass => prop_get | owner_set;
+    public property documentSchema => prop_get | owner_set;
+    private property _navi => prop_all;
 }
 
 our %CTOR = (
     'IMPL::Transform' => sub {
-        return (
-            HASH => \&TransfromPostData
-        );
+        HASH => \&TransfromPostData
     }
 );
 
+sub CTOR {
+	my ($this,$docClass,$docSchema) = @_;
+	$docClass ||= 'IMPL::DOM::Document'
+}
+
 sub TransformPostData {
     my ($this,$data) = @_;
     
@@ -26,12 +31,33 @@
     
     while (my ($key,$value) = each %$data) {
     	# TODO: review
-        my $node = $navi->Navigate($key);
+        my $node = $navi->Navigate(split /\//, $key);
         $node->nodeValue($value);
     }
     
     return $navi->Document;
 }
 
+package IMPL::DOM::PostToDOM::Navigator;
+use base qw(IMPL::DOM::Navigator::Builder);
+
+__PACKAGE__->PassThroughArgs;
+
+sub Navigate {
+	my ($this,@path) = @_;
+	
+	if (@path > 1) {
+		my $node;
+		foreach my $query (@path) {
+			unless($this->dosafe(sub {
+				$node = $this->SUPER::Navigate($query);
+			})) {
+				$node = $this->NavigateCreate($query);				
+			}
+		}
+	} else {
+		die new IMPL::InvalidArgumentException("A path is a required parameter");
+	}
+}
 
 1;