blib/conf/MobyServices/b64_encoded_jpeg_renderer.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 75 CC 7 SCAR 33.7
CC
7
Cov
0%
getStringContent
56.0
types
2.0
render
2.0
CRAP 29.0
1 package MobyServices::b64_encoded_jpeg_renderer;
2 use strict;
3 use XML::LibXML;
4 use MOBY::MobyXMLConstants;
5 our @ISA = qw(Exporter);
6 use File::Temp qw/ tempfile /;
7 our @EXPORT_OK = qw(render type);
8 use MIME::Base64;
9  
10  
11 sub types {
12 return ["b64_encoded_jpeg"];
13 }
14  
15 sub render {
16 my ($DOM, $htmldir,$imgdir) = @_;
17 my $content;
18 $content = &getStringContent($DOM);
19 $content =~ s/^\s+//; $content =~ s/\s+$//;
20 my $bindata = decode_base64($content);
21 my ($fh, $filename) = tempfile( DIR => "$htmldir/$imgdir/", SUFFIX=> ".jpg" );
22 $filename =~ /(\w+\.jpg)$/;
23 $filename = $1;
24 binmode($fh);
25 print $fh $bindata;
26 close $fh;
27 return ("<img src='$imgdir/$filename'>");
28 }
29  
30 sub getStringContent {
31 my ($ROOT) = @_;
32 my $content;
33 my @childnodes = $ROOT->childNodes;
34 foreach (@childnodes){
35 next unless ($_->nodeType == ELEMENT_NODE);
36 next unless ($_->localname eq "String");
37 my $article = $_->getAttributeNode('articleName');
38 $article = $_->getAttributeNode('moby:articleName') unless $article;
39 next unless $article;
40 next unless $article->getValue eq 'content'; # the articleName for String content of a text-xml node
41 foreach my $subnode($_->childNodes){ # if it is correct, then get the text content
42 next unless (($subnode->nodeType == TEXT_NODE) || ($subnode->nodeType == CDATA_SECTION_NODE));
43 $content .=$subnode->textContent;
44 }
45 $ROOT->removeChild($_);
46 last;
47 }
48 return $content;
49 }
50  
51 1;
52  
53  
54  
55  
56 =head1 NAME
57  
58 b64_encoded_jpeg_renderer.pm - a renderer (HTML) for b64_encoded_jpeg type MOBY Objects
59  
60 =head1 AUTHOR
61  
62 Please report all bugs to Mark Wilkinson (markw at illuminae.com)
63  
64 =head1 SYNOPSIS
65  
66 just put the renderer in your gbrowse.conf/MobyServices folder
67 and it will work.
68  
69 =head1 DESCRIPTION
70  
71 This renderer returns HTML that fits between the
72 <td> tags in a web-page to display the content
73 of a b64_encoded_jpeg (or ontological child of) object.
74  
75 =head1 METHODS
76  
77 The module has two methods:
78  
79 =over
80  
81 =item type
82  
83 this returns a scalar indicating the MOBY Object
84 Class that this renderer is designed to handle. Objects
85 of this type, or objects that inherit from this type,
86 will be passed to this renderer.
87  
88 =item render
89  
90 This is called with three pieces of data which may or may not
91 be useful to your script:
92
93 =over
94  
95 =item 1) $data - an XML::DOM object
96 representing the deserialized MOBY object
97  
98  
99 =item 2) $htmldir - the full path to the directory serving your html
100  
101 e.g. /usr/local/apache/htdocs/
102
103 (this is the HTDOCS parameter you specified
104 when you installed Gbrowse)
105  
106 =item 3) $imgdir - the additional path information to a writable directory for images
107  
108 e.g. /gbrowse/tmp
109
110 (this is the folder specified in the tmpimages parameter
111 in your organism.conf file)
112  
113  
114 =back
115  
116 =back
117  
118 =head1 RETURNS
119  
120 The subroutine should return two pieces of data:
121  
122 =over
123  
124 =item 1) An HTML representation of the Object
125  
126 this will appear between <td></td> tags in the webpage
127  
128 =item 2) A boolean indicating whether the renderer has parsed all sub-objects, or just the top level object
129  
130 '1' indicates that the renderer has fully parsed the Object XML
131 '0' indicates that you need Gbrowse to follow child objects
132 and render them independently
133  
134 =back
135  
136 =cut