view Lib/IMPL/DOM/Schema/Validator/RegExp.pm @ 104:196bf443b5e1

DOM::Schema RC0 inflators support, validation and some other things, Minor and major fixes almost for everything. A 'Source' property of the ValidationErrors generated from a NodeSet or a NodeList is subject to change in the future.
author wizard
date Tue, 11 May 2010 02:42:59 +0400
parents df6b4f054957
children a6e9759ff88a
line wrap: on
line source

package IMPL::DOM::Schema::Validator::RegExp;

use base 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;
}

sub CTOR {
	my ($this,%args) = @_;
	
	$this->message($args{message} || "A %Node.nodeName% doesn't match to the format %Schema.display%");
}

sub Validate {
	my ($this,$node,$ctx) = @_;
	
	my $rx = $this->nodeValue;
	return new IMPL::DOM::Schema::ValidationError(
		Node => $node,
		Source => ( $ctx && $ctx->{Source} ) || $this->parentNode,
		Schema => $this->parentNode,
		Message => $this->message
	) unless (not $node->isComplex) and $node->nodeValue =~ /$rx/;
	return ();
}

1;