/[suikacvs]/messaging/manakai/lib/Message/DOM/Node.pm
Suika

Diff of /messaging/manakai/lib/Message/DOM/Node.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by wakaba, Fri Jun 15 16:12:28 2007 UTC revision 1.4 by wakaba, Sat Jun 16 08:05:48 2007 UTC
# Line 4  our $VERSION=do{my @r=(q$Revision$=~/\d+ Line 4  our $VERSION=do{my @r=(q$Revision$=~/\d+
4  push our @ISA, 'Message::IF::Node';  push our @ISA, 'Message::IF::Node';
5  require Scalar::Util;  require Scalar::Util;
6    
7    ## NOTE:
8    ##   Node
9    ##   + Attr (2)
10    ##   + AttributeDefinition (81002)
11    ##   + CharacterData
12    ##     + Comment (8)
13    ##     + Text (3)
14    ##       + CDATASection (4)
15    ##   + Document (9)
16    ##   + DocumentFragment (11)
17    ##   + DocumentType (10)
18    ##   + Element (1)
19    ##   + ElementTypeDefinition (81001)
20    ##   + Entity (6)
21    ##   + EntityReference (5)
22    ##   + Notation (12)
23    ##   + ProcessingInstruction (7)
24    
25    use overload
26        '==' => sub {
27          return 0 unless UNIVERSAL::isa ($_[0], 'Message::IF::Node');
28          ## TODO: implement is_equal_node
29          return $_[0]->is_equal_node ($_[1]);
30        },
31        '!=' => sub {
32          return not ($_[0] == $_[1]);
33        },
34        fallback => 1;
35    
36  ## The |Node| interface - constants  ## The |Node| interface - constants
37    
38  ## Definition group NodeType  ## Definition group NodeType
39    
 ## Spec:  
 ## <http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-1841493061>  
 ## <http://suika.fam.cx/gate/2005/sw/manakai/DOM%20Extensions#anchor-23>  
   
40  ## NOTE: Numeric codes up to 200 are reserved by W3C [DOM1SE, DOM2, DOM3].  ## NOTE: Numeric codes up to 200 are reserved by W3C [DOM1SE, DOM2, DOM3].
41    
42  sub ELEMENT_NODE () { 1 }  sub ELEMENT_NODE () { 1 }
# Line 57  sub AUTOLOAD { Line 82  sub AUTOLOAD {
82      ## Read-only attributes (trivial accessors)      ## Read-only attributes (trivial accessors)
83      owner_document => 1,      owner_document => 1,
84      parent_node => 1,      parent_node => 1,
85        manakai_read_only => 1,
86    }->{$method_name}) {    }->{$method_name}) {
87      no strict 'refs';      no strict 'refs';
88      eval qq{      eval qq{
# Line 93  sub attributes ($) { Line 119  sub attributes ($) {
119    
120  ## TODO: baseURI  ## TODO: baseURI
121    
 ## TODO: childNodes  
122  sub child_nodes ($) {  sub child_nodes ($) {
123    my $self = shift;    require Message::DOM::NodeList;
124    return $$self->{child_nodes} || [];    return bless \\($_[0]), 'Message::DOM::NodeList::ChildNodeList';
125  } # child_nodes  } # child_nodes
126    
127  sub first_child ($) {  sub first_child ($) {
# Line 168  sub previous_sibling ($) { Line 193  sub previous_sibling ($) {
193    return undef;    return undef;
194  } # previous_sibling  } # previous_sibling
195    
196    sub manakai_read_only ($);
197    
198  sub text_content ($;$) {  sub text_content ($;$) {
199    ## TODO:    ## TODO:
200  } # text_content  } # text_content
201    
202    ## TODO:
203    sub is_same_node ($$) {
204      return $_[0] eq $_[1];
205    } # is_same_node
206    
207    ## TODO:
208  sub is_equal_node ($$) {  sub is_equal_node ($$) {
209    return shift eq shift;    return $_[0]->node_name eq $_[1]->node_name &&
210        $_[0]->node_value eq $_[1]->node_value;
211  } # is_equal_node  } # is_equal_node
212    
   
213  sub manakai_parent_element ($) {  sub manakai_parent_element ($) {
214    my $self = shift;    my $self = shift;
215    my $parent = $$self->{parent_node};    my $parent = $$self->{parent_node};
# Line 190  sub manakai_parent_element ($) { Line 223  sub manakai_parent_element ($) {
223    return undef;    return undef;
224  } # manakai_parent_element  } # manakai_parent_element
225    
 sub child_nodes ($) {  
   ## TODO: NodeList  
   return ${+shift}->{child_nodes} || [];  
 } # child_nodes  
   
226  ## NOTE: Only applied to Elements and Documents  ## NOTE: Only applied to Elements and Documents
227  sub append_child ($$) {  sub append_child ($$) {
228    my ($self, $new_child) = @_;    my ($self, $new_child) = @_;
# Line 256  sub has_child_nodes ($) { Line 284  sub has_child_nodes ($) {
284    return @{${+shift}->{child_nodes}} > 0;    return @{${+shift}->{child_nodes}} > 0;
285  } # has_child_nodes  } # has_child_nodes
286    
287  ## NOTE: Only applied to Elements and Documents  sub manakai_set_read_only ($;$$) {
288  sub first_child ($) {    my ($self, $value, $deep) = @_;
289    my $self = shift;    ## TODO: deep
290    return $$self->{child_nodes}->[0];    $$self->{manakai_read_only} = $value;
291  } # first_child  } # manakai_set_read_only
292    
293  ## NOTE: Only applied to Elements and Documents  package Message::IF::Node;
 sub last_child ($) {  
   my $self = shift;  
   return @{$$self->{child_nodes}} ? $$self->{child_nodes}->[-1] : undef;  
 } # last_child  
294    
295  ## NOTE: Only applied to Elements and Documents  =head1 LICENSE
 sub previous_sibling ($) {  
   my $self = shift;  
   my $parent = $$self->{parent_node};  
   return undef unless defined $parent;  
   my $r;  
   for (@{$$parent->{child_nodes}}) {  
     if ($_ eq $self) {  
       return $r;  
     } else {  
       $r = $_;  
     }  
   }  
   return undef;  
 } # previous_sibling  
296    
297  package Message::IF::Node;  Copyright 2007 Wakaba <w@suika.fam.cx>
298    
299    This program is free software; you can redistribute it and/or
300    modify it under the same terms as Perl itself.
301    
302    =cut
303    
304  1;  1;
 ## License: <http://suika.fam.cx/~wakaba/archive/2004/8/18/license#Perl+MPL>  
305  ## $Date$  ## $Date$

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24