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