annotate Lib/IMPL/DOM/Document.pm @ 394:2c14f66efa08

minor changes
author cin
date Tue, 18 Feb 2014 18:17:20 +0400
parents 010ceafd0c5a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
1 package IMPL::DOM::Document;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
4
280
c6d0f889ef87 +IMPL::declare now supports meta attributes
cin
parents: 194
diff changeset
5 use IMPL::lang;
368
010ceafd0c5a form metadata + tests
cin
parents: 315
diff changeset
6 use IMPL::Const qw(:prop);
315
77df11605d3a code cleanup
cin
parents: 280
diff changeset
7 use IMPL::declare {
77df11605d3a code cleanup
cin
parents: 280
diff changeset
8 require => {
77df11605d3a code cleanup
cin
parents: 280
diff changeset
9 DOMNode => 'IMPL::DOM::Node'
77df11605d3a code cleanup
cin
parents: 280
diff changeset
10 },
77df11605d3a code cleanup
cin
parents: 280
diff changeset
11 base => [
77df11605d3a code cleanup
cin
parents: 280
diff changeset
12 DOMNode => '@_'
368
010ceafd0c5a form metadata + tests
cin
parents: 315
diff changeset
13 ],
010ceafd0c5a form metadata + tests
cin
parents: 315
diff changeset
14 props => [
010ceafd0c5a form metadata + tests
cin
parents: 315
diff changeset
15 schemaDocument => PROP_RW
315
77df11605d3a code cleanup
cin
parents: 280
diff changeset
16 ]
77df11605d3a code cleanup
cin
parents: 280
diff changeset
17 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
18
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
19 sub document {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
20 return $_[0];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
21 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
22
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
23 sub Create {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
24 my ($this,$nodeName,$class,$refProps) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
25
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 104
diff changeset
26 if ( ref $class eq 'HASH' ) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
27 $refProps = $class;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
28 $class = undef;
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 104
diff changeset
29 }
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 104
diff changeset
30
315
77df11605d3a code cleanup
cin
parents: 280
diff changeset
31 $class ||= DOMNode;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
32 $refProps ||= {};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
33
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
34 delete $refProps->{nodeName};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
35
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 77
diff changeset
36 die new IMPL::Exception("class is not specified") unless $class;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
37 return $class->new(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
38 nodeName => $nodeName,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
39 document => $this,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
40 %$refProps
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
41 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
42 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
43
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
44 sub save {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
45 my ($this,$writer) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
46
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
47 $writer->xmlDecl(undef,'yes');
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
48 $this->SUPER::save($writer);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
49 $writer->end();
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
50 }
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
51
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
52 {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
53 my $empty;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
54 sub Empty() {
368
010ceafd0c5a form metadata + tests
cin
parents: 315
diff changeset
55 return $empty ? $empty : ($empty = __PACKAGE__->new(nodeName => 'Empty'));
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
56 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
57 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
58
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
59 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
60 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
61
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
62 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
63
77
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
64 =head1 NAME
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
65
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
66 C<IMPL::DOM::Document> DOM документ.
77
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
67
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
68 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
69
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
70 Документ, позволяет создавать узлы определенных типов, что позволяет абстрагироваться
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
71 от механизмов реального создания объектов. Т.о. например C<IMPL::DOM::Navigator::Builder>
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
72 может формировать произвольные документы.
77
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
73
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
74 =head1 SYNOPSIS
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
75
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
76 =begin code
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
77
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
78 package MyDocument;
165
76515373dac0 Added Class::Template,
wizard
parents: 152
diff changeset
79 use parent qw(IMPL::DOM::Document);
77
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
80
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
81 sub Create {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
82 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
83 my ($name,$class,$hashProps) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
84
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
85 if ($class eq 'Info') {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
86 return MyInfo->new($name,$hashProps->{date},$hashProps->{description});
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
87 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
88 # leave as it is
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
89 return $this->SUPER::Create(@_);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
90 }
77
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
91 }
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
92
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
93 =end code
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
94
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
95 =head1 METHODS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
96
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
97 =over
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
98
77
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
99 =item C< Create($nodeName,$class,$hashProps) >
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
100
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
101 Реализация по умолчанию. Создает узел определеннго типа с определенным именем и свойствами.
77
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
102
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
103 =begin code
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
104
77
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
105 sub Create {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
106 my ($this,$nodeName,$class,$hashProps) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
107
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
108 return $class->new (
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
109 nodeName => $nodeName,
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
110 document => $this,
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
111 %$hashProps
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
112 );
77
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
113 }
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
114
9d24db321029 Refactoring Web::TT
wizard
parents: 49
diff changeset
115 =end code
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
116
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
117 =item C< save($writer) >
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
118
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
119 Сохраняет документ в виде XML узла и вызывает C<< $writer->end() >>.
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
120
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
121 =over
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
122
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
123 =item C<$writer>
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
124
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
125 Объект с интерфейсом C<XML::Writer> который будет использован для записи
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
126 содержимого документа
152
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
127
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
128 =back
1e7f03414b65 DOM: schema improvements
wizard
parents: 148
diff changeset
129
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
130 =back
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
131
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 37
diff changeset
132 =cut