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