diff Lib/IMPL/DOM/Schema/Validator/RegExp.pm @ 389:5aff94ba842f

DOM Schema refactoring complete
author cin
date Wed, 12 Feb 2014 13:36:24 +0400
parents b8c724f6de36
children
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Schema/Validator/RegExp.pm	Tue Feb 11 20:22:01 2014 +0400
+++ b/Lib/IMPL/DOM/Schema/Validator/RegExp.pm	Wed Feb 12 13:36:24 2014 +0400
@@ -1,27 +1,30 @@
 package IMPL::DOM::Schema::Validator::RegExp;
 use strict;
-use parent qw(IMPL::DOM::Schema::Validator);
 
-our %CTOR = (
-    'IMPL::DOM::Schema::Validator' => sub {
-        my %args = @_;
-        $args{nodeName} ||= 'RegExp';
-        %args;
-    }
-);
-
-use IMPL::Class::Property;
-
-BEGIN {
-    public property message => prop_all;
-    public property launder => prop_all;
-    private property _rx => prop_all;
-}
+use IMPL::Const qw(:prop);
+use IMPL::declare {
+	require => {
+		Label => 'IMPL::DOM::Schema::Label',
+		ValidationError => 'IMPL::DOM::Schema::ValidationError'
+	},
+	base => [
+		'IMPL::DOM::Schema::Validator' => sub {
+	        my %args = @_;
+	        $args{nodeName} ||= 'RegExp';
+	        %args;
+	    }
+	],
+	props => [
+		message => { get => 1, set =>1, dom =>1 },
+		launder => { get => 1, set =>1, dom =>1 },
+		_rx => { get=> 1, set=> 1}
+	]
+};
 
 sub CTOR {
     my ($this,%args) = @_;
     
-    $this->message($args{message} || "A %node.nodeName% doesn't match to the format %schema.display%");
+    $this->message($args{message} || "A %node.nodeName% doesn't match to the format %schemaNode.label%");
 }
 
 sub Validate {
@@ -29,11 +32,11 @@
     
     my $rx = $this->_rx() || $this->_rx( map qr{$_}, $this->nodeValue );
     
-    return new IMPL::DOM::Schema::ValidationError(
+    return ValidationError->new (
         node => $node,
-        source => $ctx && $ctx->{Source} || $this->parentNode,
-        schema => $this->parentNode,
-        message => $this->message
+        schemaNode => $ctx->{schemaNode},
+        schemaType => $ctx->{schemaType},
+        message => $this->_MakeLabel($this->message)
     ) unless (not $node->isComplex) and $node->nodeValue =~ /($rx)/;
     
     $node->nodeValue($1) if $this->launder;
@@ -41,4 +44,14 @@
     return ();
 }
 
+sub _MakeLabel {
+	my ($this,$label) = @_;
+	
+	if ($label =~ /^ID:(\w+)$/) {
+		return Label->new($this->document->stringMap, $1);
+	} else {
+		return $label;
+	}
+}
+
 1;