Phylo/PhyloWS/Resource.pm untested

filter: Statementstmt 0.0% 0 / 64 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 113 CC 9 SCAR 28.7
CC
9
Cov
0%
to_xml
42.0
new
20.0
is_identifiable
2.0
CRAP 17.6
1 package Bio::Phylo::PhyloWS::Resource;
2 use strict;
3 use warnings;
4 use base qw'Bio::Phylo::PhyloWS Bio::Phylo::NeXML::Writable';
5 use Bio::Phylo::Util::Exceptions 'throw';
6 use Bio::Phylo::Util::CONSTANT qw'_DESCRIPTION_ _RESOURCE_ /looks_like/';
7 use Bio::Phylo::Util::Logger;
8 {
9 my @fields;
10 my $logger = Bio::Phylo::Util::Logger->new;
11  
12 =head1 NAME
13  
14 Bio::Phylo::PhyloWS::Resource - Represents a PhyloWS web resource
15  
16 =head1 SYNOPSIS
17  
18 # no direct usage
19  
20 =head1 DESCRIPTION
21  
22 This class represents a resource on the web that implements the PhyloWS
23 recommendations.
24  
25 =head1 METHODS
26  
27 =head2 CONSTRUCTOR
28  
29 =over
30  
31 =item new()
32  
33 Type : Constructor
34 Title : new
35 Usage : my $phylows = Bio::Phylo::PhyloWS::Resource->new( -guid => $guid );
36 Function: Instantiates Bio::Phylo::PhyloWS::Resource object
37 Returns : a Bio::Phylo::PhyloWS::Resource object
38 Args : Required: -guid => $guid
39 Optional: any number of setters. For example,
40 Bio::Phylo::PhyloWS::Resource->new( -format => $format )
41 will call set_format( $format ) internally
42  
43 =cut
44  
45 sub new {
46 my $self = shift->SUPER::new( '-tag' => 'item', @_ );
47 if ( not $self->get_link ) {
48 my $has_guid_and_auth = $self->get_guid && $self->get_authority;
49 if ( not $has_guid_and_auth and not $self->get_query ) {
50 throw 'BadArgs' => 'Need -guid and -authority or -query argument';
51 }
52 if ( not $self->get_section ) {
53 throw 'BadArgs' => 'Need -section argument';
54 }
55 }
56 return $self;
57 }
58  
59 =back
60  
61 =head2 TESTS
62  
63 =over
64  
65 =item is_identifiable()
66  
67 Tests if invocant has an xml id attribute
68  
69 Type : Test
70 Title : is_identifiable
71 Usage : if ( $obj->is_identifiable ) {
72 # do something
73 }
74 Function: Tests if invocant has an xml id attribute
75 Returns : FALSE
76 Args : NONE
77  
78 =cut
79  
80 sub is_identifiable { 0 }
81  
82 =back
83  
84 =head2 SERIALIZERS
85  
86 =over
87  
88 =item to_xml()
89  
90 Serializes resource to RSS1.0 XML representation
91  
92 Type : Serializer
93 Title : to_xml()
94 Usage : print $obj->to_xml();
95 Function: Serializes object to RSS1.0 XML string
96 Returns : String
97 Args : None
98 Comments:
99  
100 =cut
101  
102 # <item rdf:about="${baseURL}/${phyloWSPath}?format=nexus">
103 # <title>Nexus file</title>
104 # <link>${baseURL}/${phyloWSPath}?format=nexus</link>
105 # <description>A Nexus serialization of the resource</description>
106 # <dc:format>text/plain</dc:format>
107 # </item>
108 sub to_xml {
109 my $self = shift;
110 my $tag = $self->get_tag;
111
112 # create the link URL
113 my $link;
114 if ( $link = $self->get_link ) {
115 $logger->info("Using link field: $link");
116 }
117 else {
118 $link = $self->get_url;
119 $logger->info("Computed URL: $link");
120 }
121
122 # generating default elements
123 my $xml = '<' . $tag . ' rdf:about="' . $link . '">';
124 $xml .= '<title>' . $self->get_name . '</title>';
125 $xml .= '<link>' . $link . '</link>';
126 $xml .= '<description>' . $self->get_desc . '</description>';
127
128 # specify output format
129 if ( my $format = $self->get_format ) {
130 $xml .= '<dc:format>' . $Bio::Phylo::PhyloWS::MIMETYPE{$format} . '</dc:format>';
131 }
132
133 # serialize additional annotations
134 for my $meta ( @{ $self->get_meta } ) {
135 my $predicate = $meta->get_predicate;
136 my $object = $meta->get_object;
137 if ( $object =~ /http:/ or $object =~ /urn:/ ) {
138 $xml .= "<$predicate rdf:resource=\"$object\"/>";
139 }
140 elsif ( ref $object ) {
141 my @methods = qw(to_xml toString sprint _as_string code xmlify as_xml dump_tree as_XML);
142 SERIALIZER: for my $method (@methods) {
143 if ( looks_like_implementor( $object, $method ) ) {
144 $xml .= "<$predicate>";
145 $xml .= $object->$method;
146 $xml .= "</$predicate>";
147 last SERIALIZER;
148 }
149 }
150 }
151 else {
152 $xml .= "<$predicate>$object</$predicate>";
153 }
154 }
155
156 # done!
157 $xml .= '</' . $tag . '>';
158 return $xml;
159 }
160
161 sub _container { _DESCRIPTION_ }
162 sub _type { _RESOURCE_ }
163  
164 sub _cleanup {
165 my $self = shift;
166 my $id = $self->get_id;
167 delete $_->{$id} for @fields;
168 }
169  
170 =back
171  
172 =cut
173  
174 # podinherit_insert_token
175  
176 =head1 SEE ALSO
177  
178 There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo>
179 for any user or developer questions and discussions.
180  
181 Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>
182  
183 =head1 CITATION
184  
185 If you use Bio::Phylo in published research, please cite it:
186  
187 B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
188 and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
189 I<BMC Bioinformatics> B<12>:63.
190 L<http://dx.doi.org/10.1186/1471-2105-12-63>
191  
192 =cut
193  
194 }
195 1;