/[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.5 - (show annotations) (download)
Sat Jun 16 15:27:45 2007 UTC (17 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.4: +35 -6 lines
++ manakai/t/ChangeLog	16 Jun 2007 15:27:38 -0000
	* DOM-Node.t: Tests for |prefix| and |text_content| are added.

2007-06-16  Wakaba  <wakaba@suika.fam.cx>

++ manakai/lib/Message/DOM/ChangeLog	16 Jun 2007 15:27:12 -0000
	* DOMConfiguration.pm: New module.

	* Attr.pm (trivial accessor for read-write attributes): Throw
	an exception if the node is read-only.  Delete the property
	if undef is specified.
	(prefix): Implemented.

	* DOMElement.pm (trivial accessor for read-write attributes): Throw
        an exception if the node is read-only.  Delete the property
        if undef is specified.
        (prefix): Implemented.
	(text_content, manakai_append_text): Old implementations are removed.

	* DOMCharacterData.pm (text_content): Implemented.

	* DOMDocument.pm (____new): Initialize the strict-document-children
	parameter by true.
	(text_content): Reimplemented.
	(dom_config): New.

	* DOMException.pm (READ_ONLY_NODE_ERR): New subtype.

	* DocumentType.pm (text_content): Implemented.

	* ElementTypeDefinition.pm (text_content): Implemented.

	* Node.pm (___report_error): New method.
	(text_content): Implemented.
	(manakai_append_text): Copied from |DOMElement.pm|.

	* Notation.pm (text_content): Implemented.

	* ProcessingInstruction.pm (text_content): Implemented.

	* Text.pm (is_element_content_whitespace): Alpha version.

2007-06-16  Wakaba  <wakaba@suika.fam.cx>

1 package Message::DOM::Attr;
2 use strict;
3 our $VERSION=do{my @r=(q$Revision: 1.4 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4 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 $$self->{child_nodes} = [];
15 return $self;
16 } # ____new
17
18 sub AUTOLOAD {
19 my $method_name = our $AUTOLOAD;
20 $method_name =~ s/.*:://;
21 return if $method_name eq 'DESTROY';
22
23 if ({
24 ## Read-only attributes (trivial accessors)
25 namespace_uri => 1,
26 owner_element => 1,
27 }->{$method_name}) {
28 no strict 'refs';
29 eval qq{
30 sub $method_name (\$) {
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 if (\${\$_[0]}->{manakai_read_only}) {
43 report Message::DOM::DOMException
44 -object => \$_[0],
45 -type => 'NO_MODIFICATION_ALLOWED_ERR',
46 -subtype => 'READ_ONLY_NODE_ERR';
47 }
48 if (defined \$_[1]) {
49 \${\$_[0]}->{$method_name} = ''.\$_[1];
50 } else {
51 delete \${\$_[0]}->{$method_name};
52 }
53 }
54 return \${\$_[0]}->{$method_name};
55 }
56 };
57 goto &{ $AUTOLOAD };
58 } else {
59 require Carp;
60 Carp::croak (qq<Can't locate method "$AUTOLOAD">);
61 }
62 } # AUTOLOAD
63 sub owner_element ($);
64
65 ## The |Node| interface - attribute
66
67 sub local_name ($) {
68 ## TODO: HTML5
69 return ${+shift}->{local_name};
70 } # local_name
71
72 sub manakai_local_name ($) {
73 return ${+shift}->{local_name};
74 } # manakai_local_name
75
76 sub namespace_uri ($);
77
78 ## The name of the attribute [DOM1, DOM2].
79 ## Same as |Attr.name| [DOM3].
80
81 *node_name = \&name;
82
83 sub node_type () { 2 } # ATTRIBUTE_NODE
84
85 ## The value of the attribute [DOM1, DOM2].
86 ## Same as |Attr.value| [DOM3].
87
88 *node_value = \&value;
89
90 sub prefix ($;$) {
91 ## NOTE: No check for new value as Firefox doesn't do.
92 ## See <http://suika.fam.cx/gate/2005/sw/prefix>.
93
94 ## NOTE: Same as trivial setter except "" -> undef
95
96 ## NOTE: Same as |Element|'s |prefix|.
97
98 if (@_ > 1) {
99 if (${$_[0]}->{manakai_read_only}) {
100 report Message::DOM::DOMException
101 -object => $_[0],
102 -type => 'NO_MODIFICATION_ALLOWED_ERR',
103 -subtype => 'READ_ONLY_NODE_ERR';
104 }
105 if (defined $_[1] and $_[1] ne '') {
106 ${$_[0]}->{prefix} = ''.$_[1];
107 } else {
108 delete ${$_[0]}->{prefix};
109 }
110 }
111 return ${$_[0]}->{prefix};
112 } # prefix
113
114 ## The |Attr| interface - attribute
115
116 ## TODO: HTML5 case stuff?
117 sub name ($) {
118 my $self = shift;
119 if (defined $$self->{prefix}) {
120 return $$self->{prefix} . ':' . $$self->{local_name};
121 } else {
122 return $$self->{local_name};
123 }
124 } # name
125
126 sub value ($;$) {
127 if (@_ > 1) {
128 ${$_[0]}->{value} = $_[1];
129 }
130 return ${$_[0]}->{value};
131 } # value
132
133 package Message::IF::Attr;
134
135 package Message::DOM::Document;
136
137 sub create_attribute ($$) {
138 ## TODO: HTML5
139 return Message::DOM::Attr->____new ($_[0], undef, undef, undef, $_[1]);
140 } # create_attribute
141
142 sub create_attribute_ns ($$$) {
143 my ($prefix, $lname);
144 if (ref $_[2] eq 'ARRAY') {
145 ($prefix, $lname) = @{$_[2]};
146 } else {
147 ($prefix, $lname) = split /:/, $_[2], 2;
148 ($prefix, $lname) = (undef, $prefix) unless defined $lname;
149 }
150 return Message::DOM::Attr->____new ($_[0], undef, $_[1], $prefix, $lname);
151 } # create_element_ns
152
153 1;
154 ## License: <http://suika.fam.cx/~wakaba/archive/2004/8/18/license#Perl+MPL>
155 ## $Date: 2007/06/16 08:05:48 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24