[Bio] / FigKernelPackages / SAPserver.pm Repository:
ViewVC logotype

Annotation of /FigKernelPackages/SAPserver.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     #
4 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
5 :     # for Interpretations of Genomes. All Rights Reserved.
6 :     #
7 :     # This file is part of the SEED Toolkit.
8 :     #
9 :     # The SEED Toolkit is free software. You can redistribute
10 :     # it and/or modify it under the terms of the SEED Toolkit
11 :     # Public License.
12 :     #
13 :     # You should have received a copy of the SEED Toolkit Public License
14 :     # along with this program; if not write to the University of Chicago
15 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
16 :     # Genomes at veronika@thefig.info or download a copy from
17 :     # http://www.theseed.org/LICENSE.TXT.
18 :     #
19 :    
20 : parrello 1.4 #
21 :     # This is a SAS Component.
22 :     #
23 :    
24 : parrello 1.1 package SAPserver;
25 :    
26 :     use strict;
27 :     use LWP::UserAgent;
28 :     use YAML;
29 :    
30 :     =head1 Sapling Server Helper Object
31 :    
32 :     =head2 Introduction
33 :    
34 :     This module is used to call the sapling server, which is a general-purpose
35 :     server for extracting data from the Sapling database. Each Sapling server
36 :     function correspond to a method of this object.
37 :    
38 : parrello 1.2 This package deliberately uses no internal SEED packages or scripts, only common
39 :     PERL modules.
40 :    
41 : parrello 1.1 The fields in this object are as follows.
42 :    
43 :     =over 4
44 :    
45 :     =item server_url
46 :    
47 :     The URL used to request data from the sapling server.
48 :    
49 :     =item ua
50 :    
51 :     The user agent for communication with the server.
52 :    
53 :     =back
54 :    
55 :     =cut
56 :    
57 :     =head3 new
58 :    
59 :     my $ss = SAPserver->new(%options);
60 :    
61 :     Construct a new SAPserver object. The following options are supported.
62 :    
63 :     =over 4
64 :    
65 :     =item url
66 :    
67 :     URL for the sapling server. This option may be used to redirect requests to a
68 :     test version of the server, or to an older server script.
69 :    
70 :     =back
71 :    
72 :     =cut
73 :    
74 :     sub new {
75 :     # Get the parameters.
76 :     my ($class, %options) = @_;
77 :     # Get the options.
78 : parrello 1.4 my $url = $options{url} || "http://bio-macpro-1.mcs.anl.gov/~parrello/FIG/sap_server.cgi";
79 : parrello 1.1 # Create the fields of the object.
80 :     my $server_url = $url;
81 :     my $ua = LWP::UserAgent->new();
82 :     # Create the SAPserver object.
83 :     my $retVal = {
84 :     server_url => $server_url,
85 :     ua => $ua,
86 :     };
87 :     # Bless and return it.
88 :     bless $retVal, $class;
89 :     return $retVal;
90 :     }
91 :    
92 :     =head2 Public Methods
93 :    
94 :     =head3 AUTOLOAD
95 :    
96 :     my $result = $ss->method(%args);
97 :    
98 :     Call a function on the server. Any method call on this object (other than
99 :     the constructor) is translated into a request against the server. This
100 :     enables us to add new server functions without requiring an update to this
101 :     module. The parameters are specified as a hash, and the result is a scalar
102 : parrello 1.2 or object reference. If an error occurred, we will throw an exception.
103 : parrello 1.1
104 :     =cut
105 :    
106 :     # This variable will contain the method name.
107 :     our $AUTOLOAD;
108 :    
109 :     sub AUTOLOAD {
110 :     # Get the parameters.
111 :     my ($self, %args) = @_;
112 :     # Declare the return variable.
113 :     my $retVal;
114 :     # Get the method name.
115 :     my $function = $AUTOLOAD;
116 : parrello 1.3 # Strip off the stuff before the method name.
117 : parrello 1.1 $function =~ s/.+:://;
118 :     # Compute the argument document.
119 :     my $argString = YAML::Dump(\%args);
120 :     # Get our user agent.
121 :     my $ua = $self->{ua};
122 :     # Request the function from the server.
123 :     my $response = $ua->post($self->{server_url},
124 :     [function => $function, args => $argString]);
125 :     # Get the response content.
126 :     my $content = $response->content;
127 :     if (! $response->is_success) {
128 : parrello 1.2 die "Server error " . $response->status_line . "\n$content";
129 : parrello 1.1 } else {
130 :     $retVal = YAML::Load($content);
131 :     # Figure out what we got back.
132 :     my $returnType = ref $retVal;
133 :     if ($returnType && $returnType eq 'ErrorDocument') {
134 : parrello 1.2 die $retVal->{message};
135 : parrello 1.1 }
136 :     }
137 :     # Return the result.
138 :     return $retVal;
139 :     }
140 :    
141 :     =head3 DESTROY
142 :    
143 :     $ss->DESTROY();
144 :    
145 :     This method has no function. It's purpose is to keep the destructor from
146 :     being caught by the autoload processing.
147 :    
148 :     =cut
149 :    
150 :     sub DESTROY { }
151 :    
152 :    
153 : parrello 1.2 1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3