view Lib/IMPL/DOM/Transform/PostToDOM.pm @ 109:ddf0f037d460

IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT) Some fixes to the web document model. (beta version)
author wizard
date Mon, 17 May 2010 05:12:08 +0400
parents 83e356614c1e
children 0ed8e2541b1c
line wrap: on
line source

package IMPL::DOM::PostToDOM;
use strict;
use warnings;

use IMPL::DOM::Navigator;
use IMPL::Class::Property;

use base qw(IMPL::Transform);

BEGIN {
    public property documentClass => prop_get | owner_set;
    public property documentSchema => prop_get | owner_set;
    private property _navi => prop_all;
}

our %CTOR = (
    'IMPL::Transform' => sub {
        HASH => \&TransfromPostData
    }
);

sub CTOR {
	my ($this,$docClass,$docSchema) = @_;
	$docClass ||= 'IMPL::DOM::Document'
}

sub TransformPostData {
    my ($this,$data) = @_;
    
    my $navi = $this->Navigator;
    
    while (my ($key,$value) = each %$data) {
    	# TODO: review
        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;