Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/Property.pm @ 194:4d0e1962161c
Replaced tabs with spaces
IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author | cin |
---|---|
date | Tue, 10 Apr 2012 20:08:29 +0400 |
parents | 76515373dac0 |
children | 2904da230022 |
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'; | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
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 | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
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( |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
50 Message => $this->messageRequired, |
103 | 51 Node => $node, |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
52 Schema => $this, |
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
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; |