annotate lib/IMPL/DOM/Schema/Property.pm @ 421:7798345304bc ref20150831

working on IMPL::Config, removed old stuff
author cin
date Sun, 16 Jul 2017 22:59:39 +0300
parents c6e90e02dd17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::DOM::Schema::Property;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3 use warnings;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 use IMPL::declare {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 require => {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 Label => 'IMPL::DOM::Schema::Label',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8 DOMNode => 'IMPL::DOM::Node',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 ValidationError => 'IMPL::DOM::Schema::ValidationError'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 },
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 base => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12 'IMPL::DOM::Schema::SimpleNode' => sub {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13 my %args = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15 $args{maxOccur} = 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16 $args{minOccur} = delete $args{optional} ? 0 : 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17 $args{nodeName} ||= 'Property';
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 return %args;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 ],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22 props => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23 messageRequired => { get => 1, set => 1, dom => 1 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 ]
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 sub CTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28 my ($this,%args) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30 $this->messageRequired($args{messageRequired} || 'A property %schemaNode.name% is required in the %node.qname%');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33 sub Validate {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34 my ($this,$node,$ctx) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 my $nodeValue = $node->nodeProperty($this->name);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38 if (length $nodeValue) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 # we have a value so validate it
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41 # buld a pseudo node for the property value
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42 my $nodeProp = DOMNode->new(nodeName => '::property', nodeValue => $nodeValue);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44 return $this->SUPER::Validate($nodeProp);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46 } elsif($this->minOccur) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47 # we don't have a value but it's a mandatory property
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48 return ValidationError->new(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49 message => $this->_MakeLabel($this->messageRequired),
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50 node => $node,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51 schemaNode => $this
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52 );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54 return ();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57 sub _MakeLabel {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58 my ($this,$label) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60 if ($label =~ /^ID:(\w+)$/) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61 return Label->new($this->document->stringMap, $1);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
63 return $label;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
64 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
65 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67 1;