diff Lib/IMPL/DOM/Transform/PostToDOM.pm @ 194:4d0e1962161c

Replaced tabs with spaces IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author cin
date Tue, 10 Apr 2012 20:08:29 +0400
parents d1676be8afcc
children a4d9126edcbb
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Transform/PostToDOM.pm	Tue Apr 10 08:13:22 2012 +0400
+++ b/Lib/IMPL/DOM/Transform/PostToDOM.pm	Tue Apr 10 20:08:29 2012 +0400
@@ -18,7 +18,7 @@
 
 our %CTOR = (
     'IMPL::Transform' => sub {
-    	-plain => \&TransformPlain,
+        -plain => \&TransformPlain,
         HASH => \&TransformContainer,
         CGI => \&TransformCGI,
         CGIWrapper => \&TransformCGI
@@ -26,17 +26,17 @@
 );
 
 sub CTOR {
-	my ($this,$docClass,$docSchema,$prefix) = @_;
-	$docClass ||= 'IMPL::DOM::Document';
-	
-	$this->_navi(
-		IMPL::DOM::Navigator::Builder->new(
-			$docClass,
-			$docSchema
-		)
-	);
-	$this->_schema($docSchema);
-	$this->prefix($prefix) if $prefix;
+    my ($this,$docClass,$docSchema,$prefix) = @_;
+    $docClass ||= 'IMPL::DOM::Document';
+    
+    $this->_navi(
+        IMPL::DOM::Navigator::Builder->new(
+            $docClass,
+            $docSchema
+        )
+    );
+    $this->_schema($docSchema);
+    $this->prefix($prefix) if $prefix;
 }
 
 sub TransformContainer {
@@ -45,59 +45,59 @@
     my $navi = $this->_navi;
         
     foreach my $key (
-    	sort { $a->[1] cmp $b->[1] || $a->[2] <=> $b->[2]}
-    	map [$_,/(\w+)(?:\[(\d+)\])?/], keys %$data
+        sort { $a->[1] cmp $b->[1] || $a->[2] <=> $b->[2]}
+        map [$_,/(\w+)(?:\[(\d+)\])?/], keys %$data
     ){
-    	my $value = $data->{$key->[0]};
-    	my $node = $navi->NavigateCreate($key->[1]);
-    	
-    	$node->nodeProperty(instanceId => $key->[2]) if defined $key->[2];
-    	
-    	$this->Transform($value);
-    	
-    	$navi->Back();
+        my $value = $data->{$key->[0]};
+        my $node = $navi->NavigateCreate($key->[1]);
+        
+        $node->nodeProperty(instanceId => $key->[2]) if defined $key->[2];
+        
+        $this->Transform($value);
+        
+        $navi->Back();
     }
     
     return $navi->Current;
 }
 
 sub TransformPlain {
-	my ($this,$data) = @_;
-	
-	$this->_navi->Current->nodeValue( $this->_navi->inflateValue($data) );
+    my ($this,$data) = @_;
+    
+    $this->_navi->Current->nodeValue( $this->_navi->inflateValue($data) );
 }
 
 sub TransformCGI {
-	my ($this,$query) = @_;
+    my ($this,$query) = @_;
 
-	my $data={};
-	
-	my $prefix = $this->prefix;
-	
-	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 };
-	}
-	
-	my $doc = $this->Transform($data);
-	$doc->nodeProperty( query => $query );
-	$this->Errors->Append( $this->_navi->BuildErrors);
-	$this->Errors->Append( $this->_schema->Validate($doc));
-	return $doc;
+    my $data={};
+    
+    my $prefix = $this->prefix;
+    
+    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 };
+    }
+    
+    my $doc = $this->Transform($data);
+    $doc->nodeProperty( query => $query );
+    $this->Errors->Append( $this->_navi->BuildErrors);
+    $this->Errors->Append( $this->_schema->Validate($doc));
+    return $doc;
 }
 
 1;
@@ -114,26 +114,26 @@
 
 =begin code
 
-	my $schema = IMPL::DOM::Schema->LoadSchema('Data/user.add.schema.xml');
-	
-	my $transform = IMPL::DOM::Transform::PostToDOM->new(
-		undef, # default class
-		$schema,
-		$schema->selectSingleNode('ComplexNode')->name
-	);
-	
-	my $doc = $transform->Transform(
-		CGI->new({
-			'user/login' => 'bob',
-			'user/fullName' => 'Bob Marley',
-			'user/password' => 'secret',
-			'user/password_retype' => 'secret',
-			'user/birthday' => '1978-12-17',
-			'user/email[1]' => 'bob@marley.com',
-			'user/email[2]' => 'bob.marley@google.com',
-			process => 1
-		})
-	);
+    my $schema = IMPL::DOM::Schema->LoadSchema('Data/user.add.schema.xml');
+    
+    my $transform = IMPL::DOM::Transform::PostToDOM->new(
+        undef, # default class
+        $schema,
+        $schema->selectSingleNode('ComplexNode')->name
+    );
+    
+    my $doc = $transform->Transform(
+        CGI->new({
+            'user/login' => 'bob',
+            'user/fullName' => 'Bob Marley',
+            'user/password' => 'secret',
+            'user/password_retype' => 'secret',
+            'user/birthday' => '1978-12-17',
+            'user/email[1]' => 'bob@marley.com',
+            'user/email[2]' => 'bob.marley@google.com',
+            process => 1
+        })
+    );
 
 =end code
 
@@ -152,7 +152,7 @@
 
 =item 3 В случае когда узел может повторяться несколько раз, в квадратных скобках указывается
 послеовательный номер экземпляра.
-	
+    
 =item 4 Имена параметров объединяются через символ '/'
 
 =back