view Lib/IMPL/DOM/Schema/SimpleNode.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 c289ed9662ca
children e30bdd040fe3
line wrap: on
line source

package IMPL::DOM::Schema::SimpleNode;
use strict;
use warnings;

use base qw(IMPL::DOM::Schema::Node);
use IMPL::Class::Property;
use IMPL::Class::Property::Direct;

BEGIN {
	public _direct property inflator => prop_get;
	public _direct property messageInflateError => prop_get;
}

our %CTOR = (
    'IMPL::DOM::Schema::Node' => sub {my %args = @_; $args{nodeName} ||= 'SimpleNode'; %args}
);

sub CTOR {
	my ($this,%args) = @_;
	
	$this->{$inflator} = $args{inflator} if $args{inflator};
	$this->{$messageInflateError} = $args{messageInflateError} || 'Failed to inflate nodeValue %Node.path%: %Error%';
}

sub Validate {
    my ($this,$node,$ctx) = @_;
    
    my @result;
    
    push @result, $_->Validate($node,$ctx) foreach $this->childNodes;
    
    return @result;
}

sub inflateValue {
	my ($this,$value) = @_;
	
	if ( my $inflator = $this->inflator ) {
		return $inflator->new($value);
	} else {
		return $value;
	}
}

1;

__END__

=pod

=head1 NAME

C<IMPL::DOM::SimpleNode> - узел с текстом.

=head1 DESCRIPTION

Узел имеющий простое значение. Данный узел может содержать ограничения
на простое значение.

Производит валидацию содержимого, при постоении DOM модели не имеет специального
типа и будет создан в виде C<IMPL::DOM::Node>.

Также определяет как будет воссоздано значение узла в DOM модели.

=cut