Bio::Phylo::NeXML::DOM::Document::Twig - XML DOM document mappings to the


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

Index


Code Index:

NAME

Top

Bio::Phylo::NeXML::DOM::Document::Twig - XML DOM document mappings to the XML::Twig package

SYNOPSIS

Top

Don't use directly; use Bio::Phylo::NeXML::DOM->new( -format => 'twig' ) instead.

DESCRIPTION

Top

This module provides mappings the methods specified in the Bio::Phylo::NeXML::DOM::Document abstract class to the XML::Twig package.

AUTHOR

Top

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

Constructor

new()
 Type    : Constructor
 Title   : new
 Usage   : $doc = Bio::Phylo::NeXML::DOM::Document->new(@args)
 Function: Create a Document object using the underlying package
 Returns : Document object or undef on fail
 Args    : Package-specific arguments

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

Document property accessors/mutators

set_encoding()
 Type    : Mutator
 Title   : set_encoding
 Usage   : $doc->set_encoding($enc)
 Function: Set encoding for document
 Returns : True on success
 Args    : Encoding descriptor as string

get_encoding()
 Type    : Accessor
 Title   : get_encoding
 Usage   : $doc->get_encoding()
 Function: Get encoding for document
 Returns : Encoding descriptor as string
 Args    : none

set_root()
 Type    : Mutator
 Title   : set_root
 Usage   : $doc->set_root($elt)
 Function: Set the document's root element
 Returns : True on success
 Args    : Element object

get_root()
 Type    : Accessor
 Title   : get_root
 Usage   : $doc->get_root()
 Function: Get the document's root element
 Returns : Element object or undef if DNE
 Args    : none

Document element accessors

get_element_by_id()
 Type    : Accessor
 Title   : get_element_by_id
 Usage   : $doc->get_element_by_id($id)
 Function: Get element having id $id
 Returns : Element object or undef if DNE
 Args    : id designator as string

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 
 Returns : Array of elements or undef if no match
 Args    : tag name as string

Output methods

to_xml()
 Type    : Serializer
 Title   : to_xml
 Usage   : $doc->to_xml
 Function: Create XML string from document
 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: Twig.pm 1660 2011-04-02 18:29:40Z rvos $

package Bio::Phylo::NeXML::DOM::Document::Twig;
use strict;
use Bio::Phylo::Util::Exceptions 'throw';
use Bio::Phylo::Util::Dependency 'XML::Twig';
use Bio::Phylo::NeXML::DOM::Document;
use Bio::Phylo::Util::CONSTANT 'looks_like_instance';
use base qw'Bio::Phylo::NeXML::DOM::Document XML::Twig';

sub new {
    my ( $class, @args ) = @_;
    my $self = XML::Twig->new();
    $self->set_encoding();
    bless $self, $class;
    return $self;
}

sub parse_document {
    my ( $class, $text ) = @_;
    my $self = XML::Twig->new();
    $self->parse($text);
    bless $self, $class;
    return $self;
}

sub set_encoding {
    my ( $self, $encoding, @args ) = @_;
    $self->set_encoding($encoding);
    return 1;
}

sub get_encoding {
    return shift->encoding;
}

sub set_root {
    my ( $self, $root ) = @_;
    if ( looks_like_instance $root, 'XML::Twig::Elt' ) {
        XML::Twig::set_root( $self, $root );

        # manage ids
        for ( $root->descendants_or_self ) {
            ${ $self->{twig_id_list} }{ $_->att('id') } = $_ if $_->att('id');
        }
        return 1;
    }
    else {
        throw 'ObjectMisMatch' => 'Argument is not an XML::Twig::Elt';
    }
}

sub get_root {
    return shift->root;
}

sub get_element_by_id {
    return shift->elt_id(shift);
}

sub get_elements_by_tagname {
    my ( $self, $tagname, @args ) = @_;
    return $self->get_root->get_elements_by_tagname($tagname);
}

sub to_xml {
    my ( $self, @args ) = @_;
    return $self->sprint(@args);
}

1;