Changeset 17335

Show
Ignore:
Timestamp:
08/11/08 00:13:04 (5 years ago)
Author:
daisuke
Message:

Add has_dom_content

Location:
lang/perl/MooseX-DOM/trunk/lib/MooseX
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/MooseX-DOM/trunk/lib/MooseX/DOM.pm

    r17333 r17335  
    179179  ); 
    180180 
     181=head2 has_dom_content $name 
     182 
     183If your node only contains text data (that is, your root node does not have any 
     184subsequent element nodes as its child), you can access the text data directly 
     185with this declaration 
     186 
    181187=head1 AUTHOR 
    182188 
  • lang/perl/MooseX-DOM/trunk/lib/MooseX/DOM/LibXML.pm

    r17333 r17335  
    7979            $node->appendChild($child); 
    8080        } 
     81 
    8182        $child->removeChildNodes(); 
    8283        $child->appendTextNode($value); 
     
    148149            }); 
    149150        }, 
     151        has_dom_content => sub { 
     152            return Class::MOP::subname($subname->('has_dom_content') => sub ($) { 
     153                my $caller = caller(); 
     154                my $name = shift; 
     155                my $method = $subname->($name, $caller); 
     156                $subassign->($method => sub { 
     157                    my $self = shift; 
     158                    my $node = $self->node; 
     159                    return () unless $node; 
     160 
     161                    if (@_) { 
     162                        $node->removeChildNodes(); 
     163                        $node->appendText($_[0]); 
     164                    } 
     165 
     166                    return $node->textContent; 
     167                } ); 
     168            }); 
     169        }, 
    150170        has_dom_attr => sub { 
    151171            return Class::MOP::subname($subname->('has_dom_attr') => sub ($;%) { 
     
    162182                    my $self = shift; 
    163183                    my $node = $self->node; 
     184                    return () unless $node; 
     185 
    164186                    if (@_) { 
    165187                        $node->setAttribute($name, $_[0]);