annotate lib/IMPL/DOM/Document.pm @ 407:c6e90e02dd17 ref20150831

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