view Lib/IMPL/DOM/Schema/Validator/RegExp.pm @ 102:cf3b6ef2be22

Schema beta version
author wizard
date Fri, 07 May 2010 08:05:23 +0400
parents df6b4f054957
children 196bf443b5e1
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) = @_;
	
	$this->message("A %Node.nodeName% doesn't match to the format %Schema.name%");
}

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

1;