annotate Lib/IMPL/DOM/Schema/Property.pm @ 24:7f00786f8210

Первая рабочая реазизация схемы и навигаторов
author Sergey
date Mon, 05 Oct 2009 00:48:49 +0400
parents fafe56cfcd69
children 9dd67fa91ee3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
1 package IMPL::DOM::Schema::Property;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
2 use strict;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
3 use warnings;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
4
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
5 use base qw(IMPL::DOM::Schema::SimpleNode);
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
6 require IMPL::DOM::Schema;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
7 require IMPL::DOM::Node;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
8 use IMPL::Class::Property;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
9
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
10 __PACKAGE__->PassThroughArgs;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
11
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
12 BEGIN {
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
13 public property RequiredMessage => prop_all;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
14 }
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
15
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
16 our %CTOR = (
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
17 'IMPL::DOM::Schema::SimpleNode' => sub {
21
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
18 my %args = @_;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
19
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
20 $args{maxOccur} = 1;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
21 $args{minOccur} = delete $args{optional} ? 0 : 1;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
22 $args{nodeName} ||= 'Property';
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
23
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
24 return %args;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
25 }
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
26 );
21
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
27
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
28 sub CTOR {
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
29 my ($this,%args) = @_;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
30
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
31 $this->RequiredMessage($args{RequiredMessage} || 'A property %Schema.name% is required');
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
32 }
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
33
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
34 sub Validate {
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
35 my ($this,$node) = @_;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
36
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
37 if ($this->minOccur) {
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
38 my $prop = $this->name;
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
39 my $nodeProp = new IMPL::DOM::Node(nodeName => '::property', nodeValue => $node->$prop() || $node->nodePropety($prop));
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
40
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
41 if (! $nodeProp->nodeValue) {
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
42 return new IMPL::DOM::Schema::ValidationError(
21
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
43 Message =>
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
44 );
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
45 }
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
46 return $this->SUPER::Validate($nodeProp);
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
47 } else {
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
48 return ();
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
49 }
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
50 }
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
51
fafe56cfcd69 temp commit
Sergey
parents:
diff changeset
52 1;