| 1 |
wakaba |
1.1 |
package Message::DOM::ProcessingInstruction; |
| 2 |
|
|
use strict; |
| 3 |
wakaba |
1.8 |
our $VERSION=do{my @r=(q$Revision: 1.7 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
| 4 |
wakaba |
1.1 |
push our @ISA, 'Message::DOM::Node', 'Message::IF::ProcessingInstruction'; |
| 5 |
|
|
require Message::DOM::Node; |
| 6 |
|
|
|
| 7 |
|
|
sub ____new ($$$$) { |
| 8 |
|
|
my $self = shift->SUPER::____new (shift); |
| 9 |
|
|
($$self->{target}, $$self->{data}) = @_; |
| 10 |
|
|
return $self; |
| 11 |
|
|
} # ____new |
| 12 |
|
|
|
| 13 |
|
|
sub AUTOLOAD { |
| 14 |
|
|
my $method_name = our $AUTOLOAD; |
| 15 |
|
|
$method_name =~ s/.*:://; |
| 16 |
|
|
return if $method_name eq 'DESTROY'; |
| 17 |
|
|
|
| 18 |
|
|
if ({ |
| 19 |
|
|
## Read-only attributes (trivial accessors) |
| 20 |
|
|
target => 1, |
| 21 |
|
|
}->{$method_name}) { |
| 22 |
|
|
no strict 'refs'; |
| 23 |
|
|
eval qq{ |
| 24 |
|
|
sub $method_name (\$) { |
| 25 |
|
|
if (\@_ > 1) { |
| 26 |
|
|
require Carp; |
| 27 |
|
|
Carp::croak (qq<Can't modify read-only attribute>); |
| 28 |
|
|
} |
| 29 |
|
|
return \${\$_[0]}->{$method_name}; |
| 30 |
|
|
} |
| 31 |
|
|
}; |
| 32 |
|
|
goto &{ $AUTOLOAD }; |
| 33 |
|
|
} elsif ({ |
| 34 |
|
|
## Read-write attributes (DOMString, trivial accessors) |
| 35 |
wakaba |
1.5 |
manakai_base_uri => 1, |
| 36 |
wakaba |
1.6 |
data => 1, |
| 37 |
wakaba |
1.1 |
}->{$method_name}) { |
| 38 |
|
|
no strict 'refs'; |
| 39 |
|
|
eval qq{ |
| 40 |
wakaba |
1.5 |
sub $method_name (\$;\$) { |
| 41 |
wakaba |
1.1 |
if (\@_ > 1) { |
| 42 |
wakaba |
1.5 |
if (\${\${\$_[0]}->{owner_document}}->{strict_error_checking} and |
| 43 |
|
|
\${\$_[0]}->{manakai_read_only}) { |
| 44 |
|
|
report Message::DOM::DOMException |
| 45 |
|
|
-object => \$_[0], |
| 46 |
|
|
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
| 47 |
|
|
-subtype => 'READ_ONLY_NODE_ERR'; |
| 48 |
|
|
} |
| 49 |
|
|
if (defined \$_[1]) { |
| 50 |
|
|
\${\$_[0]}->{$method_name} = ''.\$_[1]; |
| 51 |
|
|
} else { |
| 52 |
|
|
delete \${\$_[0]}->{$method_name}; |
| 53 |
|
|
} |
| 54 |
wakaba |
1.1 |
} |
| 55 |
wakaba |
1.5 |
return \${\$_[0]}->{$method_name}; |
| 56 |
wakaba |
1.1 |
} |
| 57 |
|
|
}; |
| 58 |
|
|
goto &{ $AUTOLOAD }; |
| 59 |
|
|
} else { |
| 60 |
|
|
require Carp; |
| 61 |
|
|
Carp::croak (qq<Can't locate method "$AUTOLOAD">); |
| 62 |
|
|
} |
| 63 |
|
|
} # AUTOLOAD |
| 64 |
|
|
sub target ($); |
| 65 |
|
|
sub data ($); |
| 66 |
|
|
|
| 67 |
wakaba |
1.5 |
## |Node| attributes |
| 68 |
|
|
|
| 69 |
|
|
sub base_uri ($) { |
| 70 |
|
|
my $self = $_[0]; |
| 71 |
|
|
return $$self->{manakai_base_uri} if defined $$self->{manakai_base_uri}; |
| 72 |
|
|
|
| 73 |
|
|
local $Error::Depth = $Error::Depth + 1; |
| 74 |
|
|
my $node = $$self->{parent_node}; |
| 75 |
|
|
while (defined $node) { |
| 76 |
|
|
my $nt = $node->node_type; |
| 77 |
|
|
if ($nt == 1 or $nt == 6 or $nt == 9 or $nt == 10 or $nt == 11) { |
| 78 |
|
|
## Element, Entity, Document, DocumentType, or DocumentFragment |
| 79 |
|
|
return $node->base_uri; |
| 80 |
|
|
} elsif ($nt == 5) { |
| 81 |
|
|
## EntityReference |
| 82 |
|
|
return $node->manakai_entity_base_uri if $node->manakai_external; |
| 83 |
|
|
} |
| 84 |
|
|
$node = $$node->{parent_node}; |
| 85 |
|
|
} |
| 86 |
|
|
return $node->base_uri if $node; |
| 87 |
|
|
return $self->owner_document->base_uri; |
| 88 |
|
|
} # base_uri |
| 89 |
wakaba |
1.1 |
|
| 90 |
wakaba |
1.3 |
sub child_nodes ($) { |
| 91 |
|
|
require Message::DOM::NodeList; |
| 92 |
|
|
return bless \\($_[0]), 'Message::DOM::NodeList::EmptyNodeList'; |
| 93 |
|
|
} # child_nodes |
| 94 |
wakaba |
1.2 |
|
| 95 |
|
|
## The target of the processing instruction [DOM1, DOM2]. |
| 96 |
|
|
## Same as |ProcessingInstruction.target| [DOM3]. |
| 97 |
|
|
|
| 98 |
|
|
*node_name = \⌖ |
| 99 |
|
|
|
| 100 |
wakaba |
1.5 |
sub node_type () { 7 } # PROCESSING_INSTRUCTION_NODE |
| 101 |
wakaba |
1.2 |
|
| 102 |
|
|
## The entire content exclude the target [DOM1, DOM2]. |
| 103 |
|
|
## Same as |ProcessingInstruction.data| [DOM3]. |
| 104 |
|
|
|
| 105 |
|
|
*node_value = \&data; |
| 106 |
wakaba |
1.1 |
|
| 107 |
wakaba |
1.4 |
*text_content = \&node_value; |
| 108 |
|
|
|
| 109 |
wakaba |
1.5 |
## |Node| methods |
| 110 |
|
|
|
| 111 |
wakaba |
1.8 |
sub append_child ($$) { |
| 112 |
|
|
report Message::DOM::DOMException |
| 113 |
|
|
-object => $_[0], |
| 114 |
|
|
-type => 'HIERARCHY_REQUEST_ERR', |
| 115 |
|
|
-subtype => 'CHILD_NODE_TYPE_ERR'; |
| 116 |
|
|
} # append_child |
| 117 |
|
|
|
| 118 |
wakaba |
1.5 |
sub manakai_append_text ($$) { |
| 119 |
|
|
## NOTE: Same as |CharacterData|'s. |
| 120 |
|
|
if (${${$_[0]}->{owner_document}}->{strict_error_checking} and |
| 121 |
|
|
${$_[0]}->{manakai_read_only}) { |
| 122 |
|
|
report Message::DOM::DOMException |
| 123 |
|
|
-object => $_[0], |
| 124 |
|
|
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
| 125 |
|
|
-subtype => 'READ_ONLY_NODE_ERR'; |
| 126 |
|
|
} |
| 127 |
|
|
${$_[0]}->{data} .= ref $_[1] eq 'SCALAR' ? ${$_[1]} : $_[1]; |
| 128 |
|
|
} # manakai_append_text |
| 129 |
|
|
|
| 130 |
wakaba |
1.8 |
sub insert_before ($;$) { |
| 131 |
|
|
report Message::DOM::DOMException |
| 132 |
|
|
-object => $_[0], |
| 133 |
|
|
-type => 'HIERARCHY_REQUEST_ERR', |
| 134 |
|
|
-subtype => 'CHILD_NODE_TYPE_ERR'; |
| 135 |
|
|
} # insert_before |
| 136 |
|
|
|
| 137 |
|
|
sub replace_child ($$) { |
| 138 |
|
|
report Message::DOM::DOMException |
| 139 |
|
|
-object => $_[0], |
| 140 |
|
|
-type => 'HIERARCHY_REQUEST_ERR', |
| 141 |
|
|
-subtype => 'CHILD_NODE_TYPE_ERR'; |
| 142 |
|
|
} # replace_child |
| 143 |
|
|
|
| 144 |
wakaba |
1.5 |
## |ProcessingInstruction| attributes |
| 145 |
|
|
|
| 146 |
|
|
sub manakai_base_uri ($;$); |
| 147 |
|
|
|
| 148 |
wakaba |
1.1 |
package Message::IF::ProcessingInstruction; |
| 149 |
|
|
|
| 150 |
|
|
package Message::DOM::Document; |
| 151 |
|
|
|
| 152 |
|
|
sub create_processing_instruction ($$$) { |
| 153 |
wakaba |
1.7 |
if (${$_[0]}->{strict_error_checking}) { |
| 154 |
|
|
my $xv = $_[0]->xml_version; |
| 155 |
|
|
if (defined $xv) { |
| 156 |
|
|
if ($xv eq '1.0' and |
| 157 |
|
|
$_[1] =~ /\A\p{InXML_NameStartChar10}\p{InXMLNameChar10}*\z/) { |
| 158 |
|
|
# |
| 159 |
|
|
} elsif ($xv eq '1.1' and |
| 160 |
|
|
$_[1] =~ /\A\p{InXMLNameStartChar11}\p{InXMLNameChar11}*\z/) { |
| 161 |
|
|
# |
| 162 |
|
|
} else { |
| 163 |
|
|
report Message::DOM::DOMException |
| 164 |
|
|
-object => $_[0], |
| 165 |
|
|
-type => 'INVALID_CHARACTER_ERR', |
| 166 |
|
|
-subtype => 'MALFORMED_NAME_ERR'; |
| 167 |
|
|
} |
| 168 |
|
|
} |
| 169 |
|
|
} |
| 170 |
|
|
|
| 171 |
wakaba |
1.1 |
return Message::DOM::ProcessingInstruction->____new (@_[0, 1, 2]); |
| 172 |
|
|
} # create_processing_instruction |
| 173 |
|
|
|
| 174 |
wakaba |
1.5 |
=head1 LICENSE |
| 175 |
|
|
|
| 176 |
|
|
Copyright 2007 Wakaba <[email protected]> |
| 177 |
|
|
|
| 178 |
|
|
This program is free software; you can redistribute it and/or |
| 179 |
|
|
modify it under the same terms as Perl itself. |
| 180 |
|
|
|
| 181 |
|
|
=cut |
| 182 |
|
|
|
| 183 |
wakaba |
1.1 |
1; |
| 184 |
wakaba |
1.8 |
## $Date: 2007/07/07 11:11:34 $ |