view Lib/IMPL/DOM/Document.pm @ 171:59e5fcb59d86

Исправления, изменена концепция веб-форм
author sourcer
date Mon, 06 Jun 2011 03:30:36 +0400
parents 76515373dac0
children d1676be8afcc
line wrap: on
line source

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

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

__PACKAGE__->PassThroughArgs;

sub document {
    return $_[0];
}

sub Create {
    my ($this,$nodeName,$class,$refProps) = @_;
    
    if ( ref $class eq 'HASH' ) {
    	$refProps = $class;
    	$class = undef;
    }
    
    $class ||= typeof IMPL::DOM::Node;
    $refProps ||= {};
    
    delete $refProps->{nodeName};
    
    die new IMPL::Exception("class is not specified") unless $class;
    return $class->new(
        nodeName => $nodeName,
        document => $this,
        %$refProps
    );
}

sub save {
	my ($this,$writer) = @_;
	
	$writer->xmlDecl(undef,'yes');
	$this->SUPER::save($writer);
	$writer->end();
}

{
    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 parent 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

=item C< save($writer) >

    XML    C<< $writer->end() >>.

=over

=item C<$writer>

   C<XML::Writer>     
 

=back

=back

=cut