Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/Property.pm @ 248:814d755e5d12
Minor fixes
author | sergey |
---|---|
date | Tue, 06 Nov 2012 00:58:15 +0400 |
parents | b8c724f6de36 |
children | 0f59b2de72af |
rev | line source |
---|---|
49 | 1 package IMPL::DOM::Schema::Property; |
2 use strict; | |
3 use warnings; | |
4 | |
165 | 5 use parent qw(IMPL::DOM::Schema::SimpleNode); |
49 | 6 require IMPL::DOM::Schema; |
7 require IMPL::DOM::Node; | |
8 use IMPL::Class::Property; | |
152 | 9 use IMPL::DOM::Property qw(_dom); |
49 | 10 |
11 __PACKAGE__->PassThroughArgs; | |
12 | |
13 BEGIN { | |
152 | 14 public _dom property messageRequired => prop_all; |
49 | 15 } |
16 | |
17 our %CTOR = ( | |
18 'IMPL::DOM::Schema::SimpleNode' => sub { | |
19 my %args = @_; | |
20 | |
21 $args{maxOccur} = 1; | |
22 $args{minOccur} = delete $args{optional} ? 0 : 1; | |
23 $args{nodeName} ||= 'Property'; | |
238 | 24 $args{messageInflateError} ||= "Failed to inflate a property '%schema.name%' of a node '%node.path%': %error.message%"; |
49 | 25 |
26 return %args; | |
27 } | |
28 ); | |
29 | |
30 sub CTOR { | |
31 my ($this,%args) = @_; | |
32 | |
238 | 33 $this->messageRequired($args{messageRequired} || 'A property %schema.name% is required in the %node.qname%'); |
49 | 34 } |
35 | |
36 sub Validate { | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
37 my ($this,$node,$ctx) = @_; |
49 | 38 |
103 | 39 my $prop = $this->name; |
40 | |
41 # buld a pseudo node for the property value | |
42 my $nodeProp = new IMPL::DOM::Node(nodeName => '::property', nodeValue => eval { $node->$prop() } || $node->nodeProperty($prop)); | |
49 | 43 |
103 | 44 if ($nodeProp->nodeValue) { |
194 | 45 # we have a value so validate it |
46 return $this->SUPER::Validate($nodeProp,$ctx); | |
103 | 47 } elsif($this->minOccur) { |
194 | 48 # we don't have a value but it's a mandatory property |
103 | 49 return new IMPL::DOM::Schema::ValidationError( |
236 | 50 message => $this->messageRequired, |
51 node => $node, | |
52 schema => $this, | |
53 source => $ctx && $ctx->{Source} || $this | |
103 | 54 ); |
49 | 55 } |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
56 return (); |
49 | 57 } |
58 | |
59 1; |