Bio::Phylo::NeXML::DOM::Element - XML DOM Abstract class for


Bio-Phylo documentation Contained in the Bio-Phylo distribution.

Index


Code Index:

NAME

Top

Bio::Phylo::NeXML::DOM::Element - XML DOM Abstract class for flexible document object model implementation

SYNOPSIS

Top

Not used directly.

DESCRIPTION

Top

This module describes an abstract implementation of a DOM object as expected by Bio::Phylo. The methods here must be overridden in any concrete implementation. The idea is that different implementations use a particular XML DOM package, binding the methods here to analogous package methods.

This set of methods is intentionally minimal. The concrete instances of this class should inherit both from ElementI and the underlying XML DOM object class, so that package-specific methods can be directly accessed from the instantiated object.

AUTHOR

Top

Mark A. Jensen - maj -at- fortinbras -dot- us

Constructor

new()
 Type    : Constructor
 Title   : new
 Usage   : $elt = Bio::Phylo::NeXML::DOM::Element->new($tag, $attr)
 Function: Create a new XML DOM element
 Returns : DOM element object
 Args    : Optional: 
           '-tag' => $tag  - tag name as string
           '-attr'    => $attr - hashref of attributes/values

parse_element()
 Type    : Factory method
 Title   : parse_element
 Usage   : $elt = $dom->parse_element($text)
 Function: Create a new XML DOM element from XML text
 Returns : DOM element
 Args    : An XML String

Namespace accessors/mutators

 Type    : 
 Title   :
 Usage   :
 Function:
 Returns :
 Args    :

Tagname mutators/accessors

get_tag()
 Type    : Accessor
 Title   : get_tag
 Usage   : $elt->get_tag()
 Function: Get tag name
 Returns : Tag name as scalar string
 Args    : none

set_tag()
 Type    : Mutator
 Title   : set_tag
 Usage   : $elt->set_tag( $tagname )
 Function: Set tagname
 Returns : True on success
 Args    : Tag name as scalar string

Attribute mutators/accessors

get_attributes()
 Type    : Accessor
 Title   : get_attributes
 Usage   : $elt->get_attributes( @attribute_names )
 Function: Get attribute values
 Returns : A hash ref of key/value pairs
 Args    : Optional, [a list of] attribute name[s] as string[s]

set_attributes()
 Type    : Mutator
 Title   : set_attributes
 Usage   : $elt->set_attributes( @attribute_assoc_array )
 Function: Set attribute values
 Returns : True on success
 Args    : An associative array of form ( $name => $value, ... )

clear_attributes()
 Type    : Mutator
 Title   : clear_attributes
 Usage   : $elt->clear_attributes( @attribute_names )
 Function: Remove attributes from element
 Returns : Hash of removed attributes/values
 Args    : Array of attribute names

Content mutators/accessors

set_text()
 Type    : Mutator
 Title   : set_text
 Usage   : $elt->set_text($text_content)
 Function: Add a #TEXT node to the element 
 Returns : True on success
 Args    : scalar string

get_text()
 Type    : Accessor
 Title   : get_text
 Usage   : $elt->get_text()
 Function: Retrieve direct #TEXT descendants as (concatenated) string
 Returns : scalar string (the text content)
 Args    : none

clear_text()
 Type    : Mutator
 Title   : clear_text
 Usage   : $elt->clear_text()
 Function: Remove direct #TEXT descendant nodes from element
 Returns : True on success; false if no #TEXT nodes removed
 Args    : none

Traversal methods

get_parent()
 Type    : Accessor
 Title   : get_parent
 Usage   : $elt->get_parent()
 Function: Get parent DOM node of invocant 
 Returns : Element object or undef if invocant is root
 Args    : none

get_children()
 Type    : Accessor
 Title   : get_children
 Usage   : $elt->get_children()
 Function: Get child nodes of invocant
 Returns : Array ref of Elements
 Args    : none

get_first_daughter()
 Type    : Accessor
 Title   : get_first_daughter
 Usage   : $elt->get_first_daughter()
 Function: Get first child (as defined by underlying package) of invocant
 Returns : Element object or undef if invocant is childless
 Args    : none

get_last_daughter()
 Type    : Accessor
 Title   : get_last_daughter
 Usage   : $elt->get_last_daughter()
 Function: Get last child (as defined by underlying package) of invocant
 Returns : Element object or undef if invocant is childless
 Args    : none

get_next_sister()
 Type    : Accessor
 Title   : get_next_sister
 Usage   : $elt->get_next_sister()
 Function: Gets next sibling (as defined by underlying package) of invocant
 Returns : Element object or undef if invocant is the rightmost element
 Args    : none

get_previous_sister()
 Type    : Accessor
 Title   : get_previous_sister
 Usage   : $elt->get_previous_sister()
 Function: Get previous sibling (as defined by underlying package) of invocant
 Returns : Element object or undef if invocant is leftmost element
 Args    : none

get_elements_by_tagname()
 Type    : Accessor
 Title   : get_elements_by_tagname
 Usage   : $elt->get_elements_by_tagname($tagname)
 Function: Get array of elements having given tag name from invocant's 
           descendants
 Returns : Array of elements or undef if no match
 Args    : tag name as string

Prune and graft methods

set_child()
 Type    : Mutator
 Title   : set_child
 Usage   : $elt->set_child($child)
 Function: Add child element object to invocant's descendants
 Returns : the element object added
 Args    : Element object

prune_child()
 Type    : Mutator
 Title   : prune_child
 Usage   : $elt->prune_child($child)
 Function: Remove the subtree rooted by $child from among the invocant's
           descendants
 Returns : $child or undef if $child is not among the children of invocant
 Args    : Element object

Output methods

to_xml()
 Type    : Serializer
 Title   : to_xml
 Usage   : $elt->to_xml
 Function: Create XML string from subtree rooted by invocant
 Returns : XML string
 Args    : Formatting arguments as allowed by underlying package

CITATION

Top

If you use Bio::Phylo in published research, please cite it:

Rutger A Vos, Jason Caravas, Klaas Hartmann, Mark A Jensen and Chase Miller, 2011. Bio::Phylo - phyloinformatic analysis using Perl. BMC Bioinformatics 12:63. http://dx.doi.org/10.1186/1471-2105-12-63


Bio-Phylo documentation Contained in the Bio-Phylo distribution.
# $Id: Element.pm 1660 2011-04-02 18:29:40Z rvos $
package Bio::Phylo::NeXML::DOM::Element;
use strict;
use Bio::Phylo::Util::Exceptions 'throw';
use Bio::Phylo::Util::CONSTANT qw'_ELEMENT_ /looks_like/';

sub new {
    my $class = shift;
    if ( my %args = looks_like_hash @_ ) {
        $class = __PACKAGE__ . '::' . ucfirst( lc( $args{'-format'} ) );
        delete $args{'-format'};
        return looks_like_class($class)->new(%args);
    }
}

sub parse_element {
    throw 'NotImplemented' => "Can't call 'get_tag' on interface";
}

sub _recurse_bless {
    my $node  = shift;
    my $class = ref $node;
    for my $child ( @{ $node->get_children } ) {
        bless $child, $class;
        _recurse_bless($child);
    }
}

sub get_tag {
    throw 'NotImplemented' => "Can't call 'get_tag' on interface";
}

sub set_tag {
    throw 'NotImplemented' => "Can't call 'set_tag' on interface";
}

sub get_attributes {
    throw 'NotImplemented' => "Can't call 'get_attributes' on interface";
}

sub set_attributes {
    throw 'NotImplemented' => "Can't call 'set_attributes' on interface";
}

sub clear_attributes {
    throw 'NotImplemented' => "Can't call 'clear_attributes' on interface";
}

sub set_text {
    throw 'NotImplemented' => "Can't call 'set_text' on interface";
}

sub get_text {
    throw 'NotImplemented' => "Can't call 'get_text' on interface";
}

sub clear_text {
    throw 'NotImplemented' => "Can't call 'clear_text' on interface";
}

sub get_parent {
    throw 'NotImplemented' => "Can't call 'get_parent' on interface";
}

sub get_children {
    throw 'NotImplemented' => "Can't call 'get_children' on interface";
}

sub get_first_daughter {
    throw 'NotImplemented' => "Can't call 'get_first_daughter' on interface";
}

sub get_last_daughter {
    throw 'NotImplemented' => "Can't call 'get_last_daughter' on interface";
}

sub get_next_sister {
    throw 'NotImplemented' => "Can't call 'get_next_sister' on interface";
}

sub get_previous_sister {
    throw 'NotImplemented' => "Can't call 'get_previous_sister' on interface";
}

sub get_elements_by_tagname {
    throw 'NotImplemented' =>
      "Can't call 'get_elements_by_tagname' on interface";
}

sub set_child {
    throw 'NotImplemented' => "Can't call 'set_child' on interface";
}

sub prune_child {
    throw 'NotImplemented' => "Can't call 'prune_child' on interface";
}

sub to_xml {
    throw 'NotImplemented' => "Can't call 'to_xml' on interface";
}

1;