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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations) (download)
Sat Jun 23 12:47:12 2007 UTC (17 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.5: +5 -5 lines
++ manakai/t/ChangeLog	23 Jun 2007 12:47:01 -0000
2007-06-23  Wakaba  <wakaba@suika.fam.cx>

	* DOM-Document.t: Tests for |manakai_is_html|, |manakai_compat_mode|,
	and |compat_mode| are added.

++ manakai/lib/Message/DOM/ChangeLog	23 Jun 2007 12:46:16 -0000
2007-06-23  Wakaba  <wakaba@suika.fam.cx>

	* DOMDocument.pm (compat_mode, manakai_compat_mode): Implemented.
	(manakai_is_html): Revised.
	(Document): Now it implements the |HTMLDocument| interface.
	(adopt_node): Alpha version.

	* AttributeDefinition.pm (allowed_tokens): |allowed_tokens|,
	not |allowed_token|!

	* ElementTypeDefinition.pm (attribute_definitions): Don't
	return an |undef| even if its |attribute_definitions|
	list is not created.

1 package Message::DOM::AttributeDefinition;
2 use strict;
3 our $VERSION=do{my @r=(q$Revision: 1.5 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4 push our @ISA, 'Message::DOM::Node', 'Message::IF::AttributeDefinition';
5 require Message::DOM::Node;
6
7 sub ____new ($$$) {
8 my $self = shift->SUPER::____new (shift);
9 $$self->{node_name} = $_[0];
10 $$self->{child_nodes} = [];
11 $$self->{allowed_tokens} = [];
12 return $self;
13 } # ____new
14
15 sub AUTOLOAD {
16 my $method_name = our $AUTOLOAD;
17 $method_name =~ s/.*:://;
18 return if $method_name eq 'DESTROY';
19
20 if ({
21 ## Read-only attributes (trivial accessors)
22 node_name => 1,
23 }->{$method_name}) {
24 no strict 'refs';
25 eval qq{
26 sub $method_name (\$) {
27 if (\@_ > 1) {
28 require Carp;
29 Carp::croak (qq<Can't modify read-only attribute>);
30 }
31 return \${\$_[0]}->{$method_name};
32 }
33 };
34 goto &{ $AUTOLOAD };
35 } elsif ({
36 ## Read-write attributes (DOMString, trivial accessors)
37 }->{$method_name}) {
38 no strict 'refs';
39 eval qq{
40 sub $method_name (\$) {
41 if (\@_ > 1) {
42 \${\$_[0]}->{$method_name} = ''.$_[1];
43 }
44 return \${\$_[0]}->{$method_name};
45 }
46 };
47 goto &{ $AUTOLOAD };
48 } else {
49 require Carp;
50 Carp::croak (qq<Can't locate method "$AUTOLOAD">);
51 }
52 } # AUTOLOAD
53
54 ## |AttributeDefinition| constants
55
56 ## |DeclaredValueType|
57 sub NO_TYPE_ATTR () { 0 }
58 sub CDATA_ATTR () { 1 }
59 sub ID_ATTR () { 2 }
60 sub IDREF_ATTR () { 3 }
61 sub IDREFS_ATTR () { 4 }
62 sub ENTITY_ATTR () { 5 }
63 sub ENTITIES_ATTR () { 6 }
64 sub NMTOKEN_ATTR () { 7 }
65 sub NMTOKENS_ATTR () { 8 }
66 sub NOTATION_ATTR () { 9 }
67 sub ENUMERATION_ATTR () { 10 }
68 sub UNKNOWN_ATTR () { 11 }
69
70 ## |DefaultValueType|
71 sub UNKNOWN_DEFAULT () { 0 }
72 sub FIXED_DEFAULT () { 1 }
73 sub REQUIRED_DEFAULT () { 2 }
74 sub IMPLIED_DEFAULT () { 3 }
75 sub EXPLICIT_DEFAULT () { 4 }
76
77 ## The |Node| interface - attribute
78
79 ## Spec:
80 ## <http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-F68D095>
81 ## <http://suika.fam.cx/gate/2005/sw/AttributeDefinition>
82
83 sub node_name ($); # read-only trivial accessor
84
85 ## Spec:
86 ## <http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-111237558>
87
88 sub node_type ($) { 81002 } # ATTRIBUTE_DEFINITION_NODE
89
90 ## Spec:
91 ## <http://suika.fam.cx/gate/2005/sw/AttributeDefinition#anchor-2>
92
93 ## TODO: node_value
94
95 ## |AttributeDefinition| attributes
96
97 sub allowed_tokens ($) {
98 ## TODO:
99 return ${$_[0]}->{allowed_tokens};
100 }
101
102 sub declared_type ($;$) {
103 my $self = $_[0];
104 if (@_ > 1) {
105 if (${$$self->{owner_document}}->{strict_error_checking}) {
106 if ($$self->{manakai_read_only}) {
107 report Message::DOM::DOMException
108 -object => $self,
109 -type => 'NO_MODIFICATION_ALLOWED_ERR',
110 -subtype => 'READ_ONLY_NODE_ERR';
111 }
112 }
113 if ($_[1]) {
114 $$self->{declared_type} = 0+$_[1];
115 } else {
116 delete $$self->{declared_type};
117 }
118 }
119
120 return $$self->{declared_type} || 0;
121 } # declared_type
122
123 sub default_type ($;$) {
124 my $self = $_[0];
125 if (@_ > 1) {
126 if (${$$self->{owner_document}}->{strict_error_checking}) {
127 if ($$self->{manakai_read_only}) {
128 report Message::DOM::DOMException
129 -object => $self,
130 -type => 'NO_MODIFICATION_ALLOWED_ERR',
131 -subtype => 'READ_ONLY_NODE_ERR';
132 }
133 }
134 if ($_[1]) {
135 $$self->{default_type} = 0+$_[1];
136 } else {
137 delete $$self->{default_type};
138 }
139 }
140
141 return $$self->{default_type} || 0;
142 } # default_type
143
144 package Message::IF::AttributeDefinition;
145
146 package Message::DOM::Document;
147
148 ## Spec:
149 ## <http://suika.fam.cx/gate/2005/sw/DocumentXDoctype>
150
151 sub create_attribute_definition ($$) {
152 return Message::DOM::AttributeDefinition->____new (@_[0, 1]);
153 } # create_attribute_definition
154
155 1;
156 ## License: <http://suika.fam.cx/~wakaba/archive/2004/8/18/license#Perl+MPL>
157 ## $Date: 2007/06/17 14:15:38 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24