Mercurial > pub > Impl
comparison lib/IMPL/DOM/Schema/Validator/RegExp.pm @ 407:c6e90e02dd17 ref20150831
renamed Lib->lib
| author | cin |
|---|---|
| date | Fri, 04 Sep 2015 19:40:23 +0300 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 406:f23fcb19d3c1 | 407:c6e90e02dd17 |
|---|---|
| 1 package IMPL::DOM::Schema::Validator::RegExp; | |
| 2 use strict; | |
| 3 | |
| 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 }; | |
| 23 | |
| 24 sub CTOR { | |
| 25 my ($this,%args) = @_; | |
| 26 | |
| 27 $this->message($args{message} || "A %node.nodeName% doesn't match to the format %schemaNode.label%"); | |
| 28 } | |
| 29 | |
| 30 sub Validate { | |
| 31 my ($this,$node,$ctx) = @_; | |
| 32 | |
| 33 my $rx = $this->_rx() || $this->_rx( map qr{$_}, $this->nodeValue ); | |
| 34 | |
| 35 return ValidationError->new ( | |
| 36 node => $node, | |
| 37 schemaNode => $ctx->{schemaNode}, | |
| 38 schemaType => $ctx->{schemaType}, | |
| 39 message => $this->_MakeLabel($this->message) | |
| 40 ) unless (not $node->isComplex) and $node->nodeValue =~ /($rx)/; | |
| 41 | |
| 42 $node->nodeValue($1) if $this->launder; | |
| 43 | |
| 44 return (); | |
| 45 } | |
| 46 | |
| 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 | |
| 57 1; |
