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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Sun Jun 17 13:37:40 2007 UTC (17 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.5: +73 -32 lines
++ manakai/t/ChangeLog	17 Jun 2007 13:37:22 -0000
2007-06-17  Wakaba  <wakaba@suika.fam.cx>

	* DOM-Attr.t, DOM-AttributeDefinition.t, DOM-DocumentType.t,
	DOM-Element.t, DOM-Entity.t, DOM-EntityReference.t,
	DOM-Notation.t, DOM-ProcessingInstruction.t: New.

	* DOM-Document.t, DOM-Node.t: Tests for newly-implemented attributes
	and methods are added.

	* Makefile (test-module-dom-old): Renamed from |test-module-dom|.
	(test-module-dom): New.

++ manakai/lib/Message/DOM/ChangeLog	17 Jun 2007 13:34:54 -0000
2007-06-17  Wakaba  <wakaba@suika.fam.cx>

	* Attr.pm (____new): Initialize |specified| as 1.
	(base_uri, manakai_attribute_type, specified): Implemented.
	(prefix): Don't check read-only flag unless |strict_error_checking|.
	(value): Call |text_content| for now.

	* AttributeDefinition.pm (DeclaredValueType, DefaultValueType): Added.
	(declared_type, default_type): Implemented.

	* CharacterData.pm (____new): Allow a scalar reference
	as an input for the |data| attribute.
	(base_uri, manakai_append_text): Implemented.

	* DOMConfiguration.pm (set_parameter): Resetting implemented.

	* DOMDocument.pm (____new): Set default values to
	configuration parameter whose default is true.
	(document_uri, input_encoding): Implemented.
	(all_declarations_processed, manakai_is_html): Implemented.
	(base_uri, manakai_append_text,
	manakai_entity_base_uri, strict_error_checking,
	xml_encoding, xml_version, xml_standalone): Implemented.

	* DOMElement.pm (manakai_base_uri, base_uri): Implemented.
	(get_attribute, get_attribute_node): Alpha version.
	(set_attribute_node, set_attribute_node_ns): Implemented.
	(set_attribute_ns): Accept non-ARRAY qualified name.

	* DOMException.pm (___error_def): |WRONG_DOCUMENT_ERR|,
	|NOT_SUPPORTED_ERR|, and |INUSE_ATTRIBUTE_ERR| are added.

	* DocumentType.pm (public_id, system_id): Implemented.
	(base_uri, declaration_base_uri, manakai_declaration_base_uri,
	manakai_append_text): Implemented.
	(element_types, general_entities, notations,
	set_element_type_definition_node, set_general_entity_node,
	set_notation_node): Alpha version.

	* ElementTypeDefinition.pm (manakai_append_text): Implemented.
	(attribute_definitions, set_attribute_definition_node): Alpha version.

	* Entity.pm (has_replacement_tree, public_id, system_id,
	manakai_declaration_base_uri, manakai_entity_base_uri,
	manakai_entity_uri): Implemented.

	* EntityReference.pm (manakai_expanded, manakai_external): Implemented.
	(base_uri, manakai_entity_base_uri): Implemented.

	* Node.pm (base_uri): Implemented.
	(text_content): Don't check read-only or not
	unless |strict_error_checking|.
	(manakai_append_text): Implemented.
	(get_feature): Alpha.
	(manakai_set_read_only): Implemented.

	* Notation.pm (public_id, system_id, manakai_append_text,
	manakai_declaration_base_uri): Implemented.

	* ProcessingInstruction.pm (manakai_base_uri,
	base_uri, manakai_append_text): Implemented.

1 wakaba 1.1 package Message::DOM::Attr;
2     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.1 push our @ISA, 'Message::DOM::Node', 'Message::IF::Attr';
5     require Message::DOM::Node;
6    
7     sub ____new ($$$$$$) {
8     my $self = shift->SUPER::____new (shift);
9     ($$self->{owner_element},
10     $$self->{namespace_uri},
11     $$self->{prefix},
12     $$self->{local_name}) = @_;
13     Scalar::Util::weaken ($$self->{owner_element});
14 wakaba 1.4 $$self->{child_nodes} = [];
15 wakaba 1.6 $$self->{specified} = 1;
16 wakaba 1.1 return $self;
17     } # ____new
18    
19     sub AUTOLOAD {
20     my $method_name = our $AUTOLOAD;
21     $method_name =~ s/.*:://;
22     return if $method_name eq 'DESTROY';
23    
24     if ({
25     ## Read-only attributes (trivial accessors)
26 wakaba 1.3 namespace_uri => 1,
27 wakaba 1.1 owner_element => 1,
28     }->{$method_name}) {
29     no strict 'refs';
30     eval qq{
31     sub $method_name (\$) {
32     return \${\$_[0]}->{$method_name};
33     }
34     };
35     goto &{ $AUTOLOAD };
36     } else {
37     require Carp;
38     Carp::croak (qq<Can't locate method "$AUTOLOAD">);
39     }
40     } # AUTOLOAD
41     sub owner_element ($);
42    
43 wakaba 1.6 ## |Node| attributes
44    
45     sub base_uri ($) {
46     my $self = $_[0];
47     local $Error::Depth = $Error::Depth + 1;
48     my $oe = $self->owner_element;
49     if ($oe) {
50     my $ln = $self->local_name;
51     my $nsuri = $self->namespace_uri;
52     if (($ln eq 'base' and
53     defined $nsuri and $nsuri eq 'http://www.w3.org/XML/1998/namespace') or
54     ($ln eq 'xml:base' and not defined $nsuri)) {
55     my $oep = $oe->parent_node;
56     if ($oep) {
57     return $oep->base_uri;
58     } else {
59     return $self->owner_document->base_uri;
60     }
61     } else {
62     return $oe->base_uri;
63     }
64     } else {
65     return $self->owner_document->base_uri;
66     }
67     } # base_uri
68 wakaba 1.1
69 wakaba 1.3 sub local_name ($) {
70     ## TODO: HTML5
71     return ${+shift}->{local_name};
72     } # local_name
73    
74     sub manakai_local_name ($) {
75 wakaba 1.6 return ${$_[0]}->{local_name};
76 wakaba 1.3 } # manakai_local_name
77    
78     sub namespace_uri ($);
79 wakaba 1.2
80     ## The name of the attribute [DOM1, DOM2].
81     ## Same as |Attr.name| [DOM3].
82    
83     *node_name = \&name;
84    
85     sub node_type () { 2 } # ATTRIBUTE_NODE
86    
87     ## The value of the attribute [DOM1, DOM2].
88     ## Same as |Attr.value| [DOM3].
89    
90     *node_value = \&value;
91 wakaba 1.1
92 wakaba 1.3 sub prefix ($;$) {
93 wakaba 1.5 ## NOTE: No check for new value as Firefox doesn't do.
94     ## See <http://suika.fam.cx/gate/2005/sw/prefix>.
95    
96     ## NOTE: Same as trivial setter except "" -> undef
97    
98     ## NOTE: Same as |Element|'s |prefix|.
99    
100     if (@_ > 1) {
101 wakaba 1.6 if (${${$_[0]}->{owner_document}}->{strict_error_checking} and
102     ${$_[0]}->{manakai_read_only}) {
103 wakaba 1.5 report Message::DOM::DOMException
104     -object => $_[0],
105     -type => 'NO_MODIFICATION_ALLOWED_ERR',
106     -subtype => 'READ_ONLY_NODE_ERR';
107     }
108     if (defined $_[1] and $_[1] ne '') {
109     ${$_[0]}->{prefix} = ''.$_[1];
110     } else {
111     delete ${$_[0]}->{prefix};
112     }
113     }
114     return ${$_[0]}->{prefix};
115 wakaba 1.3 } # prefix
116    
117 wakaba 1.6 ## |Attr| attributes
118    
119     sub manakai_attribute_type ($;$) {
120     my $self = $_[0];
121     if (@_ > 1) {
122     if (${$$self->{owner_document}}->{strict_error_checking}) {
123     if ($$self->{manakai_read_only}) {
124     report Message::DOM::DOMException
125     -object => $self,
126     -type => 'NO_MODIFICATION_ALLOWED_ERR',
127     -subtype => 'READ_ONLY_NODE_ERR';
128     }
129     }
130     if ($_[1]) {
131     $$self->{manakai_attribute_type} = 0+$_[1];
132     } else {
133     delete $$self->{manakai_attribute_type};
134     }
135     }
136    
137     return $$self->{manakai_attribute_type} || 0;
138     } # manakai_attribute_type
139 wakaba 1.1
140     ## TODO: HTML5 case stuff?
141     sub name ($) {
142     my $self = shift;
143     if (defined $$self->{prefix}) {
144     return $$self->{prefix} . ':' . $$self->{local_name};
145     } else {
146     return $$self->{local_name};
147     }
148     } # name
149    
150 wakaba 1.6 sub specified ($;$) {
151 wakaba 1.1 if (@_ > 1) {
152 wakaba 1.6 ## NOTE: A manakai extension.
153     if (${${$_[0]}->{owner_document}}->{strict_error_checking} and
154     ${$_[0]}->{manakai_read_only}) {
155     report Message::DOM::DOMException
156     -object => $_[0],
157     -type => 'NO_MODIFICATION_ALLOWED_ERR',
158     -subtype => 'READ_ONLY_NODE_ERR';
159     }
160     if ($_[1] or not defined ${$_[0]}->{owner_element}) {
161     ${$_[0]}->{specified} = 1;
162     } else {
163     delete ${$_[0]}->{specified};
164     }
165 wakaba 1.1 }
166 wakaba 1.6 return ${$_[0]}->{specified};
167     } # specified
168    
169     sub value ($;$) {
170     ## TODO:
171     shift->text_content (@_);
172 wakaba 1.1 } # value
173    
174     package Message::IF::Attr;
175    
176     package Message::DOM::Document;
177    
178     sub create_attribute ($$) {
179     ## TODO: HTML5
180     return Message::DOM::Attr->____new ($_[0], undef, undef, undef, $_[1]);
181     } # create_attribute
182    
183     sub create_attribute_ns ($$$) {
184     my ($prefix, $lname);
185     if (ref $_[2] eq 'ARRAY') {
186     ($prefix, $lname) = @{$_[2]};
187     } else {
188     ($prefix, $lname) = split /:/, $_[2], 2;
189     ($prefix, $lname) = (undef, $prefix) unless defined $lname;
190     }
191     return Message::DOM::Attr->____new ($_[0], undef, $_[1], $prefix, $lname);
192     } # create_element_ns
193    
194     1;
195     ## License: <http://suika.fam.cx/~wakaba/archive/2004/8/18/license#Perl+MPL>
196 wakaba 1.6 ## $Date: 2007/06/16 15:27:45 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24