Bio::Phylo::NeXML::Meta::XMLLiteral - Annotation value adaptor, no direct usage


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

Index


Code Index:

NAME

Top

Bio::Phylo::NeXML::Meta::XMLLiteral - Annotation value adaptor, no direct usage

SYNOPSIS

Top

 # no direct usage

DESCRIPTION

Top

No direct usage, is used internally by Bio::Phylo::NeXML::Meta to wrap objects into a common adaptor class for serialization to XML.

METHODS

Top

CONSTRUCTOR

new()
 Type    : Constructor
 Title   : new
 Usage   : my $lit = Bio::Phylo::NeXML::Meta::XMLLiteral->new($obj);
 Function: Initializes a Bio::Phylo::NeXML::Meta::XMLLiteral object.
 Returns : A Bio::Phylo::NeXML::Meta::XMLLiteral object.
 Args    : An object (or array ref of objects) to wrap,
           either a 'RDF::Core::Model' (or subclass),
           an 'XML::XMLWriter' or (subclass) or any
           of the following serialization methods
           used for duck-typing one of the following classes:
 	       Bio::Phylo                        => to_xml, 
 	       XML::DOM, XML::GDOME, XML::LibXML => toString, 
 	       XML::Twig                         => sprint,
	       XML::DOM2                         => xmlify, 
	       XML::DOMBacked                    => as_xml,
	       XML::Handler                      => dump_tree, 
	       XML::Element                      => as_XML
	       XML::API                          => _as_string, 
	       XML::Code                         => code	   




SERIALIZERS

to_xml()

Serializes invocant to xml.

 Type    : Serializer
 Title   : to_xml
 Usage   : my $xml = $obj->to_xml;
 Function: Turns the invocant object (and its descendants) into an XML string.
 Returns : SCALAR
 Args    : NONE

SEE ALSO

Top

Bio::Phylo::NeXML::Meta
Bio::Phylo::Manual

Also see the manual: Bio::Phylo::Manual and http://rutgervos.blogspot.com.

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

REVISION

Top

 $Id: XMLLiteral.pm 1660 2011-04-02 18:29:40Z rvos $


Bio-Phylo documentation Contained in the Bio-Phylo distribution.
package Bio::Phylo::NeXML::Meta::XMLLiteral;
use strict;
use Bio::Phylo::Util::CONSTANT qw'_META_ /looks_like/';
use Bio::Phylo::Util::Exceptions 'throw';
{
    my $TYPE_CONSTANT      = _META_;
    my $CONTAINER_CONSTANT = $TYPE_CONSTANT;

    sub new {
        my ( $class, $obj ) = @_;
        return bless \$obj, $class;
    }

    sub to_xml {
        my $self = shift;
        my $objs = $$self;
        my @objs = ref($objs) eq 'ARRAY' ? @{$objs} : ($objs);
        my $xml  = '';
        for my $obj (@objs) {

            # for RDF::Core::Model objects
            if ( looks_like_instance( $obj, 'RDF::Core::Model' ) ) {
                eval {
                    require RDF::Core::Model::Serializer;
                    my $serialized_model = '';
                    my $serializer       = RDF::Core::Model::Serializer->new(
                        'Model'  => $obj,
                        'Output' => \$serialized_model,
                    );
                    $xml .= $serialized_model;
                };
                if ($@) {
                    throw 'API' => $@;
                }
            }

            # for XML::XMLWriter object
            elsif ( looks_like_instance( $obj, 'XML::XMLWriter' ) ) {
                $xml .= $obj->get;
            }
            else {

                # duck-typing
                # Bio::Phylo => to_xml,
                # XML::DOM,XML::GDOME,XML::LibXML => toString,
                # XML::Twig => sprint
                # XML::DOM2 => xmlify,
                # XML::DOMBacked => as_xml,
                # XML::Handler => dump_tree,
                # XML::Element => as_XML
                # XML::API => _as_string,
                # XML::Code => code
                my @methods =
                  qw(to_xml toString sprint _as_string code xmlify as_xml dump_tree as_XML);
              SERIALIZER: for my $method (@methods) {
                    if ( looks_like_implementor( $obj, $method ) ) {
                        $xml .= $obj->$method;
                        last SERIALIZER;
                    }
                }
            }
        }
        return $xml;
    }

    # podinherit_insert_token

    sub _type      { $TYPE_CONSTANT }
    sub _container { $CONTAINER_CONSTANT }
    sub _cleanup   { }
}
1;