1 |
wakaba |
1.1 |
package Message::DOM::AttributeDefinition; |
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::AttributeDefinition'; |
5 |
|
|
require Message::DOM::Node; |
6 |
wakaba |
1.8 |
require Message::DOM::Attr; |
7 |
wakaba |
1.1 |
|
8 |
|
|
sub ____new ($$$) { |
9 |
|
|
my $self = shift->SUPER::____new (shift); |
10 |
|
|
$$self->{node_name} = $_[0]; |
11 |
wakaba |
1.3 |
$$self->{child_nodes} = []; |
12 |
wakaba |
1.6 |
$$self->{allowed_tokens} = []; |
13 |
wakaba |
1.1 |
return $self; |
14 |
|
|
} # ____new |
15 |
|
|
|
16 |
|
|
sub AUTOLOAD { |
17 |
|
|
my $method_name = our $AUTOLOAD; |
18 |
|
|
$method_name =~ s/.*:://; |
19 |
|
|
return if $method_name eq 'DESTROY'; |
20 |
|
|
|
21 |
|
|
if ({ |
22 |
|
|
## Read-only attributes (trivial accessors) |
23 |
wakaba |
1.2 |
node_name => 1, |
24 |
wakaba |
1.10 |
owner_element_type_definition => 1, |
25 |
wakaba |
1.1 |
}->{$method_name}) { |
26 |
|
|
no strict 'refs'; |
27 |
|
|
eval qq{ |
28 |
|
|
sub $method_name (\$) { |
29 |
|
|
if (\@_ > 1) { |
30 |
|
|
require Carp; |
31 |
|
|
Carp::croak (qq<Can't modify read-only attribute>); |
32 |
|
|
} |
33 |
|
|
return \${\$_[0]}->{$method_name}; |
34 |
|
|
} |
35 |
|
|
}; |
36 |
|
|
goto &{ $AUTOLOAD }; |
37 |
|
|
} else { |
38 |
|
|
require Carp; |
39 |
|
|
Carp::croak (qq<Can't locate method "$AUTOLOAD">); |
40 |
|
|
} |
41 |
|
|
} # AUTOLOAD |
42 |
|
|
|
43 |
wakaba |
1.4 |
## |AttributeDefinition| constants |
44 |
|
|
|
45 |
|
|
## |DeclaredValueType| |
46 |
|
|
sub NO_TYPE_ATTR () { 0 } |
47 |
|
|
sub CDATA_ATTR () { 1 } |
48 |
|
|
sub ID_ATTR () { 2 } |
49 |
|
|
sub IDREF_ATTR () { 3 } |
50 |
|
|
sub IDREFS_ATTR () { 4 } |
51 |
|
|
sub ENTITY_ATTR () { 5 } |
52 |
|
|
sub ENTITIES_ATTR () { 6 } |
53 |
|
|
sub NMTOKEN_ATTR () { 7 } |
54 |
|
|
sub NMTOKENS_ATTR () { 8 } |
55 |
|
|
sub NOTATION_ATTR () { 9 } |
56 |
|
|
sub ENUMERATION_ATTR () { 10 } |
57 |
|
|
sub UNKNOWN_ATTR () { 11 } |
58 |
|
|
|
59 |
|
|
## |DefaultValueType| |
60 |
|
|
sub UNKNOWN_DEFAULT () { 0 } |
61 |
|
|
sub FIXED_DEFAULT () { 1 } |
62 |
|
|
sub REQUIRED_DEFAULT () { 2 } |
63 |
|
|
sub IMPLIED_DEFAULT () { 3 } |
64 |
|
|
sub EXPLICIT_DEFAULT () { 4 } |
65 |
|
|
|
66 |
wakaba |
1.11 |
## |Node| attributes |
67 |
wakaba |
1.2 |
|
68 |
|
|
sub node_name ($); # read-only trivial accessor |
69 |
|
|
|
70 |
wakaba |
1.11 |
sub node_type () { 81002 } # ATTRIBUTE_DEFINITION_NODE |
71 |
wakaba |
1.2 |
|
72 |
wakaba |
1.11 |
*node_value = \&Message::DOM::Node::text_content; |
73 |
wakaba |
1.1 |
|
74 |
wakaba |
1.8 |
## |Node| methods |
75 |
|
|
|
76 |
|
|
*append_child = \&Message::DOM::Attr::append_child; |
77 |
|
|
|
78 |
|
|
*insert_before = \&Message::DOM::Attr::insert_before; |
79 |
|
|
|
80 |
|
|
*replace_child = \&Message::DOM::Attr::replace_child; |
81 |
|
|
|
82 |
wakaba |
1.4 |
## |AttributeDefinition| attributes |
83 |
|
|
|
84 |
wakaba |
1.6 |
sub allowed_tokens ($) { |
85 |
wakaba |
1.7 |
require Message::DOM::DOMStringList; |
86 |
|
|
return bless \[$_[0], 'allowed_tokens'], 'Message::DOM::DOMStringList'; |
87 |
|
|
} # allowed_tokens |
88 |
wakaba |
1.5 |
|
89 |
wakaba |
1.4 |
sub declared_type ($;$) { |
90 |
|
|
my $self = $_[0]; |
91 |
|
|
if (@_ > 1) { |
92 |
|
|
if (${$$self->{owner_document}}->{strict_error_checking}) { |
93 |
|
|
if ($$self->{manakai_read_only}) { |
94 |
|
|
report Message::DOM::DOMException |
95 |
|
|
-object => $self, |
96 |
|
|
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
97 |
|
|
-subtype => 'READ_ONLY_NODE_ERR'; |
98 |
|
|
} |
99 |
|
|
} |
100 |
|
|
if ($_[1]) { |
101 |
|
|
$$self->{declared_type} = 0+$_[1]; |
102 |
|
|
} else { |
103 |
|
|
delete $$self->{declared_type}; |
104 |
|
|
} |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
return $$self->{declared_type} || 0; |
108 |
|
|
} # declared_type |
109 |
|
|
|
110 |
|
|
sub default_type ($;$) { |
111 |
|
|
my $self = $_[0]; |
112 |
|
|
if (@_ > 1) { |
113 |
|
|
if (${$$self->{owner_document}}->{strict_error_checking}) { |
114 |
|
|
if ($$self->{manakai_read_only}) { |
115 |
|
|
report Message::DOM::DOMException |
116 |
|
|
-object => $self, |
117 |
|
|
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
118 |
|
|
-subtype => 'READ_ONLY_NODE_ERR'; |
119 |
|
|
} |
120 |
|
|
} |
121 |
|
|
if ($_[1]) { |
122 |
|
|
$$self->{default_type} = 0+$_[1]; |
123 |
|
|
} else { |
124 |
|
|
delete $$self->{default_type}; |
125 |
|
|
} |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
return $$self->{default_type} || 0; |
129 |
|
|
} # default_type |
130 |
|
|
|
131 |
wakaba |
1.10 |
sub owner_element_type_definition ($); |
132 |
|
|
|
133 |
wakaba |
1.1 |
package Message::IF::AttributeDefinition; |
134 |
|
|
|
135 |
|
|
package Message::DOM::Document; |
136 |
|
|
|
137 |
wakaba |
1.2 |
sub create_attribute_definition ($$) { |
138 |
wakaba |
1.11 |
if (${$_[0]}->{strict_error_checking}) { |
139 |
|
|
my $xv = $_[0]->xml_version; |
140 |
|
|
if (defined $xv) { |
141 |
|
|
if ($xv eq '1.0' and |
142 |
|
|
$_[1] =~ /\A\p{InXML_NameStartChar10}\p{InXMLNameChar10}*\z/) { |
143 |
|
|
# |
144 |
|
|
} elsif ($xv eq '1.1' and |
145 |
|
|
$_[1] =~ /\A\p{InXMLNameStartChar11}\p{InXMLNameChar11}*\z/) { |
146 |
|
|
# |
147 |
|
|
} else { |
148 |
|
|
report Message::DOM::DOMException |
149 |
|
|
-object => $_[0], |
150 |
|
|
-type => 'INVALID_CHARACTER_ERR', |
151 |
|
|
-subtype => 'MALFORMED_NAME_ERR'; |
152 |
|
|
} |
153 |
|
|
} |
154 |
|
|
} |
155 |
|
|
|
156 |
wakaba |
1.1 |
return Message::DOM::AttributeDefinition->____new (@_[0, 1]); |
157 |
|
|
} # create_attribute_definition |
158 |
|
|
|
159 |
wakaba |
1.10 |
=head1 LICENSE |
160 |
|
|
|
161 |
|
|
Copyright 2007 Wakaba <w@suika.fam.cx> |
162 |
|
|
|
163 |
|
|
This program is free software; you can redistribute it and/or |
164 |
|
|
modify it under the same terms as Perl itself. |
165 |
|
|
|
166 |
|
|
=cut |
167 |
|
|
|
168 |
wakaba |
1.1 |
1; |
169 |
wakaba |
1.11 |
## $Date: 2007/07/12 13:54:46 $ |