diff Lib/IMPL/DOM/Schema/NodeList.pm @ 388:648dfaf642e0

DOM refactoring, removed inflators from DOM Schema, DOM validation - in progress
author cin
date Tue, 11 Feb 2014 20:22:01 +0400
parents b8c724f6de36
children 5aff94ba842f
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Schema/NodeList.pm	Tue Feb 11 01:13:47 2014 +0400
+++ b/Lib/IMPL/DOM/Schema/NodeList.pm	Tue Feb 11 20:22:01 2014 +0400
@@ -1,20 +1,21 @@
 package IMPL::DOM::Schema::NodeList;
 use strict;
 use warnings;
-use parent qw(IMPL::DOM::Node);
 
-use IMPL::Class::Property;
-use IMPL::DOM::Property qw(_dom);
-require IMPL::DOM::Schema::ValidationError;
 
-our %CTOR = (
-    'IMPL::DOM::Node' => sub { nodeName => 'NodeList' }
-);
-
-BEGIN {
-    public _dom property messageUnexpected => prop_all;
-    public _dom property messageNodesRequired => prop_all;
-}
+use IMPL::declare {
+	require => {
+		ValidationError => 'IMPL::DOM::Schema::ValidationError',
+		AnyNode => '-IMPL::DOM::Schema::AnyNode'
+	},
+	base => [
+		'IMPL::DOM::Node' => sub { nodeName => 'NodeList' }
+	],
+	props => [
+		messageUnexpected => { get => 1, set => 1, dom => 1 },
+		messageNodesRequired => { get => 1, set => 1, dom => 1}
+	]
+};
 
 sub CTOR {
     my ($this,%args) = @_;
@@ -27,40 +28,37 @@
     my ($this,$node,$ctx) = @_;
     
     my @nodes = map {
-        {nodeName => $_->name, anyNode => $_->isa('IMPL::DOM::Schema::AnyNode') , Schema => $_, Max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur, Min => $_->minOccur, Seen => 0 }
+        {nodeName => $_->name, anyNode => $_->isa(AnyNode) , schemaNode => $_, max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur, min => $_->minOccur, seen => 0 }
     } @{$this->childNodes};
     
     my $info = shift @nodes;
-    my $sourceSchema = $ctx->{Source} || $this->parentNode;
     
     foreach my $child ( @{$node->childNodes} ) {
         #skip schema elements
         while ($info and not $info->{anyNode} and $info->{nodeName} ne $child->nodeName) {
             # if possible of course :)
-            return new IMPL::DOM::Schema::ValidationError (
+            return ValidationError->new (
                 message => $this->messageUnexpected,
                 node => $child,
                 parent => $node,
-                schema => $info->{Schema},
-                source => $sourceSchema
+                schemaNode => $info->{schemaNode}
             ) if $info->{Min} > $info->{Seen};
             
             $info = shift @nodes;
         }
         
         # return error if no more children allowed
-        return new IMPL::DOM::Schema::ValidationError (
+        return ValidationError->new (
             message => $this->messageUnexpected,
             node => $child,
-            parent => $node,
-            source => $sourceSchema
+            parent => $node
         ) unless $info;
         
         # it's ok, we found schema element for child
         # but it may be any node or switching node wich would not satisfy current child
 
         # validate
-        while (my @errors = $info->{Schema}->Validate($child)) {
+        while (my @errors = $info->{schemaNode}->Validate($child)) {
             if( $info->{anyNode} and $info->{Seen} >= $info->{Min} ) {
                 # in case of any or switch node, skip it if possible
                 next if $info = shift @nodes;