Phylo/Unparsers/Html.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 41 SCAR 17.9
CC
2
Cov
0%
_to_string
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 6.0
1 package Bio::Phylo::Unparsers::Html;
2 use strict;
3 use warnings;
4 use base 'Bio::Phylo::Unparsers::Abstract';
5 use Bio::Phylo::Util::CONSTANT qw'/looks_like/ :objecttypes';
6 use Bio::Phylo::Util::Exceptions 'throw';
7 use Bio::Phylo::Util::Dependency qw'Template';
8  
9 =head1 NAME
10  
11 Bio::Phylo::Unparsers::Html - Serializer used by Bio::Phylo::IO, no serviceable
12 parts inside
13  
14 =head1 DESCRIPTION
15  
16 This module creates an HTML representation of the provided project
17  
18 =begin comment
19  
20 Type : Wrapper
21 Title : _to_string
22 Usage : my $json_string = $obj->_to_string;
23 Function: Stringifies a Bio::Phylo object into an HTML string
24 Alias :
25 Returns : SCALAR
26 Args : Bio::Phylo::* object
27  
28 =end comment
29  
30 =cut
31  
32 sub _to_string {
33 my $self = shift;
34 my $obj = $self->{'PHYLO'};
35 if ( $obj->_type == _PROJECT_ ) {
36 my $result;
37 my $template = $self->{'TEMPLATE'} || \*DATA;
38 my $tt = Template->new;
39 $tt->process($template,{'proj' => $obj},\$result);
40 return $result;
41 }
42 else {
43 throw 'ObjectMismatch' => "Can't make HTML string out of $obj";
44 }
45 }
46  
47 # podinherit_insert_token
48  
49 =head1 SEE ALSO
50  
51 There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo>
52 for any user or developer questions and discussions.
53  
54 =over
55  
56 =item L<Bio::Phylo::IO>
57  
58 The html unparser is called by the L<Bio::Phylo::IO> object.
59 Look there to learn how to unparse objects.
60  
61 =item L<Bio::Phylo::Manual>
62  
63 Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>.
64  
65 =back
66  
67 =head1 CITATION
68  
69 If you use Bio::Phylo in published research, please cite it:
70  
71 B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
72 and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
73 I<BMC Bioinformatics> B<12>:63.
74 L<http://dx.doi.org/10.1186/1471-2105-12-63>
75  
76 =cut
77  
78 1;
79  
80 __DATA__
81 <html>
82 <head>
83 <title>
84 [% IF proj.get_name %]
85 [% proj.get_name %]
86 [% END %]
87 </title>
88 </head>
89 <body>
90 <img src="http://www.evoio.org/wg/evoio/images/f/f1/Phylotastic_logo.png"/>
91 <h1>Document</h1>
92 [% PROCESS identifiable obj = proj, tag = "h2" %]
93
94 <!-- process taxa blocks, if any -->
95 [% IF proj.get_taxa.size > 0 %]
96 <h1>Taxa</h1>
97 <!-- iterate over each taxa block -->
98 <ul>
99 [% FOREACH taxa = proj.get_taxa %]
100 <li>
101
102 <!-- write taxa block metadata -->
103 [% PROCESS identifiable obj = taxa, tag = "h2" %]
104 <h3>Number of taxa: [% taxa.get_ntax %]</h3>
105
106 <!-- write taxon contents -->
107 <ul>
108 [% FOREACH taxon = taxa.get_entities %]
109 [% PROCESS identifiable obj = taxon, tag = "li" %]
110 [% END %]
111 </ul>
112 </li>
113 [% END %]
114 </ul>
115 [% END %]
116
117 <!-- process characters blocks, if any -->
118 [% IF proj.get_matrices.size > 0 %]
119 <h1>Characters</h1>
120 <!-- iterate over each characters block -->
121 [% FOREACH matrix = proj.get_matrices %]
122
123 <!-- write characters block metadata -->
124 [% PROCESS identifiable obj = matrix, tag = "h2" %]
125 <ul>
126 <li>Data type: [% matrix.get_type %]</li>
127 <li>Number of taxa: [% matrix.get_ntax %]</li>
128 <li>Number of characters: [% matrix.get_nchar %]</li>
129 <li>Taxa block:
130 <a href="#[% matrix.get_taxa.get_xml_id %]">
131 [% matrix.get_taxa.get_internal_name %]
132 </a>
133 <li>
134 </ul>
135
136 <!-- write datum contents -->
137 <table>
138 [% FOREACH datum = matrix.get_entities %]
139 <tr>
140 <td>
141 [% PROCESS identifiable obj = datum, tag = "h3" %]
142 </td>
143 <td>
144 <pre>[% datum.get_char %]</pre>
145 </td>
146 </tr>
147 [% END %]
148 <table>
149 [% END %]
150 [% END %]
151
152 <!-- process trees blocks, if any -->
153 [% IF proj.get_forests.size > 0 %]
154 <h1>Trees</h1>
155 <!-- iterate over each trees block -->
156 [% FOREACH forest = proj.get_forests %]
157
158 <!-- write trees block metadata -->
159 [% PROCESS identifiable obj = forest, tag = "h2" %]
160
161 <!-- write trees block contents -->
162 [% FOREACH tree = forest.get_entities %]
163 [% PROCESS identifiable obj = tree, tag = "h3" %]
164 <pre>[% tree.to_newick %]</pre>
165 [% END %]
166 [% END %]
167 [% END %]
168 </body>
169 </html>
170  
171 [% BLOCK identifiable %]
172 <[% tag %] id="[% obj.get_xml_id %]" class="[% obj.get_tag %]">
173 <a name="[% obj.get_xml_id %]">
174 [% IF obj.get_name %]
175 [% obj.get_name %]
176 [% END %]
177 </a>
178 </[% tag %]>
179 [% PROCESS annotatable %]
180 [% END %]
181  
182 [% BLOCK annotatable %]
183 [% IF obj.get_meta.size > 0 %]
184 <ul>
185 [% FOREACH meta = obj.get_meta %]
186 <li id="[% meta.get_xml_id %]" class="[% meta.get_tag %]">
187 <a href="[% meta.get_predicate_namespace %][% meta.get_predicate_local %]" class="predicate">
188 [% meta.get_predicate %]
189 </a> =
190 [% IF meta.is_resource %]
191 [% IF meta.is_xml_literal %]
192 <pre class="xml_literal">[% meta.get_object %]</pre>
193 [% ELSE %]
194 <a href="[% meta.get_object %]" rel="[% meta.get_predicate %]" class="resource">
195 [% meta.get_object %]
196 </a>
197 [% END %]
198 [% ELSE %]
199 <span class="[% meta.get_object_type %]">[% meta.get_object %]</span>
200 [% END %]
201 [% PROCESS annotatable obj = meta %]
202 </li>
203 [% END %]
204 </ul>
205 [% END %]
206 [% END %]