Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/Property.pm @ 381:ced5937ff21a
Custom getters/setters support method names in theirs definitions
Initial support for localizable labels in DOM schemas
author | cin |
---|---|
date | Wed, 22 Jan 2014 16:56:10 +0400 |
parents | 0f59b2de72af |
children | 5aff94ba842f |
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::Node; |
7 use IMPL::Class::Property; | |
152 | 8 use IMPL::DOM::Property qw(_dom); |
49 | 9 |
10 __PACKAGE__->PassThroughArgs; | |
11 | |
12 BEGIN { | |
152 | 13 public _dom 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'; | |
238 | 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 | |
238 | 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 # buld a pseudo node for the property value | |
40 my $nodeProp = new IMPL::DOM::Node(nodeName => '::property', nodeValue => eval { $node->$prop() } || $node->nodeProperty($prop)); | |
49 | 41 |
103 | 42 if ($nodeProp->nodeValue) { |
194 | 43 # we have a value so validate it |
44 return $this->SUPER::Validate($nodeProp,$ctx); | |
103 | 45 } elsif($this->minOccur) { |
194 | 46 # we don't have a value but it's a mandatory property |
103 | 47 return new IMPL::DOM::Schema::ValidationError( |
236 | 48 message => $this->messageRequired, |
49 node => $node, | |
50 schema => $this, | |
51 source => $ctx && $ctx->{Source} || $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 | |
57 1; |