annotate lib/IMPL/DOM/Schema/Validator/RegExp.pm @ 420:df591e3afd10 ref20150831

sync
author cin
date Sat, 25 Feb 2017 22:35:26 +0300
parents c6e90e02dd17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::DOM::Schema::Validator::RegExp;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4 use IMPL::Const qw(:prop);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 use IMPL::declare {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 require => {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 Label => 'IMPL::DOM::Schema::Label',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8 ValidationError => 'IMPL::DOM::Schema::ValidationError'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 },
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 base => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 'IMPL::DOM::Schema::Validator' => sub {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12 my %args = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13 $args{nodeName} ||= 'RegExp';
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 %args;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16 ],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17 props => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18 message => { get => 1, set =>1, dom =>1 },
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 launder => { get => 1, set =>1, dom =>1 },
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20 _rx => { get=> 1, set=> 1}
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 ]
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 sub CTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25 my ($this,%args) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 $this->message($args{message} || "A %node.nodeName% doesn't match to the format %schemaNode.label%");
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30 sub Validate {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31 my ($this,$node,$ctx) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33 my $rx = $this->_rx() || $this->_rx( map qr{$_}, $this->nodeValue );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35 return ValidationError->new (
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 node => $node,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37 schemaNode => $ctx->{schemaNode},
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38 schemaType => $ctx->{schemaType},
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 message => $this->_MakeLabel($this->message)
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40 ) unless (not $node->isComplex) and $node->nodeValue =~ /($rx)/;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42 $node->nodeValue($1) if $this->launder;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44 return ();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47 sub _MakeLabel {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48 my ($this,$label) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50 if ($label =~ /^ID:(\w+)$/) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51 return Label->new($this->document->stringMap, $1);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 return $label;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57 1;