view Lib/IMPL/DOM/Schema/Validator/RegExp.pm @ 109:ddf0f037d460

IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT) Some fixes to the web document model. (beta version)
author wizard
date Mon, 17 May 2010 05:12:08 +0400
parents a6e9759ff88a
children e6447ad85cb4
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;