1 |
wakaba |
1.1 |
package Message::DOM::AttributeDefinition; |
2 |
|
|
use strict; |
3 |
wakaba |
1.5 |
our $VERSION=do{my @r=(q$Revision: 1.4 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
4 |
wakaba |
1.1 |
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 |
wakaba |
1.3 |
$$self->{child_nodes} = []; |
11 |
wakaba |
1.5 |
$$self->{allowed_token} = []; |
12 |
wakaba |
1.1 |
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 |
wakaba |
1.2 |
node_name => 1, |
23 |
wakaba |
1.1 |
}->{$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 |
wakaba |
1.4 |
## |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 |
wakaba |
1.1 |
## The |Node| interface - attribute |
78 |
|
|
|
79 |
wakaba |
1.2 |
## 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 |
wakaba |
1.1 |
|
95 |
wakaba |
1.4 |
## |AttributeDefinition| attributes |
96 |
|
|
|
97 |
wakaba |
1.5 |
sub allowed_token ($) { |
98 |
|
|
## TODO: |
99 |
|
|
return ${$_[0]}->{allowed_token}; |
100 |
|
|
} |
101 |
|
|
|
102 |
wakaba |
1.4 |
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 |
wakaba |
1.1 |
package Message::IF::AttributeDefinition; |
145 |
|
|
|
146 |
|
|
package Message::DOM::Document; |
147 |
|
|
|
148 |
|
|
## Spec: |
149 |
|
|
## <http://suika.fam.cx/gate/2005/sw/DocumentXDoctype> |
150 |
|
|
|
151 |
wakaba |
1.2 |
sub create_attribute_definition ($$) { |
152 |
wakaba |
1.1 |
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 |
wakaba |
1.5 |
## $Date: 2007/06/17 13:37:40 $ |