view Lib/IMPL/DOM/Document.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 9d24db321029
children e6447ad85cb4
line wrap: on
line source

package IMPL::DOM::Document;
use strict;
use warnings;

use base qw(IMPL::DOM::Node);

__PACKAGE__->PassThroughArgs;

sub document {
    return $_[0];
}

sub Create {
    my ($this,$nodeName,$class,$refProps) = @_;
    
    $refProps ||= {};
    
    delete $refProps->{nodeName};
    
    die new IMPL::Exception("class is not specified") unless $class;
    return $class->new(
        nodeName => $nodeName,
        document => $this,
        %$refProps
    );
}

{
    my $empty;
    sub Empty() {
        return $empty ? $empty : $empty = __PACKAGE__->new(nodeName => 'Empty');
    }
}

1;
__END__

=pod

=head1 NAME

C<IMPL::DOM::Document> DOM документ.

=head1 DESCRIPTION

Документ, позволяет создавать узлы определенных типов, что позволяет абстрагироваться
от механизмов реального создания объектов. Т.о. например C<IMPL::DOM::Navigator::Builder>
может формировать произвольные документы.

=head1 SYNOPSIS

=begin code

package MyDocument;
use base qw(IMPL::DOM::Document);

sub Create {
	my $this = shift;
	my ($name,$class,$hashProps) = @_;
	
	if ($class eq 'Info') {
		return MyInfo->new($name,$hashProps->{date},$hashProps->{description});
	} else {
		# leave as it is
		return $this->SUPER::Create(@_);
	}
}

=end code

=head1 METHODS

=over

=item C< Create($nodeName,$class,$hashProps) >

Реализация по умолчанию. Создает узел определеннго типа с определенным именем и свойствами.

=begin code

sub Create {
	my ($this,$nodeName,$class,$hashProps) = @_;
	
	return $class->new (
		nodeName => $nodeName,
		document => $this,
		%$hashProps
	);
}

=end code

=back

=cut