changeset 237:61db68166c37

refactoring QueryToDOM
author sergey
date Mon, 15 Oct 2012 17:39:12 +0400
parents 2904da230022
children b8c724f6de36
files Lib/IMPL/DOM/Transform/ObjectToDOM.pm Lib/IMPL/DOM/Transform/QueryToDOM.pm
diffstat 2 files changed, 53 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Transform/ObjectToDOM.pm	Mon Oct 15 04:23:01 2012 +0400
+++ b/Lib/IMPL/DOM/Transform/ObjectToDOM.pm	Mon Oct 15 17:39:12 2012 +0400
@@ -25,7 +25,7 @@
 };
 
 sub CTOR {
-    my ($this,$docName,$docSchema) = @_;
+    my ($this,$docName,$docSchema,$transforms) = @_;
     
     my $docNodeSchema = $docSchema->selectSingleNode(sub { $_->name eq $docName })
         or die OperationException->new("Can't find a node schema for the document '$docName'");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/DOM/Transform/QueryToDOM.pm	Mon Oct 15 17:39:12 2012 +0400
@@ -0,0 +1,52 @@
+package IMPL::DOM::Transform::QueryToDOM;
+use strict;
+
+use IMPL::Const qw(:prop);
+use IMPL::declare {
+	base => [
+	   'IMPL::DOM::Transform::ObjectToDOM' => '@_'
+	],
+	props => [
+	   prefix => PROP_RO,
+	   delimier => PROP_RO
+	]
+};
+
+sub CTOR {
+	my ($this) = @_;
+	
+	$this->templates->{'CGI'} = \&TransformCGI;
+	$this->templates->{'CGIWrapper'} = \&TransformCGI;
+	
+	$this->delimier('.');
+}
+
+sub TransformCGI {
+	my ($this,$query) = @_;
+
+    my $data={};
+    
+    my $prefix = $this->prefix;
+    my $delim = $this->delimiter;
+    
+    foreach my $param (grep index($_,$prefix) >= 0 , $query->param()) {
+        length (my $value = $query->param($param)) or next;
+        
+        my @parts = split /\//,$param;
+        
+        my $node = $data;
+        while ( my $part = shift @parts ) {
+            if (@parts) {
+                $node = ($node->{$part} ||= {});
+            } else {            
+                $node->{$part} = $value;
+            }
+        }  
+    }
+    
+    if (keys %$data > 1) {
+        $data = { document => $data };
+    }
+    
+    return $this->Transform($data);
+}
\ No newline at end of file