Mercurial > pub > Impl
comparison 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 |
comparison
equal
deleted
inserted
replaced
103:c289ed9662ca | 104:196bf443b5e1 |
---|---|
8 use IMPL::Class::Property; | 8 use IMPL::Class::Property; |
9 | 9 |
10 __PACKAGE__->PassThroughArgs; | 10 __PACKAGE__->PassThroughArgs; |
11 | 11 |
12 BEGIN { | 12 BEGIN { |
13 public property RequiredMessage => prop_all; | 13 public property messageRequired => prop_all; |
14 } | 14 } |
15 | 15 |
16 our %CTOR = ( | 16 our %CTOR = ( |
17 'IMPL::DOM::Schema::SimpleNode' => sub { | 17 'IMPL::DOM::Schema::SimpleNode' => sub { |
18 my %args = @_; | 18 my %args = @_; |
19 | 19 |
20 $args{maxOccur} = 1; | 20 $args{maxOccur} = 1; |
21 $args{minOccur} = delete $args{optional} ? 0 : 1; | 21 $args{minOccur} = delete $args{optional} ? 0 : 1; |
22 $args{nodeName} ||= 'Property'; | 22 $args{nodeName} ||= 'Property'; |
23 $args{messageInflateError} ||= "Failed to inflate a property '%Schema.name%' of a node '%Node.path%': %Error.Message%"; | |
23 | 24 |
24 return %args; | 25 return %args; |
25 } | 26 } |
26 ); | 27 ); |
27 | 28 |
28 sub CTOR { | 29 sub CTOR { |
29 my ($this,%args) = @_; | 30 my ($this,%args) = @_; |
30 | 31 |
31 $this->RequiredMessage($args{RequiredMessage} || 'A property %Schema.name% is required in the %Node.qname%'); | 32 $this->messageRequired($args{messageRequired} || 'A property %Schema.name% is required in the %Node.qname%'); |
32 } | 33 } |
33 | 34 |
34 sub Validate { | 35 sub Validate { |
35 my ($this,$node) = @_; | 36 my ($this,$node,$ctx) = @_; |
36 | 37 |
37 my $prop = $this->name; | 38 my $prop = $this->name; |
38 | 39 |
39 # buld a pseudo node for the property value | 40 # buld a pseudo node for the property value |
40 my $nodeProp = new IMPL::DOM::Node(nodeName => '::property', nodeValue => eval { $node->$prop() } || $node->nodeProperty($prop)); | 41 my $nodeProp = new IMPL::DOM::Node(nodeName => '::property', nodeValue => eval { $node->$prop() } || $node->nodeProperty($prop)); |
41 | 42 |
42 if ($nodeProp->nodeValue) { | 43 if ($nodeProp->nodeValue) { |
43 # we have a value so validate it | 44 # we have a value so validate it |
44 return $this->SUPER::Validate($nodeProp); | 45 return $this->SUPER::Validate($nodeProp,$ctx); |
45 } elsif($this->minOccur) { | 46 } elsif($this->minOccur) { |
46 # we don't have a value but it's a mandatory property | 47 # we don't have a value but it's a mandatory property |
47 return new IMPL::DOM::Schema::ValidationError( | 48 return new IMPL::DOM::Schema::ValidationError( |
48 Message => $this->RequiredMessage, | 49 Message => $this->messageRequired, |
49 Node => $node, | 50 Node => $node, |
50 Schema => $this | 51 Schema => $this, |
52 Source => $ctx && $ctx->{Source} || $this | |
51 ); | 53 ); |
52 } | 54 } |
53 | 55 return (); |
54 } | 56 } |
55 | 57 |
56 1; | 58 1; |