Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Document.pm @ 244:a02b110da931
refactoring
fixed binding to CGI query parameters with multiple values
author | sergey |
---|---|
date | Mon, 22 Oct 2012 04:09:27 +0400 |
parents | 4d0e1962161c |
children | c6d0f889ef87 |
rev | line source |
---|---|
49 | 1 package IMPL::DOM::Document; |
2 use strict; | |
3 use warnings; | |
4 | |
165 | 5 use parent qw(IMPL::DOM::Node); |
49 | 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' ) { |
194 | 17 $refProps = $class; |
18 $class = undef; | |
148
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 { |
194 | 35 my ($this,$writer) = @_; |
36 | |
37 $writer->xmlDecl(undef,'yes'); | |
38 $this->SUPER::save($writer); | |
39 $writer->end(); | |
152 | 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 | |
180 | 56 C<IMPL::DOM::Document> DOM документ. |
77 | 57 |
49 | 58 =head1 DESCRIPTION |
59 | |
180 | 60 Документ, позволяет создавать узлы определенных типов, что позволяет абстрагироваться |
61 от механизмов реального создания объектов. Т.о. например C<IMPL::DOM::Navigator::Builder> | |
62 может формировать произвольные документы. | |
77 | 63 |
64 =head1 SYNOPSIS | |
65 | |
66 =begin code | |
67 | |
68 package MyDocument; | |
165 | 69 use parent qw(IMPL::DOM::Document); |
77 | 70 |
71 sub Create { | |
194 | 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 } | |
77 | 81 } |
82 | |
83 =end code | |
84 | |
49 | 85 =head1 METHODS |
86 | |
87 =over | |
88 | |
77 | 89 =item C< Create($nodeName,$class,$hashProps) > |
90 | |
180 | 91 Реализация по умолчанию. Создает узел определеннго типа с определенным именем и свойствами. |
77 | 92 |
93 =begin code | |
49 | 94 |
77 | 95 sub Create { |
194 | 96 my ($this,$nodeName,$class,$hashProps) = @_; |
97 | |
98 return $class->new ( | |
99 nodeName => $nodeName, | |
100 document => $this, | |
101 %$hashProps | |
102 ); | |
77 | 103 } |
104 | |
105 =end code | |
49 | 106 |
152 | 107 =item C< save($writer) > |
108 | |
180 | 109 Сохраняет документ в виде XML узла и вызывает C<< $writer->end() >>. |
152 | 110 |
111 =over | |
112 | |
113 =item C<$writer> | |
114 | |
180 | 115 Объект с интерфейсом C<XML::Writer> который будет использован для записи |
116 содержимого документа | |
152 | 117 |
118 =back | |
119 | |
49 | 120 =back |
121 | |
122 =cut |