/[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.11 - (hide annotations) (download)
Sun Jul 29 03:49:00 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
CVS Tags: manakai-release-0-4-0, HEAD
Changes since 1.10: +21 -4 lines
++ manakai/t/ChangeLog	19 Jul 2007 15:16:15 -0000
2007-07-19  Wakaba  <wakaba@suika.fam.cx>

	* DOM-Attr.t: New tests for |DeclaredValueType|, |specified|,
	|schemaTypeInfo|, and |isId| are added.

	* DOM-Element.t: New tests for |schemaTypeInfo| are added.

	* DOM-Entity.t: New tests for |xmlVersion| are added.

	* DOM-ProcessingInstruction.t: New tests for |node_value|,
	|data|, and |text_content| are added.

++ manakai/lib/Message/DOM/ChangeLog	19 Jul 2007 15:14:20 -0000
2007-07-19  Wakaba  <wakaba@suika.fam.cx>

	* Attr.pm (DeclaredValueType): Added.

	* ProcessingInstruction.pm (data): Accept |undef|
	as a valid input, for |text_content| (maybe) allows it.

	* TypeInfo.pm (type_namespace): The implementation was wrong.

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24