/[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.2 - (hide annotations) (download)
Fri Jun 15 14:32:49 2007 UTC (17 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.1: +21 -3 lines
++ manakai/t/ChangeLog	15 Jun 2007 14:31:27 -0000
2007-06-15  Wakaba  <wakaba@suika.fam.cx>

	* DOM-Node.t: New test.

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

	* DOM-Document.t: New test.

++ manakai/lib/Message/DOM/ChangeLog	15 Jun 2007 14:32:37 -0000
2007-06-15  Wakaba  <wakaba@suika.fam.cx>

	* ProcessingInstruction.pm, EntityReference.pm,
	CDATASection, DocumentFragment.pm, DOMDocument.pm, Entity.pm,
	ElementTypeDefinition.pm, AttributeDefinition.pm,
	DocumentType.pm, DOMElement.pm, Attr.pm,
	CharacterData.pm, Text.pm, Comment.pm (node_name,
	node_value, node_type): Implemented.

1 wakaba 1.1 package Message::DOM::Attr;
2     use strict;
3 wakaba 1.2 our $VERSION=do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4 wakaba 1.1 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     return $self;
15     } # ____new
16    
17     sub AUTOLOAD {
18     my $method_name = our $AUTOLOAD;
19     $method_name =~ s/.*:://;
20     return if $method_name eq 'DESTROY';
21    
22     if ({
23     ## Read-only attributes (trivial accessors)
24     owner_element => 1,
25     }->{$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     } elsif ({
38     ## Read-write attributes (DOMString, trivial accessors)
39     }->{$method_name}) {
40     no strict 'refs';
41     eval qq{
42     sub $method_name (\$) {
43     if (\@_ > 1) {
44     \${\$_[0]}->{$method_name} = ''.$_[1];
45     }
46     return \${\$_[0]}->{$method_name};
47     }
48     };
49     goto &{ $AUTOLOAD };
50     } else {
51     require Carp;
52     Carp::croak (qq<Can't locate method "$AUTOLOAD">);
53     }
54     } # AUTOLOAD
55     sub owner_element ($);
56    
57     ## The |Node| interface - attribute
58    
59 wakaba 1.2 ## Spec:
60     ## <http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-F68D095>
61     ## Modified: <http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-1841493061>
62    
63     ## The name of the attribute [DOM1, DOM2].
64     ## Same as |Attr.name| [DOM3].
65    
66     *node_name = \&name;
67    
68     sub node_type () { 2 } # ATTRIBUTE_NODE
69    
70     ## Spec:
71     ## <http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-F68D080>
72     ## Modified: <http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-1841493061>
73    
74     ## The value of the attribute [DOM1, DOM2].
75     ## Same as |Attr.value| [DOM3].
76    
77     *node_value = \&value;
78 wakaba 1.1
79     ## The |Attr| interface - attribute
80    
81     ## TODO: HTML5 case stuff?
82     sub name ($) {
83     my $self = shift;
84     if (defined $$self->{prefix}) {
85     return $$self->{prefix} . ':' . $$self->{local_name};
86     } else {
87     return $$self->{local_name};
88     }
89     } # name
90    
91     sub value ($;$) {
92     if (@_ > 1) {
93     ${$_[0]}->{value} = $_[1];
94     }
95     return ${$_[0]}->{value};
96     } # value
97    
98     package Message::IF::Attr;
99    
100     package Message::DOM::Document;
101    
102     sub create_attribute ($$) {
103     ## TODO: HTML5
104     return Message::DOM::Attr->____new ($_[0], undef, undef, undef, $_[1]);
105     } # create_attribute
106    
107     sub create_attribute_ns ($$$) {
108     my ($prefix, $lname);
109     if (ref $_[2] eq 'ARRAY') {
110     ($prefix, $lname) = @{$_[2]};
111     } else {
112     ($prefix, $lname) = split /:/, $_[2], 2;
113     ($prefix, $lname) = (undef, $prefix) unless defined $lname;
114     }
115     return Message::DOM::Attr->____new ($_[0], undef, $_[1], $prefix, $lname);
116     } # create_element_ns
117    
118     1;
119     ## License: <http://suika.fam.cx/~wakaba/archive/2004/8/18/license#Perl+MPL>
120 wakaba 1.2 ## $Date: 2007/06/13 12:05:35 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24