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