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