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