1 |
package Message::DOM::EntityReference; |
2 |
use strict; |
3 |
our $VERSION=do{my @r=(q$Revision: 1.3 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
4 |
push our @ISA, 'Message::DOM::Node', 'Message::IF::EntityReference'; |
5 |
require Message::DOM::Node; |
6 |
|
7 |
## Spec: |
8 |
## <http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-11C98490> |
9 |
|
10 |
sub ____new ($$$) { |
11 |
my $self = shift->SUPER::____new (shift); |
12 |
$$self->{node_name} = $_[0]; |
13 |
$$self->{child_nodes} = []; |
14 |
return $self; |
15 |
} # ____new |
16 |
|
17 |
sub AUTOLOAD { |
18 |
my $method_name = our $AUTOLOAD; |
19 |
$method_name =~ s/.*:://; |
20 |
return if $method_name eq 'DESTROY'; |
21 |
|
22 |
if ({ |
23 |
## Read-only attributes (trivial accessors) |
24 |
node_name => 1, |
25 |
}->{$method_name}) { |
26 |
no strict 'refs'; |
27 |
eval qq{ |
28 |
sub $method_name (\$) { |
29 |
if (\@_ > 1) { |
30 |
require Carp; |
31 |
Carp::croak (qq<Can't modify read-only attribute>); |
32 |
} |
33 |
return \${\$_[0]}->{$method_name}; |
34 |
} |
35 |
}; |
36 |
goto &{ $AUTOLOAD }; |
37 |
} elsif ({ |
38 |
## Read-write attributes (boolean, trivial accessors) |
39 |
manakai_expanded => 1, |
40 |
manakai_external => 1, |
41 |
}->{$method_name}) { |
42 |
no strict 'refs'; |
43 |
eval qq{ |
44 |
sub $method_name (\$;\$) { |
45 |
if (\@_ > 1) { |
46 |
if (\${\${\$_[0]}->{owner_document}}->{manakai_strict_error_checking} and |
47 |
\${\$_[0]}->{manakai_read_only}) { |
48 |
report Message::DOM::DOMException |
49 |
-object => \$_[0], |
50 |
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
51 |
-subtype => 'READ_ONLY_NODE_ERR'; |
52 |
} |
53 |
if (\$_[1]) { |
54 |
\${\$_[0]}->{$method_name} = 1; |
55 |
} else { |
56 |
delete \${\$_[0]}->{$method_name}; |
57 |
} |
58 |
} |
59 |
return \${\$_[0]}->{$method_name}; |
60 |
} |
61 |
}; |
62 |
goto &{ $AUTOLOAD }; |
63 |
} else { |
64 |
require Carp; |
65 |
Carp::croak (qq<Can't locate method "$AUTOLOAD">); |
66 |
} |
67 |
} # AUTOLOAD |
68 |
|
69 |
## |Node| attributes |
70 |
|
71 |
sub base_uri ($) { |
72 |
## NOTE: Same as |CharacterData|'s. |
73 |
|
74 |
my $self = $_[0]; |
75 |
local $Error::Depth = $Error::Depth + 1; |
76 |
my $pe = $$self->{parent_node}; |
77 |
while (defined $pe) { |
78 |
my $nt = $pe->node_type; |
79 |
if ($nt == 1 or $nt == 2 or $nt == 6 or $nt == 9 or $nt == 11) { |
80 |
## Element, Attr, Entity, Document, or DocumentFragment |
81 |
return $pe->base_uri; |
82 |
} elsif ($nt == 5) { |
83 |
## EntityReference |
84 |
return $pe->manakai_entity_base_uri if $pe->manakai_external; |
85 |
} |
86 |
$pe = $$pe->{parent_node}; |
87 |
} |
88 |
return $pe->base_uri if $pe; |
89 |
return $$self->{owner_document}->base_uri; |
90 |
} # base_uri |
91 |
|
92 |
sub node_name ($); # read-only trivial accessor |
93 |
|
94 |
sub node_type () { 5 } # ENTITY_REFERENCE_NODE |
95 |
|
96 |
## |EntityReference| attributes |
97 |
|
98 |
sub manakai_entity_base_uri ($;$) { |
99 |
my $self = $_[0]; |
100 |
if (@_ > 1) { |
101 |
if (${$$self->{owner_document}}->{strict_error_checking}) { |
102 |
if ($$self->{manakai_read_only}) { |
103 |
report Message::DOM::DOMException |
104 |
-object => $self, |
105 |
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
106 |
-subtype => 'READ_ONLY_NODE_ERR'; |
107 |
} |
108 |
} |
109 |
if (defined $_[1]) { |
110 |
$$self->{manakai_entity_base_uri} = ''.$_[1]; |
111 |
} else { |
112 |
delete $$self->{manakai_entity_base_uri}; |
113 |
} |
114 |
} |
115 |
|
116 |
if (defined $$self->{manakai_entity_base_uri}) { |
117 |
return $$self->{manakai_entity_base_uri}; |
118 |
} else { |
119 |
local $Error::Depth = $Error::Depth + 1; |
120 |
return $self->base_uri; |
121 |
} |
122 |
} # manakai_entity_base_uri |
123 |
|
124 |
sub manakai_expanded ($;$); |
125 |
|
126 |
sub manakai_external ($;$); |
127 |
|
128 |
package Message::IF::EntityReference; |
129 |
|
130 |
package Message::DOM::Document; |
131 |
|
132 |
sub create_entity_reference ($$) { |
133 |
return Message::DOM::EntityReference->____new (@_[0, 1]); |
134 |
} # create_entity_reference |
135 |
|
136 |
=head1 LICENSE |
137 |
|
138 |
Copyright 2007 Wakaba <w@suika.fam.cx> |
139 |
|
140 |
This program is free software; you can redistribute it and/or |
141 |
modify it under the same terms as Perl itself. |
142 |
|
143 |
=cut |
144 |
|
145 |
1; |
146 |
## $Date: 2007/06/16 15:27:45 $ |