Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/Property.pm @ 391:2287c72f303a
code cleanup
| author | cin |
|---|---|
| date | Thu, 13 Feb 2014 20:17:22 +0400 |
| parents | 5aff94ba842f |
| children |
| rev | line source |
|---|---|
| 49 | 1 package IMPL::DOM::Schema::Property; |
| 2 use strict; | |
| 3 use warnings; | |
| 4 | |
| 389 | 5 use IMPL::declare { |
| 6 require => { | |
| 7 Label => 'IMPL::DOM::Schema::Label', | |
| 8 DOMNode => 'IMPL::DOM::Node', | |
| 9 ValidationError => 'IMPL::DOM::Schema::ValidationError' | |
| 10 }, | |
| 11 base => [ | |
| 12 'IMPL::DOM::Schema::SimpleNode' => sub { | |
| 13 my %args = @_; | |
| 14 | |
| 15 $args{maxOccur} = 1; | |
| 16 $args{minOccur} = delete $args{optional} ? 0 : 1; | |
| 17 $args{nodeName} ||= 'Property'; | |
| 18 | |
| 19 return %args; | |
| 20 } | |
| 21 ], | |
| 22 props => [ | |
| 23 messageRequired => { get => 1, set => 1, dom => 1 } | |
| 24 ] | |
| 25 }; | |
| 49 | 26 |
| 27 sub CTOR { | |
| 28 my ($this,%args) = @_; | |
| 29 | |
| 389 | 30 $this->messageRequired($args{messageRequired} || 'A property %schemaNode.name% is required in the %node.qname%'); |
| 49 | 31 } |
| 32 | |
| 33 sub Validate { | |
|
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
34 my ($this,$node,$ctx) = @_; |
| 49 | 35 |
| 389 | 36 my $nodeValue = $node->nodeProperty($this->name); |
| 49 | 37 |
| 389 | 38 if (length $nodeValue) { |
| 39 # we have a value so validate it | |
| 40 | |
| 41 # buld a pseudo node for the property value | |
| 42 my $nodeProp = DOMNode->new(nodeName => '::property', nodeValue => $nodeValue); | |
| 43 | |
| 44 return $this->SUPER::Validate($nodeProp); | |
| 45 | |
| 103 | 46 } elsif($this->minOccur) { |
| 194 | 47 # we don't have a value but it's a mandatory property |
| 389 | 48 return ValidationError->new( |
| 49 message => $this->_MakeLabel($this->messageRequired), | |
| 236 | 50 node => $node, |
| 389 | 51 schemaNode => $this |
| 103 | 52 ); |
| 49 | 53 } |
|
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
54 return (); |
| 49 | 55 } |
| 56 | |
| 389 | 57 sub _MakeLabel { |
| 58 my ($this,$label) = @_; | |
| 59 | |
| 60 if ($label =~ /^ID:(\w+)$/) { | |
| 61 return Label->new($this->document->stringMap, $1); | |
| 62 } else { | |
| 63 return $label; | |
| 64 } | |
| 65 } | |
| 66 | |
| 49 | 67 1; |
