comparison Lib/IMPL/DOM/Schema/NodeSet.pm @ 7:94d47b388442

Улучшены тесты Исправлены ошибки Улучшена документация Работа над схемой DOM
author Sergey
date Mon, 24 Aug 2009 01:05:34 +0400
parents
children 1ca530e5c9c5
comparison
equal deleted inserted replaced
6:e2cd73ccc5bd 7:94d47b388442
1 package IMPL::DOM::Schema::NodeSet;
2 use strict;
3 use warnings;
4
5 use base qw(IMPL::DOM::Schema::Item);
6 use IMPL::Class::Property;
7
8 BEGIN {
9 public property UnexpectedMessage => prop_all;
10 public property MaxMessage => prop_all;
11 public property MinMessage => prop_all;
12 }
13
14 sub Validate {
15 my ($this,$node) = @_;
16
17 my @errors;
18
19 my %nodes = map {
20 $_->nodeName ,
21 {Schema => $_, Min => $_->minOccur, Max => $_->maxOccur, Seen => 0 }
22 } @{$this->childNodes};
23
24 foreach my $child ( @{$node->childNodes} ) {
25 if (my $info = $nodes{$child->nodeName}) {
26 $info->{Seen}++;
27 push @errors,{
28 Error => 1,
29 Source => $this,
30 Node => $child,
31 Message => $this->MaxMessage
32 } if ($info->{Seen} > $info->{Max});
33
34 push @errors,$info->{Schema}->Validate($child);
35 } else {
36 push @errors, {
37 Error => 1,
38 Source => $this,
39 Node => $child,
40 Message => $this->UnexpectedMessage
41 }
42 }
43 }
44
45 foreach my $info (values %nodes) {
46 push @errors, {
47 Error => 1,
48 Source => $this,
49 Message => $this->MinMessage
50 } if $info->{Min} > $info->{Seen};
51 }
52
53 return @errors;
54 }
55
56 1;
57
58 __END__
59
60 =pod
61
62 =head1 DESCRIPTION
63
64 . .
65 C<IMPL::DOM::Schema::ComplexNode> C<IMPL::DOM::Schema::SimpleNode>.
66
67 ,
68 ,
69 .
70
71 =cut