Phylo/PhyloWS/Resource.pm untested

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