/[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.1 - (hide annotations) (download)
Wed Jun 13 12:05:35 2007 UTC (17 years, 5 months ago) by wakaba
Branch: MAIN
New from NanoDOM.pm

1 wakaba 1.1 package Message::DOM::Attr;
2     use strict;
3     our $VERSION=do{my @r=(q$Revision: 1.3 $=~/\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     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     sub node_type { 2 } # ATTRIBUTE_NODE
60    
61     ## The |Attr| interface - attribute
62    
63     ## TODO: HTML5 case stuff?
64     sub name ($) {
65     my $self = shift;
66     if (defined $$self->{prefix}) {
67     return $$self->{prefix} . ':' . $$self->{local_name};
68     } else {
69     return $$self->{local_name};
70     }
71     } # name
72    
73     sub value ($;$) {
74     if (@_ > 1) {
75     ${$_[0]}->{value} = $_[1];
76     }
77     return ${$_[0]}->{value};
78     } # value
79    
80     package Message::IF::Attr;
81    
82     package Message::DOM::Document;
83    
84     sub create_attribute ($$) {
85     ## TODO: HTML5
86     return Message::DOM::Attr->____new ($_[0], undef, undef, undef, $_[1]);
87     } # create_attribute
88    
89     sub create_attribute_ns ($$$) {
90     my ($prefix, $lname);
91     if (ref $_[2] eq 'ARRAY') {
92     ($prefix, $lname) = @{$_[2]};
93     } else {
94     ($prefix, $lname) = split /:/, $_[2], 2;
95     ($prefix, $lname) = (undef, $prefix) unless defined $lname;
96     }
97     return Message::DOM::Attr->____new ($_[0], undef, $_[1], $prefix, $lname);
98     } # create_element_ns
99    
100     1;
101     ## License: <http://suika.fam.cx/~wakaba/archive/2004/8/18/license#Perl+MPL>
102     ## $Date:$

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24