/[suikacvs]/messaging/manakai/lib/Message/DOM/ProcessingInstruction.pm
Suika

Contents of /messaging/manakai/lib/Message/DOM/ProcessingInstruction.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Sun Jul 8 13:04:37 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.8: +6 -10 lines
++ manakai/t/ChangeLog	8 Jul 2007 13:03:58 -0000
	* DOM-Element.t: Tests for |attributes| are added.

	* DOM-Entity.t: Tests for |is_externally_declared|
	and |input_encoding| are added.

	* DOM-Node.t: Test data for |tag_name| and
	|get_feature| are added.

2007-07-08  Wakaba  <wakaba@suika.fam.cx>

++ manakai/lib/Message/DOM/ChangeLog	8 Jul 2007 13:02:01 -0000
	* Attr.pm (value, node_value): Now it is defined
	as |text_content| itself.

	* AttributeDefinition.pm, ElementTypeDefinition.pm,
	Node.pm (AUTOLOAD): Unused block is removed.

	* CDATASection.pm, DocumentFragment.pm (AUTOLOAD): Removed.  Unused.

	* DocumentType.pm (internal_subset): Implemented.

	* Entity.pm (is_externally_declared, input_encoding,
	xml_version): Implemented.

	* ProcessingInstruction.pm (target, data): Implemented.

2007-07-08  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 package Message::DOM::ProcessingInstruction;
2     use strict;
3 wakaba 1.9 our $VERSION=do{my @r=(q$Revision: 1.8 $=~/\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    
65 wakaba 1.5 ## |Node| attributes
66    
67     sub base_uri ($) {
68     my $self = $_[0];
69     return $$self->{manakai_base_uri} if defined $$self->{manakai_base_uri};
70    
71     local $Error::Depth = $Error::Depth + 1;
72     my $node = $$self->{parent_node};
73     while (defined $node) {
74     my $nt = $node->node_type;
75     if ($nt == 1 or $nt == 6 or $nt == 9 or $nt == 10 or $nt == 11) {
76     ## Element, Entity, Document, DocumentType, or DocumentFragment
77     return $node->base_uri;
78     } elsif ($nt == 5) {
79     ## EntityReference
80     return $node->manakai_entity_base_uri if $node->manakai_external;
81     }
82     $node = $$node->{parent_node};
83     }
84     return $node->base_uri if $node;
85     return $self->owner_document->base_uri;
86     } # base_uri
87 wakaba 1.1
88 wakaba 1.3 sub child_nodes ($) {
89     require Message::DOM::NodeList;
90     return bless \\($_[0]), 'Message::DOM::NodeList::EmptyNodeList';
91     } # child_nodes
92 wakaba 1.2
93     *node_name = \&target;
94    
95 wakaba 1.5 sub node_type () { 7 } # PROCESSING_INSTRUCTION_NODE
96 wakaba 1.2
97     *node_value = \&data;
98 wakaba 1.1
99 wakaba 1.4 *text_content = \&node_value;
100    
101 wakaba 1.5 ## |Node| methods
102    
103 wakaba 1.8 sub append_child ($$) {
104     report Message::DOM::DOMException
105     -object => $_[0],
106     -type => 'HIERARCHY_REQUEST_ERR',
107     -subtype => 'CHILD_NODE_TYPE_ERR';
108     } # append_child
109    
110 wakaba 1.5 sub manakai_append_text ($$) {
111     ## NOTE: Same as |CharacterData|'s.
112     if (${${$_[0]}->{owner_document}}->{strict_error_checking} and
113     ${$_[0]}->{manakai_read_only}) {
114     report Message::DOM::DOMException
115     -object => $_[0],
116     -type => 'NO_MODIFICATION_ALLOWED_ERR',
117     -subtype => 'READ_ONLY_NODE_ERR';
118     }
119     ${$_[0]}->{data} .= ref $_[1] eq 'SCALAR' ? ${$_[1]} : $_[1];
120     } # manakai_append_text
121    
122 wakaba 1.8 sub insert_before ($;$) {
123     report Message::DOM::DOMException
124     -object => $_[0],
125     -type => 'HIERARCHY_REQUEST_ERR',
126     -subtype => 'CHILD_NODE_TYPE_ERR';
127     } # insert_before
128    
129     sub replace_child ($$) {
130     report Message::DOM::DOMException
131     -object => $_[0],
132     -type => 'HIERARCHY_REQUEST_ERR',
133     -subtype => 'CHILD_NODE_TYPE_ERR';
134     } # replace_child
135    
136 wakaba 1.5 ## |ProcessingInstruction| attributes
137    
138     sub manakai_base_uri ($;$);
139    
140 wakaba 1.9 sub data ($;$);
141    
142     sub target ($);
143    
144 wakaba 1.1 package Message::IF::ProcessingInstruction;
145    
146     package Message::DOM::Document;
147    
148     sub create_processing_instruction ($$$) {
149 wakaba 1.7 if (${$_[0]}->{strict_error_checking}) {
150     my $xv = $_[0]->xml_version;
151     if (defined $xv) {
152     if ($xv eq '1.0' and
153     $_[1] =~ /\A\p{InXML_NameStartChar10}\p{InXMLNameChar10}*\z/) {
154     #
155     } elsif ($xv eq '1.1' and
156     $_[1] =~ /\A\p{InXMLNameStartChar11}\p{InXMLNameChar11}*\z/) {
157     #
158     } else {
159     report Message::DOM::DOMException
160     -object => $_[0],
161     -type => 'INVALID_CHARACTER_ERR',
162     -subtype => 'MALFORMED_NAME_ERR';
163     }
164     }
165     }
166    
167 wakaba 1.1 return Message::DOM::ProcessingInstruction->____new (@_[0, 1, 2]);
168     } # create_processing_instruction
169    
170 wakaba 1.5 =head1 LICENSE
171    
172     Copyright 2007 Wakaba <w@suika.fam.cx>
173    
174     This program is free software; you can redistribute it and/or
175     modify it under the same terms as Perl itself.
176    
177     =cut
178    
179 wakaba 1.1 1;
180 wakaba 1.9 ## $Date: 2007/07/08 05:42:37 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24