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