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