| 1 | package Bio::PrimerDesigner::Remote; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # $Id: Remote.pm 9 2008-11-06 22:48:20Z kyclark $ | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | Bio::PrimerDesigner::Remote - A class for remote access to Bio::PrimerDesigner | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | use Bio::PrimerDesigner::Remote; | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | Interface to the server-side binaries. Passes the primer design | ||||||||||||||||||||||||||||||||||||||||||
| 16 | paramaters to a remote CGI, which uses a server-side installation of | ||||||||||||||||||||||||||||||||||||||||||
| 17 | Bio::PrimerDesigner to process the request. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 7 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 7 | Readonly our | |||||||||||||||||||||||||||||||||||||||||
| 30 | $VERSION => sprintf "%s", q$Revision: 24 $ =~ /(\d+)/; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | ▶ | use base 'Class::Base'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | ▶ | sub CGI_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CGI_request: called CC=8 SCAR=31.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =head2 CGI_request | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | Passes arguments to the URL of the remote Bio::PrimerDesigner CGI and | ||||||||||||||||||||||||||||||||||||||||||
| 42 | returns the raw output for further processing by local design classes. | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | ▶ | my $url = shift or return $self->error('No URL specified'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | $url = 'http://' . $url unless $url =~ m{https?://}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | my $args = shift or return $self->error('No config file'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | my $program = $args->{'program'}; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # Is the remote server able to process our request? | ||||||||||||||||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | unless ( $self->check( $url, $ua, $program ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | return $self->error("$url did not return expected result"); | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $request = HTTP::Request->new('POST', $url); | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # string-ify the config hash to pass to the CGI | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my @content = (); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | @content = map {"$_=" . $args->{$_}} keys %$args; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my $content = join "#", @content; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $request->content( "config=$content" ); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $response = $ua->request( $request ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $output = $response->content; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return $self->error("Some sort of HTTP error") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$ua and $request and $response
$ua and $request
MC/DC0%0/3
$ua and $request and $response
$ua
$request
$response
Truth table0%0/4
A and B and C
A= $uaB= $requestC= $response
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | unless $ua && $request && $response; | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return map { $_ . "\n" } split "\n", $output; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | =head2 check | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | Tests the URL to make sure the host is live and the CGI returns the | ||||||||||||||||||||||||||||||||||||||||||
| 88 | expected results. | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | my ($url, $ua, $program) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | my $content = "check=" . $program; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | my $request = HTTP::Request->new( 'POST', $url ); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | $request->content( $content ); | |||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | my $response = $ua->request( $request ); | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | ▶ | return $self->error("No reponse from host $url") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | unless $response; | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | my $output = $response->content; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | return $self->error("Incorrect response from host $url") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | unless $output =~ /$program OK/m; | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | Copyright (C) 2003-2009 Sheldon McKay E<lt>mckays@cshl.eduE<gt>, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>. | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 125 | it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||||||||||||||||
| 126 | the Free Software Foundation; version 3 or any later version. | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | This program is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||||||||||||||||
| 129 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||
| 130 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||||||||||||||||||||||||||||||||||||||||
| 131 | General Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||
| 134 | along with this program; if not, write to the Free Software | ||||||||||||||||||||||||||||||||||||||||||
| 135 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | ||||||||||||||||||||||||||||||||||||||||||
| 136 | USA. | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | Bio::PrimerDesigner, primer_designer.cgi. | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||||||||||||||||||||||||