Phylo/NeXML/Meta/XMLLiteral.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 67 CC 6 SCAR 28.9
CC
6
Cov
0%
to_xml
42.0
new
2.0
_type
2.0
CRAP 18.0
1 package Bio::Phylo::NeXML::Meta::XMLLiteral;
2 use strict;
3 use warnings;
4 use Bio::Phylo::Util::CONSTANT qw'_META_ /looks_like/';
5 use Bio::Phylo::Util::Exceptions 'throw';
6 {
7 my $TYPE_CONSTANT = _META_;
8 my $CONTAINER_CONSTANT = $TYPE_CONSTANT;
9  
10 =head1 NAME
11  
12 Bio::Phylo::NeXML::Meta::XMLLiteral - Annotation value adaptor, no direct usage
13  
14 =head1 SYNOPSIS
15  
16 # no direct usage
17  
18 =head1 DESCRIPTION
19  
20 No direct usage, is used internally by L<Bio::Phylo::NeXML::Meta> to
21 wrap objects into a common adaptor class for serialization to
22 XML.
23  
24 =head1 METHODS
25  
26 =head2 CONSTRUCTOR
27  
28 =over
29  
30 =item new()
31  
32 Type : Constructor
33 Title : new
34 Usage : my $lit = Bio::Phylo::NeXML::Meta::XMLLiteral->new($obj);
35 Function: Initializes a Bio::Phylo::NeXML::Meta::XMLLiteral object.
36 Returns : A Bio::Phylo::NeXML::Meta::XMLLiteral object.
37 Args : An object (or array ref of objects) to wrap,
38 either a 'RDF::Core::Model' (or subclass),
39 an 'XML::XMLWriter' or (subclass) or any
40 of the following serialization methods
41 used for duck-typing one of the following classes:
42 Bio::Phylo => to_xml,
43 XML::DOM, XML::GDOME, XML::LibXML => toString,
44 XML::Twig => sprint,
45 XML::DOM2 => xmlify,
46 XML::DOMBacked => as_xml,
47 XML::Handler => dump_tree,
48 XML::Element => as_XML
49 XML::API => _as_string,
50 XML::Code => code
51
52  
53 =cut
54  
55 sub new {
56 my ( $class, $obj ) = @_;
57 return bless \$obj, $class;
58 }
59  
60 =back
61  
62 =head2 SERIALIZERS
63  
64 =over
65  
66 =item to_xml()
67  
68 Serializes invocant to xml.
69  
70 Type : Serializer
71 Title : to_xml
72 Usage : my $xml = $obj->to_xml;
73 Function: Turns the invocant object (and its descendants) into an XML string.
74 Returns : SCALAR
75 Args : NONE
76  
77 =cut
78  
79 sub to_xml {
80 my $self = shift;
81 my $objs = $$self;
82 my @objs = ref($objs) eq 'ARRAY' ? @{$objs} : ($objs);
83 my $xml = '';
84 for my $obj (@objs) {
85  
86 # for RDF::Core::Model objects
87 if ( looks_like_instance( $obj, 'RDF::Core::Model' ) ) {
88 eval {
89 require RDF::Core::Model::Serializer;
90 my $serialized_model = '';
91 my $serializer = RDF::Core::Model::Serializer->new(
92 'Model' => $obj,
93 'Output' => \$serialized_model,
94 );
95 $xml .= $serialized_model;
96 };
97 if ($@) {
98 throw 'API' => $@;
99 }
100 }
101  
102 # for XML::XMLWriter object
103 elsif ( looks_like_instance( $obj, 'XML::XMLWriter' ) ) {
104 $xml .= $obj->get;
105 }
106 else {
107  
108 # duck-typing
109 # Bio::Phylo => to_xml,
110 # XML::DOM,XML::GDOME,XML::LibXML => toString,
111 # XML::Twig => sprint
112 # XML::DOM2 => xmlify,
113 # XML::DOMBacked => as_xml,
114 # XML::Handler => dump_tree,
115 # XML::Element => as_XML
116 # XML::API => _as_string,
117 # XML::Code => code
118 my @methods =
119 qw(to_xml toString sprint _as_string code xmlify as_xml dump_tree as_XML);
120 SERIALIZER: for my $method (@methods) {
121 if ( looks_like_implementor( $obj, $method ) ) {
122 $xml .= $obj->$method;
123 last SERIALIZER;
124 }
125 }
126 }
127 }
128 return $xml;
129 }
130  
131 =back
132  
133 =cut
134  
135 # podinherit_insert_token
136  
137 =head1 SEE ALSO
138  
139 There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo>
140 for any user or developer questions and discussions.
141  
142 =over
143  
144 =item L<Bio::Phylo::NeXML::Meta>
145  
146 =item L<Bio::Phylo::Manual>
147  
148 Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>.
149  
150 =back
151  
152 =head1 CITATION
153  
154 If you use Bio::Phylo in published research, please cite it:
155  
156 B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
157 and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
158 I<BMC Bioinformatics> B<12>:63.
159 L<http://dx.doi.org/10.1186/1471-2105-12-63>
160  
161 =cut
162  
163 sub _type { $TYPE_CONSTANT }
164 sub _container { $CONTAINER_CONSTANT }
165 sub _cleanup { }
166 }
167 1;