Mercurial > pub > Impl
comparison 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 |
comparison
equal
deleted
inserted
replaced
406:f23fcb19d3c1 | 407:c6e90e02dd17 |
---|---|
1 package IMPL::DOM::Schema::SwitchNode; | |
2 use strict; | |
3 use warnings; | |
4 | |
5 use IMPL::declare { | |
6 require => { | |
7 Label => 'IMPL::DOM::Schema::Label', | |
8 ValidationError => 'IMPL::DOM::Schema::ValidationError' | |
9 }, | |
10 base => [ | |
11 'IMPL::DOM::Schema::AnyNode' => sub { | |
12 my %args = @_; | |
13 | |
14 $args{nodeName} ||= 'SwitchNode'; | |
15 | |
16 %args; | |
17 } | |
18 ], | |
19 props => [ | |
20 messageNoMatch => { get => 1, set => 1, dom => 1 } | |
21 ] | |
22 }; | |
23 | |
24 sub CTOR { | |
25 my ($this,%args) = @_; | |
26 | |
27 $this->messageNoMatch($args{messageNoMatch} || 'A node %node.nodeName% isn\'t expected in the %parent.path%'); | |
28 } | |
29 | |
30 sub Validate { | |
31 my ($this,$node,$ctx) = @_; | |
32 | |
33 if ( my ($schema) = $this->selectNodes(sub {$_[0]->name eq $node->nodeName} ) ) { | |
34 return $schema->Validate($node,$ctx); | |
35 } else { | |
36 return ValidationError->new( | |
37 node => $node, | |
38 message => $this->_MakeLabel($this->messageNoMatch) | |
39 ); | |
40 } | |
41 } | |
42 | |
43 sub _MakeLabel { | |
44 my ($this,$label) = @_; | |
45 | |
46 if ($label =~ /^ID:(\w+)$/) { | |
47 return Label->new($this->document->stringMap, $1); | |
48 } else { | |
49 return $label; | |
50 } | |
51 } | |
52 | |
53 1; | |
54 | |
55 __END__ | |
56 | |
57 =pod | |
58 | |
59 =head1 DESCRIPTION | |
60 | |
61 Представляет узел, который может быть одним из узлов, которые лежат внутри него. | |
62 Это более строгий вариант C<IMPL::DOM::Schema::AnyNode>. | |
63 | |
64 =cut |