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 {
|
|
13 public property RequiredMessage => prop_all;
|
|
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';
|
|
23
|
|
24 return %args;
|
|
25 }
|
|
26 );
|
|
27
|
|
28 sub CTOR {
|
|
29 my ($this,%args) = @_;
|
|
30
|
|
31 $this->RequiredMessage($args{RequiredMessage} || 'A property %Schema.name% is required in the %Node.qname%');
|
|
32 }
|
|
33
|
|
34 sub Validate {
|
|
35 my ($this,$node) = @_;
|
|
36
|
|
37 if ($this->minOccur) {
|
|
38 my $prop = $this->name;
|
101
|
39 my $nodeProp = new IMPL::DOM::Node(nodeName => '::property', nodeValue => eval { $node->$prop() } || $node->nodeProperty($prop));
|
49
|
40
|
|
41 if (! $nodeProp->nodeValue) {
|
|
42 return new IMPL::DOM::Schema::ValidationError(
|
|
43 Message => $this->RequiredMessage,
|
|
44 Node => $node,
|
|
45 Schema => $this
|
|
46 );
|
|
47 }
|
|
48 return $this->SUPER::Validate($nodeProp);
|
|
49 } else {
|
|
50 return ();
|
|
51 }
|
|
52 }
|
|
53
|
|
54 1;
|