File Coverage

blib/lib/Webservice/InterMine/Simple/Template.pm
Criterion Covered Total %
statement 9 33 27.2
branch 0 2 0.0
condition 0 2 0.0
subroutine 3 8 37.5
pod 4 4 100.0
total 16 49 32.6


line stmt bran cond sub pod time code
1             package Webservice::InterMine::Simple::Template;
2              
3 1     1   9 use strict;
  1         3  
  1         63  
4 1     1   8 use URI;
  1         4  
  1         36  
5              
6 1     1   8 use constant 'RESOURCE_PATH' => '/template/results';
  1         2  
  1         896  
7              
8             =head1 NAME
9              
10             Webservice::InterMine::Simple::Template
11              
12             =head1 SYNOPSIS
13              
14             my $template = $service->template("Gene_Pathways");
15              
16             @rows = $query2->results_table(constraint1 => "eq", value1 => "ABC trans*");
17             for my $row (@rows) {
18             print @$row;
19             }
20              
21             =head1 DESCRIPTION
22              
23             This is a basic representation of a query. It can handle straight-forward
24             requests and result sets, but for anything more complicated, we recommend you look
25             as the more fully featured L. This is especially true of
26             large data sets, as this implementation has the potential to use lots of memory when
27             receiving and processing results.
28              
29             =head1 METHODS
30              
31             =head2 new(name => $name) - Construct a new template.
32              
33             Create an object representing the template with the given name.
34              
35             =cut
36              
37             sub new {
38 0     0 1   my $class = shift;
39 0           my $self = {@_};
40 0           return bless $self, $class;
41             }
42              
43             sub _get_uri {
44 0     0     my $self = shift;
45 0           my $uri = URI->new($self->{service}{root} . RESOURCE_PATH);
46 0           return $uri;
47             }
48              
49             =head2 results_with - get the results for this query as a single string.
50              
51             Returns the string representation of the template's results.
52              
53             Parameters:
54              
55             =over 4
56              
57             =item * %template_parameters
58              
59             Specification of the template parameters to use. These take the form:
60              
61             =over 8
62              
63             =item constraint? => $path
64              
65             =item op? => $op
66              
67             =item value? => $value
68              
69             =item extra? => $extra_value
70              
71             =back
72              
73             Where ? represents a number that is used to group properties for each template constraint.
74              
75             =item * as => $format
76              
77             Specifies the result format.
78              
79             =item * size => int
80              
81             Specifies the maximum number of rows to return.
82             A query can return up to 10,000,000 rows in a single page.
83              
84             =item * start => int
85              
86             Specifies the index of the first result to return.
87              
88             =item * columnheaders => bool
89              
90             Whether or not you want the first row to be the names
91             of the output columns.
92              
93             =back
94              
95             =cut
96              
97             sub results_with {
98 0     0 1   my $self = shift;
99 0           my %args = @_;
100 0           my $uri = $self->_get_uri;
101 0   0       my $format = delete $args{as} || 'tab';
102 0           my %query_form = (name => $self->{name}, format => $format, %args);
103 0           $uri->query_form(%query_form);
104 0           my $result = $self->{service}{ua}->get($uri);
105 0 0         if ($result->is_success) {
106 0           return $result->content;
107             } else {
108 0           die $result->status_line, $result->content;
109             }
110             }
111              
112             =head2 results_table - get a list of rows (as array-references)
113              
114             Performs very naïve parsing of returned tabular data and splits
115             rows into array references based using a failure-prone "tab" split.
116              
117             Takes the same arguments as results_with.
118              
119             =cut
120              
121             sub results_table {
122 0     0 1   my $self = shift;
123 0           my $results = $self->results_with(@_);
124 0           my @results = map {[ split /\t/ ]} split(/\n/, $results);
  0            
125 0           return @results;
126             }
127              
128             =head2 get_count - get the number of rows the query returns
129              
130             Returns a number representing the total number of rows in the result set.
131              
132             Takes the same arguments as results_with.
133              
134             =cut
135              
136             sub get_count {
137 0     0 1   my $self = shift;
138 0           my $results = $self->results_with(as => "count", @_);
139 0           return $results + 0;
140             }
141              
142             =head1 SEE ALSO
143              
144             =over 4
145              
146             =item * L For a more powerful alternative
147              
148             =back
149              
150             =head1 AUTHOR
151              
152             Alex Kalderimis C<< >>
153              
154             =head1 BUGS
155              
156             Please report any bugs or feature requests to C.
157              
158             =head1 SUPPORT
159              
160             You can find documentation for this module with the perldoc command.
161              
162             perldoc Webservice::InterMine
163              
164             You can also look for information at:
165              
166             =over 4
167              
168             =item * InterMine
169              
170             L
171              
172             =item * Documentation
173              
174             L
175              
176             =back
177              
178             =head1 COPYRIGHT AND LICENSE
179              
180             Copyright 2006 - 2011 FlyMine, all rights reserved.
181              
182             This program is free software; you can redistribute it and/or modify it
183             under the same terms as Perl itself.
184              
185             =cut
186              
187             1;