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