annotate Lib/IMPL/DOM/Schema/Property.pm @ 102:cf3b6ef2be22

Schema beta version
author wizard
date Fri, 07 May 2010 08:05:23 +0400
parents d8dc6cad3f55
children c289ed9662ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
1 package IMPL::DOM::Schema::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
4
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
5 use base qw(IMPL::DOM::Schema::SimpleNode);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
6 require IMPL::DOM::Schema;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
7 require IMPL::DOM::Node;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
8 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
9
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
10 __PACKAGE__->PassThroughArgs;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
11
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
12 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
13 public property RequiredMessage => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
14 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
15
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
16 our %CTOR = (
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
17 'IMPL::DOM::Schema::SimpleNode' => sub {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
18 my %args = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
19
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
20 $args{maxOccur} = 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
21 $args{minOccur} = delete $args{optional} ? 0 : 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
22 $args{nodeName} ||= 'Property';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
23
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
24 return %args;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
25 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
26 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
27
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
28 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
29 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
30
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
31 $this->RequiredMessage($args{RequiredMessage} || 'A property %Schema.name% is required in the %Node.qname%');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
32 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
33
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
34 sub Validate {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
35 my ($this,$node) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
36
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
37 if ($this->minOccur) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
38 my $prop = $this->name;
101
d8dc6cad3f55 Schema in progress
wizard
parents: 49
diff changeset
39 my $nodeProp = new IMPL::DOM::Node(nodeName => '::property', nodeValue => eval { $node->$prop() } || $node->nodeProperty($prop));
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
40
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
41 if (! $nodeProp->nodeValue) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
42 return new IMPL::DOM::Schema::ValidationError(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
43 Message => $this->RequiredMessage,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
44 Node => $node,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
45 Schema => $this
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
46 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
47 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
48 return $this->SUPER::Validate($nodeProp);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
49 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
50 return ();
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
51 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
52 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
53
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
54 1;