comparison Lib/IMPL/DOM/Schema/SimpleNode.pm @ 388:648dfaf642e0

DOM refactoring, removed inflators from DOM Schema, DOM validation - in progress
author cin
date Tue, 11 Feb 2014 20:22:01 +0400
parents 4ddb27ff4a0b
children
comparison
equal deleted inserted replaced
387:4cc6cc370fb2 388:648dfaf642e0
1 package IMPL::DOM::Schema::SimpleNode; 1 package IMPL::DOM::Schema::SimpleNode;
2 use strict; 2 use strict;
3 use warnings; 3 use warnings;
4 4
5 use parent qw(IMPL::DOM::Schema::Node); 5 use IMPL::declare {
6 use IMPL::Class::Property; 6 base => [
7 use IMPL::DOM::Property qw(_dom); 7 'IMPL::DOM::Schema::Node' => sub {
8 8 my %args = @_;
9 BEGIN { 9 $args{nodeName} ||= 'SimpleNode';
10 public _dom _direct property inflator => prop_get; 10 %args
11 public _dom _direct property messageInflateError => prop_get; 11 }
12 } 12 ]
13 13 };
14 our %CTOR = (
15 'IMPL::DOM::Schema::Node' => sub {
16 my %args = @_;
17 $args{nodeName} ||= 'SimpleNode';
18 delete @args{qw(inflator messageInflateError)};
19 %args
20 }
21 );
22
23 sub CTOR {
24 my ($this,%args) = @_;
25
26 if ( $args{inflator} ) {
27 $this->{$inflator} = $args{inflator} ;
28 $this->{$messageInflateError} = exists $args{messageInflateError} ? $args{messageInflateError} : 'Failed to inflate nodeValue %node.path%: %error%';
29 }
30 }
31 14
32 sub Validate { 15 sub Validate {
33 my ($this,$node,$ctx) = @_; 16 my ($this,$node,$ctx) = @_;
17
18 $ctx->{schemaNode} ||= $this; # для безымянных типов
19
20 $ctx->{schemaType} = $this;
34 21
35 my @result; 22 my @result;
36 23
37 push @result, $_->Validate($node,$ctx) foreach $this->childNodes; 24 push @result, $_->Validate($node,$ctx) foreach $this->childNodes;
38 25
39 return @result; 26 return @result;
40 }
41
42 sub inflateValue {
43 my ($this,$value) = @_;
44
45 if ( my $inflator = $this->inflator ) {
46 return $inflator->new($value,$this);
47 } else {
48 return $value;
49 }
50 } 27 }
51 28
52 1; 29 1;
53 30
54 __END__ 31 __END__