diff lib/IMPL/DOM/Schema/SwitchNode.pm @ 407:c6e90e02dd17 ref20150831

renamed Lib->lib
author cin
date Fri, 04 Sep 2015 19:40:23 +0300
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/IMPL/DOM/Schema/SwitchNode.pm	Fri Sep 04 19:40:23 2015 +0300
@@ -0,0 +1,64 @@
+package IMPL::DOM::Schema::SwitchNode;
+use strict;
+use warnings;
+
+use IMPL::declare {
+	require => {
+		Label => 'IMPL::DOM::Schema::Label',
+		ValidationError => 'IMPL::DOM::Schema::ValidationError'
+	},
+	base => [
+		'IMPL::DOM::Schema::AnyNode' => sub {
+	        my %args = @_;
+	        
+	        $args{nodeName} ||= 'SwitchNode';
+	        
+	        %args;
+	    }
+	],
+	props => [
+		messageNoMatch => { get => 1, set => 1, dom => 1 } 
+	]
+};
+
+sub CTOR {
+    my ($this,%args) = @_;
+    
+    $this->messageNoMatch($args{messageNoMatch} || 'A node %node.nodeName% isn\'t expected in the %parent.path%');
+}
+
+sub Validate {
+    my ($this,$node,$ctx) = @_;
+        
+    if ( my ($schema) = $this->selectNodes(sub {$_[0]->name eq $node->nodeName} ) ) {
+        return $schema->Validate($node,$ctx);
+    } else {
+        return ValidationError->new(
+            node => $node,
+            message => $this->_MakeLabel($this->messageNoMatch)
+        );
+    }
+}
+
+sub _MakeLabel {
+	my ($this,$label) = @_;
+	
+	if ($label =~ /^ID:(\w+)$/) {
+		return Label->new($this->document->stringMap, $1);
+	} else {
+		return $label;
+	}
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 DESCRIPTION
+
+Представляет узел, который может быть одним из узлов, которые лежат внутри него.
+Это более строгий вариант C<IMPL::DOM::Schema::AnyNode>.
+
+=cut