annotate Lib/IMPL/DOM/Schema/Validator/RegExp.pm @ 391:2287c72f303a

code cleanup
author cin
date Thu, 13 Feb 2014 20:17:22 +0400
parents 5aff94ba842f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100
df6b4f054957 Schema in progress
wizard
parents:
diff changeset
1 package IMPL::DOM::Schema::Validator::RegExp;
236
2904da230022 DOM refactoring
sergey
parents: 194
diff changeset
2 use strict;
100
df6b4f054957 Schema in progress
wizard
parents:
diff changeset
3
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
4 use IMPL::Const qw(:prop);
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
5 use IMPL::declare {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
6 require => {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
7 Label => 'IMPL::DOM::Schema::Label',
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
8 ValidationError => 'IMPL::DOM::Schema::ValidationError'
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
9 },
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
10 base => [
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
11 'IMPL::DOM::Schema::Validator' => sub {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
12 my %args = @_;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
13 $args{nodeName} ||= 'RegExp';
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
14 %args;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
15 }
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
16 ],
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
17 props => [
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
18 message => { get => 1, set =>1, dom =>1 },
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
19 launder => { get => 1, set =>1, dom =>1 },
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
20 _rx => { get=> 1, set=> 1}
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
21 ]
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
22 };
100
df6b4f054957 Schema in progress
wizard
parents:
diff changeset
23
df6b4f054957 Schema in progress
wizard
parents:
diff changeset
24 sub CTOR {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
25 my ($this,%args) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
26
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
27 $this->message($args{message} || "A %node.nodeName% doesn't match to the format %schemaNode.label%");
100
df6b4f054957 Schema in progress
wizard
parents:
diff changeset
28 }
df6b4f054957 Schema in progress
wizard
parents:
diff changeset
29
df6b4f054957 Schema in progress
wizard
parents:
diff changeset
30 sub Validate {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
31 my ($this,$node,$ctx) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
32
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
33 my $rx = $this->_rx() || $this->_rx( map qr{$_}, $this->nodeValue );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
34
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
35 return ValidationError->new (
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
36 node => $node,
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
37 schemaNode => $ctx->{schemaNode},
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
38 schemaType => $ctx->{schemaType},
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
39 message => $this->_MakeLabel($this->message)
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
40 ) unless (not $node->isComplex) and $node->nodeValue =~ /($rx)/;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
41
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
42 $node->nodeValue($1) if $this->launder;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
43
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
44 return ();
100
df6b4f054957 Schema in progress
wizard
parents:
diff changeset
45 }
df6b4f054957 Schema in progress
wizard
parents:
diff changeset
46
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
47 sub _MakeLabel {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
48 my ($this,$label) = @_;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
49
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
50 if ($label =~ /^ID:(\w+)$/) {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
51 return Label->new($this->document->stringMap, $1);
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
52 } else {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
53 return $label;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
54 }
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
55 }
5aff94ba842f DOM Schema refactoring complete
cin
parents: 238
diff changeset
56
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
57 1;