1 |
wakaba |
1.2 |
package Message::DOM::Entity; |
2 |
wakaba |
1.1 |
use strict; |
3 |
wakaba |
1.7 |
our $VERSION=do{my @r=(q$Revision: 1.6 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
4 |
wakaba |
1.2 |
push our @ISA, 'Message::DOM::Node', 'Message::IF::Entity'; |
5 |
wakaba |
1.1 |
require Message::DOM::Node; |
6 |
|
|
|
7 |
|
|
sub ____new ($$$) { |
8 |
|
|
my $self = shift->SUPER::____new (shift); |
9 |
|
|
$$self->{node_name} = $_[0]; |
10 |
wakaba |
1.3 |
$$self->{child_nodes} = []; |
11 |
wakaba |
1.1 |
return $self; |
12 |
|
|
} # ____new |
13 |
|
|
|
14 |
|
|
sub AUTOLOAD { |
15 |
|
|
my $method_name = our $AUTOLOAD; |
16 |
|
|
$method_name =~ s/.*:://; |
17 |
|
|
return if $method_name eq 'DESTROY'; |
18 |
|
|
|
19 |
|
|
if ({ |
20 |
|
|
## Read-only attributes (trivial accessors) |
21 |
wakaba |
1.2 |
node_name => 1, |
22 |
wakaba |
1.7 |
owner_document_type_definition => 1, |
23 |
wakaba |
1.1 |
}->{$method_name}) { |
24 |
|
|
no strict 'refs'; |
25 |
|
|
eval qq{ |
26 |
|
|
sub $method_name (\$) { |
27 |
|
|
if (\@_ > 1) { |
28 |
|
|
require Carp; |
29 |
|
|
Carp::croak (qq<Can't modify read-only attribute>); |
30 |
|
|
} |
31 |
|
|
return \${\$_[0]}->{$method_name}; |
32 |
|
|
} |
33 |
|
|
}; |
34 |
|
|
goto &{ $AUTOLOAD }; |
35 |
|
|
} elsif ({ |
36 |
wakaba |
1.4 |
## Read-write attributes (boolean, trivial accessors) |
37 |
|
|
has_replacement_tree => 1, |
38 |
wakaba |
1.6 |
is_externally_declared => 1, |
39 |
wakaba |
1.4 |
}->{$method_name}) { |
40 |
|
|
no strict 'refs'; |
41 |
|
|
eval qq{ |
42 |
|
|
sub $method_name (\$;\$) { |
43 |
|
|
if (\@_ > 1) { |
44 |
|
|
if (\${\${\$_[0]}->{owner_document}}->{manakai_strict_error_checking} and |
45 |
|
|
\${\$_[0]}->{manakai_read_only}) { |
46 |
|
|
report Message::DOM::DOMException |
47 |
|
|
-object => \$_[0], |
48 |
|
|
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
49 |
|
|
-subtype => 'READ_ONLY_NODE_ERR'; |
50 |
|
|
} |
51 |
|
|
if (\$_[1]) { |
52 |
|
|
\${\$_[0]}->{$method_name} = 1; |
53 |
|
|
} else { |
54 |
|
|
delete \${\$_[0]}->{$method_name}; |
55 |
|
|
} |
56 |
|
|
} |
57 |
|
|
return \${\$_[0]}->{$method_name}; |
58 |
|
|
} |
59 |
|
|
}; |
60 |
|
|
goto &{ $AUTOLOAD }; |
61 |
|
|
} elsif ({ |
62 |
wakaba |
1.1 |
## Read-write attributes (DOMString, trivial accessors) |
63 |
wakaba |
1.6 |
input_encoding => 1, |
64 |
wakaba |
1.5 |
notation_name => 1, |
65 |
wakaba |
1.1 |
public_id => 1, |
66 |
|
|
system_id => 1, |
67 |
wakaba |
1.5 |
xml_encoding => 1, |
68 |
wakaba |
1.6 |
xml_version => 1, |
69 |
wakaba |
1.1 |
}->{$method_name}) { |
70 |
|
|
no strict 'refs'; |
71 |
|
|
eval qq{ |
72 |
wakaba |
1.4 |
sub $method_name (\$;\$) { |
73 |
wakaba |
1.1 |
if (\@_ > 1) { |
74 |
wakaba |
1.4 |
if (\${\$_[0]}->{strict_error_checking} and |
75 |
|
|
\${\$_[0]}->{manakai_read_only}) { |
76 |
|
|
report Message::DOM::DOMException |
77 |
|
|
-object => \$_[0], |
78 |
|
|
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
79 |
|
|
-subtype => 'READ_ONLY_NODE_ERR'; |
80 |
|
|
} |
81 |
|
|
if (defined \$_[1]) { |
82 |
|
|
\${\$_[0]}->{$method_name} = ''.\$_[1]; |
83 |
|
|
} else { |
84 |
|
|
delete \${\$_[0]}->{$method_name}; |
85 |
|
|
} |
86 |
wakaba |
1.1 |
} |
87 |
wakaba |
1.4 |
return \${\$_[0]}->{$method_name}; |
88 |
wakaba |
1.1 |
} |
89 |
|
|
}; |
90 |
|
|
goto &{ $AUTOLOAD }; |
91 |
|
|
} else { |
92 |
|
|
require Carp; |
93 |
|
|
Carp::croak (qq<Can't locate method "$AUTOLOAD">); |
94 |
|
|
} |
95 |
|
|
} # AUTOLOAD |
96 |
|
|
|
97 |
wakaba |
1.4 |
## |Node| attributes |
98 |
|
|
|
99 |
|
|
sub node_name ($); # read-only trivial accessor |
100 |
|
|
|
101 |
|
|
sub node_type () { 6 } # ENTITY_NODE |
102 |
|
|
|
103 |
|
|
## |Entity| attributes |
104 |
|
|
|
105 |
|
|
sub manakai_declaration_base_uri ($;$) { |
106 |
|
|
## NOTE: Same as |Notation|'s. |
107 |
|
|
|
108 |
|
|
if (@_ > 1) { |
109 |
|
|
if (${${$_[0]}->{owner_document}}->{strict_error_checking} and |
110 |
|
|
${$_[0]}->{manakai_read_only}) { |
111 |
|
|
report Message::DOM::DOMException |
112 |
|
|
-object => $_[0], |
113 |
|
|
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
114 |
|
|
-subtype => 'READ_ONLY_NODE_ERR'; |
115 |
|
|
} |
116 |
|
|
if (defined $_[1]) { |
117 |
|
|
${$_[0]}->{manakai_declaration_base_uri} = ''.$_[1]; |
118 |
|
|
} else { |
119 |
|
|
delete ${$_[0]}->{manakai_declaration_base_uri}; |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
if (defined wantarray) { |
124 |
|
|
if (defined ${$_[0]}->{manakai_declaration_base_uri}) { |
125 |
|
|
return ${$_[0]}->{manakai_declaration_base_uri}; |
126 |
|
|
} else { |
127 |
|
|
local $Error::Depth = $Error::Depth + 1; |
128 |
|
|
return $_[0]->base_uri; |
129 |
|
|
} |
130 |
|
|
} |
131 |
|
|
} # manakai_declaration_base_uri |
132 |
|
|
|
133 |
|
|
sub manakai_entity_base_uri ($;$) { |
134 |
|
|
my $self = $_[0]; |
135 |
|
|
if (@_ > 1) { |
136 |
|
|
if (${$$self->{owner_document}}->{strict_error_checking}) { |
137 |
|
|
if ($$self->{manakai_read_only}) { |
138 |
|
|
report Message::DOM::DOMException |
139 |
|
|
-object => $self, |
140 |
|
|
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
141 |
|
|
-subtype => 'READ_ONLY_NODE_ERR'; |
142 |
|
|
} |
143 |
|
|
} |
144 |
|
|
if (defined $_[1]) { |
145 |
|
|
$$self->{manakai_entity_base_uri} = ''.$_[1]; |
146 |
|
|
} else { |
147 |
|
|
delete $$self->{manakai_entity_base_uri}; |
148 |
|
|
} |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
if (defined wantarray) { |
152 |
|
|
if (defined $$self->{manakai_entity_base_uri}) { |
153 |
|
|
return $$self->{manakai_entity_base_uri}; |
154 |
|
|
} else { |
155 |
|
|
local $Error::Depth = $Error::Depth + 1; |
156 |
|
|
my $v = $self->manakai_entity_uri; |
157 |
|
|
return $v if defined $v; |
158 |
|
|
return $self->base_uri; |
159 |
|
|
} |
160 |
|
|
} |
161 |
|
|
} # manakai_entity_base_uri |
162 |
|
|
|
163 |
|
|
sub manakai_entity_uri ($;$) { |
164 |
|
|
my $self = $_[0]; |
165 |
|
|
if (@_ > 1) { |
166 |
|
|
if (${$$self->{owner_document}}->{strict_error_checking}) { |
167 |
|
|
if ($$self->{manakai_read_only}) { |
168 |
|
|
report Message::DOM::DOMException |
169 |
|
|
-object => $self, |
170 |
|
|
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
171 |
|
|
-subtype => 'READ_ONLY_NODE_ERR'; |
172 |
|
|
} |
173 |
|
|
} |
174 |
|
|
if (defined $_[1]) { |
175 |
|
|
$$self->{manakai_entity_uri} = ''.$_[1]; |
176 |
|
|
} else { |
177 |
|
|
delete $$self->{manakai_entity_uri}; |
178 |
|
|
} |
179 |
|
|
} |
180 |
wakaba |
1.1 |
|
181 |
wakaba |
1.4 |
if (defined wantarray) { |
182 |
|
|
return $$self->{manakai_entity_uri} if defined $$self->{manakai_entity_uri}; |
183 |
wakaba |
1.2 |
|
184 |
wakaba |
1.4 |
local $Error::Depth = $Error::Depth + 1; |
185 |
|
|
my $v = $$self->{system_id}; |
186 |
|
|
if (defined $v) { |
187 |
|
|
$v = ${$$self->{owner_document}}->{implementation}->create_uri_reference |
188 |
|
|
($v); |
189 |
|
|
if (not defined $v->uri_scheme) { |
190 |
|
|
my $base = $self->manakai_declaration_base_uri; |
191 |
|
|
return $v->get_absolute_reference ($base)->uri_reference |
192 |
|
|
if defined $base; |
193 |
|
|
} |
194 |
|
|
return $v->uri_reference; |
195 |
|
|
} else { |
196 |
|
|
return undef; |
197 |
|
|
} |
198 |
|
|
} |
199 |
|
|
} # manakai_entity_uri |
200 |
|
|
|
201 |
|
|
## NOTE: Setter is a manakai extension. |
202 |
wakaba |
1.6 |
## TODO: Document it. |
203 |
|
|
sub input_encoding ($;$); |
204 |
|
|
|
205 |
|
|
## NOTE: Setter is a manakai extension. |
206 |
|
|
## TODO: Document it. |
207 |
|
|
sub is_externally_declared ($;$); |
208 |
|
|
# @@enDesc: |
209 |
|
|
# Whether the entity is declared by an external markup declaration, |
210 |
|
|
# i.e. a markup declaration occuring in the external subset or |
211 |
|
|
# in a parameter entity. |
212 |
|
|
# @@Type: boolean |
213 |
|
|
# @@TrueCase: |
214 |
|
|
# @@@enDesc: |
215 |
|
|
# If the entity is declared by an external markup declaration. |
216 |
|
|
# @@FalseCase: |
217 |
|
|
# @@@enDesc: |
218 |
|
|
# If the entity is declared by a markup declaration in |
219 |
|
|
# the internal subset, or if the <IF::Entity> node |
220 |
|
|
# is created in memory. |
221 |
|
|
|
222 |
|
|
## NOTE: Setter is a manakai extension. |
223 |
wakaba |
1.5 |
sub notation_name ($;$); |
224 |
|
|
|
225 |
wakaba |
1.7 |
## NOTE: A manakai extension. |
226 |
|
|
sub owner_document_type_definition ($); |
227 |
|
|
|
228 |
wakaba |
1.5 |
## NOTE: Setter is a manakai extension. |
229 |
wakaba |
1.4 |
sub public_id ($;$); |
230 |
|
|
|
231 |
|
|
## NOTE: Setter is a manakai extension. |
232 |
|
|
sub system_id ($;$); |
233 |
wakaba |
1.2 |
|
234 |
wakaba |
1.5 |
## NOTE: Setter is a manakai extension. |
235 |
|
|
sub xml_encoding ($;$); |
236 |
|
|
|
237 |
wakaba |
1.6 |
## NOTE: Setter is a manakai extension. |
238 |
|
|
## TODO: Document it. ## TODO: e.g. xml_version = '3.7' |
239 |
|
|
## TODO: Spec does not mention |null| case |
240 |
|
|
## TODO: Should we provide default? |
241 |
|
|
sub xml_version ($;$); |
242 |
|
|
|
243 |
wakaba |
1.4 |
## |Entity| methods |
244 |
wakaba |
1.2 |
|
245 |
wakaba |
1.4 |
## NOTE: A manakai extension |
246 |
|
|
sub has_replacement_tree ($;$); |
247 |
wakaba |
1.1 |
|
248 |
|
|
package Message::IF::Entity; |
249 |
|
|
|
250 |
|
|
package Message::DOM::Document; |
251 |
|
|
|
252 |
wakaba |
1.2 |
sub create_general_entity ($$) { |
253 |
wakaba |
1.1 |
return Message::DOM::Entity->____new (@_[0, 1]); |
254 |
|
|
} # create_general_entity |
255 |
|
|
|
256 |
wakaba |
1.4 |
=head1 LICENSE |
257 |
|
|
|
258 |
|
|
Copyright 2007 Wakaba <w@suika.fam.cx> |
259 |
|
|
|
260 |
|
|
This program is free software; you can redistribute it and/or |
261 |
|
|
modify it under the same terms as Perl itself. |
262 |
|
|
|
263 |
|
|
=cut |
264 |
|
|
|
265 |
wakaba |
1.1 |
1; |
266 |
wakaba |
1.7 |
## $Date: 2007/07/08 13:04:37 $ |