Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/Property.pm @ 310:0a9d51cf6dfd
*TTView: refactoring, document supports custom classes, layouts are become controls
author | sergey |
---|---|
date | Fri, 19 Apr 2013 16:39:01 +0400 |
parents | 0f59b2de72af |
children | ced5937ff21a |
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 | |
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) { |
194 | 44 # we have a value so validate it |
45 return $this->SUPER::Validate($nodeProp,$ctx); | |
103 | 46 } elsif($this->minOccur) { |
194 | 47 # we don't have a value but it's a mandatory property |
103 | 48 return new IMPL::DOM::Schema::ValidationError( |
236 | 49 message => $this->messageRequired, |
50 node => $node, | |
51 schema => $this, | |
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; |