Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Document.pm @ 403:7171a8e2e2ba
dirty fix for url encoding
| author | sergey | 
|---|---|
| date | Tue, 20 May 2014 01:26:45 +0400 | 
| parents | 010ceafd0c5a | 
| children | 
| rev | line source | 
|---|---|
| 49 | 1 package IMPL::DOM::Document; | 
| 2 use strict; | |
| 3 use warnings; | |
| 4 | |
| 280 | 5 use IMPL::lang; | 
| 368 | 6 use IMPL::Const qw(:prop); | 
| 315 | 7 use IMPL::declare { | 
| 8 require => { | |
| 9 DOMNode => 'IMPL::DOM::Node' | |
| 10 }, | |
| 11 base => [ | |
| 12 DOMNode => '@_' | |
| 368 | 13 ], | 
| 14 props => [ | |
| 15 schemaDocument => PROP_RW | |
| 315 | 16 ] | 
| 17 }; | |
| 49 | 18 | 
| 19 sub document { | |
| 20 return $_[0]; | |
| 21 } | |
| 22 | |
| 23 sub Create { | |
| 24 my ($this,$nodeName,$class,$refProps) = @_; | |
| 25 | |
| 
148
 
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
 
wizard 
parents: 
104 
diff
changeset
 | 
26 if ( ref $class eq 'HASH' ) { | 
| 194 | 27 $refProps = $class; | 
| 28 $class = undef; | |
| 
148
 
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
 
wizard 
parents: 
104 
diff
changeset
 | 
29 } | 
| 
 
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
 
wizard 
parents: 
104 
diff
changeset
 | 
30 | 
| 315 | 31 $class ||= DOMNode; | 
| 49 | 32 $refProps ||= {}; | 
| 33 | |
| 34 delete $refProps->{nodeName}; | |
| 35 | |
| 
104
 
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
 
wizard 
parents: 
77 
diff
changeset
 | 
36 die new IMPL::Exception("class is not specified") unless $class; | 
| 49 | 37 return $class->new( | 
| 38 nodeName => $nodeName, | |
| 39 document => $this, | |
| 40 %$refProps | |
| 41 ); | |
| 42 } | |
| 43 | |
| 152 | 44 sub save { | 
| 194 | 45 my ($this,$writer) = @_; | 
| 46 | |
| 47 $writer->xmlDecl(undef,'yes'); | |
| 48 $this->SUPER::save($writer); | |
| 49 $writer->end(); | |
| 152 | 50 } | 
| 51 | |
| 49 | 52 { | 
| 53 my $empty; | |
| 54 sub Empty() { | |
| 368 | 55 return $empty ? $empty : ($empty = __PACKAGE__->new(nodeName => 'Empty')); | 
| 49 | 56 } | 
| 57 } | |
| 58 | |
| 59 1; | |
| 60 __END__ | |
| 61 | |
| 62 =pod | |
| 63 | |
| 77 | 64 =head1 NAME | 
| 65 | |
| 180 | 66 C<IMPL::DOM::Document> DOM документ. | 
| 77 | 67 | 
| 49 | 68 =head1 DESCRIPTION | 
| 69 | |
| 180 | 70 Документ, позволяет создавать узлы определенных типов, что позволяет абстрагироваться | 
| 71 от механизмов реального создания объектов. Т.о. например C<IMPL::DOM::Navigator::Builder> | |
| 72 может формировать произвольные документы. | |
| 77 | 73 | 
| 74 =head1 SYNOPSIS | |
| 75 | |
| 76 =begin code | |
| 77 | |
| 78 package MyDocument; | |
| 165 | 79 use parent qw(IMPL::DOM::Document); | 
| 77 | 80 | 
| 81 sub Create { | |
| 194 | 82 my $this = shift; | 
| 83 my ($name,$class,$hashProps) = @_; | |
| 84 | |
| 85 if ($class eq 'Info') { | |
| 86 return MyInfo->new($name,$hashProps->{date},$hashProps->{description}); | |
| 87 } else { | |
| 88 # leave as it is | |
| 89 return $this->SUPER::Create(@_); | |
| 90 } | |
| 77 | 91 } | 
| 92 | |
| 93 =end code | |
| 94 | |
| 49 | 95 =head1 METHODS | 
| 96 | |
| 97 =over | |
| 98 | |
| 77 | 99 =item C< Create($nodeName,$class,$hashProps) > | 
| 100 | |
| 180 | 101 Реализация по умолчанию. Создает узел определеннго типа с определенным именем и свойствами. | 
| 77 | 102 | 
| 103 =begin code | |
| 49 | 104 | 
| 77 | 105 sub Create { | 
| 194 | 106 my ($this,$nodeName,$class,$hashProps) = @_; | 
| 107 | |
| 108 return $class->new ( | |
| 109 nodeName => $nodeName, | |
| 110 document => $this, | |
| 111 %$hashProps | |
| 112 ); | |
| 77 | 113 } | 
| 114 | |
| 115 =end code | |
| 49 | 116 | 
| 152 | 117 =item C< save($writer) > | 
| 118 | |
| 180 | 119 Сохраняет документ в виде XML узла и вызывает C<< $writer->end() >>. | 
| 152 | 120 | 
| 121 =over | |
| 122 | |
| 123 =item C<$writer> | |
| 124 | |
| 180 | 125 Объект с интерфейсом C<XML::Writer> который будет использован для записи | 
| 126 содержимого документа | |
| 152 | 127 | 
| 128 =back | |
| 129 | |
| 49 | 130 =back | 
| 131 | |
| 132 =cut | 
