[Bio] / FigWebServices / SearchSkeleton.cgi Repository:
ViewVC logotype

Annotation of /FigWebServices/SearchSkeleton.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.17 - (view) (download)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     BEGIN {
4 :     # Print the HTML header.
5 :     print "CONTENT-TYPE: text/html\n\n";
6 :     }
7 :    
8 : parrello 1.10 use strict;
9 :     use Tracer;
10 :     use CGI;
11 :     use Sprout;
12 :     use SearchHelper;
13 :     use POSIX qw(ceil);
14 :     use File::stat;
15 :    
16 :     # Add USE statements for new search helpers below.
17 :     use SHFidSearch;
18 :     use SHBlastSearch;
19 :     use SHSigGenes;
20 :     use SHWordSearch;
21 :     use SHPropSearch;
22 :     use SHDrugSearch;
23 : parrello 1.12 use SHSubSearch;
24 : parrello 1.10
25 : parrello 1.1 =head1 NMPDR Search Skeleton
26 :    
27 :     This script executes a search and displays the results. If, on entry,
28 :     it sees a session ID, then it will assume search results have been
29 :     cached and the cached results are to be displayed. Otherwise, it
30 :     will perform the search, cache the results, and display the first
31 :     page. The search itself is performed by an object that subclasses
32 :     B<SearchHelper>. To allow for additional search types, you need
33 :     merely implement a new subclass of B<SearchHelper> and add it
34 :     to the C<use> list below. By convention, all search helper
35 :     subclasses begin with the letters C<SH>. This is not consistent
36 :     with normal PERL practice, but it fits better into the way we
37 :     do builds.
38 :    
39 :     =head2 Session Data
40 :    
41 :     The following parameters are expected from the CGI query object.
42 :     Additional parameters may be required by whichever B<SearchHelper>
43 :     subclass is selected. By convention, the parameters required by
44 :     the subclasses will be lower-case and the parameters used by this
45 :     script are capital-case. Note that some parameters are only required
46 :     by old sessions, that is, sessions which are established with
47 :     existing search result cache files.
48 :    
49 :     =over 4
50 :    
51 :     =item Trace
52 :    
53 :     Trace level and list of trace modules to turn on, space-delimited.
54 :    
55 :     =item NoForm
56 :    
57 :     If specified, then no search form will be generated.
58 :    
59 :     =item SessionID
60 :    
61 :     Unique session ID for this user. This is used to generate the name of the user's
62 :     cache file in the temporary directory. The actual filename will be
63 :     C<tmp_>I<SessionID>C<.cache>.
64 :    
65 :     =item Page (old only)
66 :    
67 :     Number of the current page to display.
68 :    
69 :     =item PageSize
70 :    
71 :     Number of items per page.
72 :    
73 :     =item ResultCount (old only)
74 :    
75 :     Total number of search result lines.
76 :    
77 :     =item Class
78 :    
79 :     Name of the B<SearchHelper> subclass for this type of search. The name does not include
80 :     the C<SH> prefix. So, to specify a B<SHFidSearch> type of
81 :     search, you would specify a class of C<FidSearch>. If this parameter is omitted,
82 :     then all of the advanced search forms will be displayed.
83 :    
84 : parrello 1.3 =item ShowURL
85 :    
86 :     If specified, then a URL for repeating the search will be shown as a hyperlink on the
87 :     results page.
88 :    
89 :     =item ShowAliases
90 :    
91 :     If specified, then hyperlinked aliases will be shown for each feature.
92 :    
93 : parrello 1.12 =item Alternate
94 :    
95 :     If specified, then a list of advanced search forms will be shown.
96 :    
97 : parrello 1.1 =back
98 :    
99 :     =head2 The Cache File
100 :    
101 :     The cache file is a tab-delimited file. The first line of the file contains the
102 :     column names and the remaining lines contain the data for each result item.
103 :    
104 :     The column contents may contain HTML tags, including hyperlinks and buttons. For best
105 :     results, all links should be relative.
106 :    
107 : parrello 1.3 Some columns will consist of a doubled percent sign followed by a name, an equal sign,
108 :     and some text. This tells the display code to call the B<RunTimeColumns> method of
109 :     the B<SearchHelper> object to compute the column value. This facility is designed for
110 :     columns that require a lot of time to calculate, so we don't want to calculate them
111 :     until we absolutely have to display them.
112 :    
113 : parrello 1.1 It is presumed that the cache file is small, containing no more than a few thousand
114 :     lines of data. If this is not the case, an entirely different strategy will be
115 :     needed for displaying search results.
116 :    
117 :     If the cache file is empty or has only a single line, a stock "No Search Results"
118 :     message will be displayed.
119 :    
120 :     =cut
121 :    
122 :    
123 :     my ($cgi, $varHash) = ScriptSetup();
124 :     eval {
125 :     # Get the search class.
126 :     my $class = $cgi->param("Class");
127 : parrello 1.11 # Check for advanced mode.
128 :     if ($cgi->param("Alternate")) {
129 : parrello 1.12 Trace("Advanced mode selected.") if T(3);
130 :     # In advanced mode, we list all the search forms listed in
131 :     # $FIG_Config::advanced_class.
132 :     my @classes = split(/\s+/, $FIG_Config::advanced_class);
133 :     # Set the page size to the default.
134 :     $cgi->param(-name => 'PageSize', -value => $FIG_Config::results_per_page);
135 :     # Tell the template we have no search results and no class.
136 :     $varHash->{result_count} = 0;
137 :     $varHash->{class} = "";
138 : parrello 1.13 # Loop through the classes, creating the table of contents and
139 :     # the forms.
140 :     $varHash->{formIndex} = $cgi->h3("Contents") . $cgi->start_ul();
141 : parrello 1.12 for my $className (@classes) {
142 :     my $shelp = GetHelper($cgi, $className);
143 : parrello 1.13 # Produce the contents entry.
144 :     $varHash->{formIndex} .= $cgi->li($cgi->a({href => "#X$className"}, $className) .
145 :     ": " . $shelp->Description());
146 :     # Produce the bookmark.
147 :     $varHash->{form} .= $cgi->a({ name => "X$className" });
148 : parrello 1.12 # Produce the form.
149 :     $varHash->{form} .= $shelp->Form();
150 :     # Produce the help text.
151 :     $varHash->{form} .= $shelp->GetHelpText();
152 :     # Put some space between us and whatever comes next.
153 :     $varHash->{form} .= "<p>&nbsp;</p>";
154 :     }
155 : parrello 1.13 # Close the table of contents.
156 :     $varHash->{formIndex} .= $cgi->end_ul();
157 : parrello 1.12 } elsif (! $class) {
158 : parrello 1.2 Trace("Producing index of search tools.") if T(3);
159 :     # No class specified, so we simply generate an index of the
160 :     # searches. First, make sure the template knows there are no search results.
161 : parrello 1.1 $varHash->{result_count} = 0;
162 : parrello 1.2 Trace("Building URL.") if T(3);
163 :     # Get a copy of our URL. Note we include the query fields so that any
164 :     # tracing parameters are preserved.
165 :     my $selfURL = $cgi->url(-relative => 1, -query => 1);
166 : parrello 1.4 # Append a question mark or semicolon to the URL, depending on whether or not
167 : parrello 1.2 # there's already a question mark present.
168 : parrello 1.4 $selfURL .= ($selfURL =~ /\?/ ? ';' : '?');
169 : parrello 1.2 # Loop through the search classes building a table of contents.
170 : parrello 1.1 my @contents = ();
171 : parrello 1.5 for my $className (SearchHelper::AdvancedClassList()) {
172 : parrello 1.2 Trace("Processing $className") if T(3);
173 : parrello 1.1 my $shelp = GetHelper($cgi, $className);
174 : parrello 1.2 push @contents, "<a href=\"${selfURL}Class=$className\">$className</a>: " . $shelp->Description();
175 : parrello 1.1 }
176 :     # Create the table of contents.
177 : parrello 1.2 Trace("Building index.") if T(3);
178 :     my $index = $cgi->h3("Index of Search Tools") .
179 : parrello 1.1 $cgi->ul($cgi->li(\@contents));
180 : parrello 1.11 # Store it as the results.
181 :     $varHash->{results} = $index;
182 : parrello 1.2 # Tell the template we don't have a class.
183 :     $varHash->{class} = "";
184 :     Trace("Index built.") if T(3);
185 : parrello 1.1 } else {
186 : parrello 1.2 Trace("Class $class detected.") if T(3);
187 : parrello 1.1 # Here we have a class, so we're working with a single type of search.
188 :     my $shelp = GetHelper($cgi, $class);
189 : parrello 1.2 # Tell the template what the class is.
190 :     $varHash->{class} = $class;
191 : parrello 1.3 # Insure we have a page size.
192 :     if (! $cgi->param("PageSize")) {
193 :     $cgi->param(-name => 'PageSize', -value => $FIG_Config::results_per_page);
194 :     }
195 : parrello 1.14 # Display the form, if desired. This absolutely must happen before we do the ShowURL
196 :     # thing below. The form can actually appear after the results, however, thanks to the
197 :     # template.
198 : parrello 1.3 my $formShown = ! $cgi->param("NoForm");
199 :     if ($formShown) {
200 : parrello 1.9 Trace("Displaying form.") if T(3);
201 : parrello 1.1 $varHash->{form} = $shelp->Form();
202 :     }
203 : parrello 1.3 # Declare the result count variable.
204 :     my $result_count = 0;
205 : parrello 1.1 # Now there are three different directions we can go. If a
206 :     # "Search" button has been pressed, then we need to perform a
207 :     # search. If this is a new session and the button has not
208 :     # been pressed, we do nothing. If this is an old session
209 :     # and the button has not been pressed, we display results. Note
210 :     # that we allow for regular buttons (Search) or image buttons
211 :     # (Search.x).
212 : parrello 1.17 if (!$cgi->param("Search") && !$cgi->param("Search.x")) {
213 : parrello 1.16 # No button, so check for results. Note we only do this if this is not
214 :     # a new session. A new session won't have results.
215 : parrello 1.1 Trace("No search requested.") if T(3);
216 :     if (! $shelp->IsNew()) {
217 :     $varHash->{results} = DisplayResults($shelp, $cgi);
218 :     }
219 :     } else {
220 :     # Here we have a button press, so we need to find stuff and
221 : parrello 1.16 # then display it.
222 : parrello 1.1 Trace("Performing the search.") if T(3);
223 : parrello 1.3 # Clear the result area.
224 :     $varHash->{results} = "";
225 : parrello 1.16 # Now we process the showURL thing. Note that we only
226 : parrello 1.4 # do it if the form was shown. If the form was not shown, the
227 :     # code for computing the URL won't work.
228 : parrello 1.16 if ($formShown) {
229 : parrello 1.3 my $searchURL = $shelp->ComputeSearchURL();
230 :     $varHash->{results} .= $cgi->p("<a href=\"$searchURL\">Right-click to save a URL for this search</a>");
231 :     }
232 : parrello 1.4 # Perform the search.
233 : parrello 1.15 Trace("Calling FIND method.") if T(3);
234 : parrello 1.3 $result_count = $shelp->Find();
235 : parrello 1.15 Trace("Processing results.") if T(3);
236 : parrello 1.1 # Check to see what kind of results we got.
237 : parrello 1.2 if (! defined($result_count)) {
238 : parrello 1.1 # Here an error occurred, so we display the error message.
239 : parrello 1.3 $varHash->{results} .= $cgi->h3("ERROR: " . $shelp->Message());
240 :     $result_count = 0;
241 : parrello 1.1 } elsif ($result_count == 0) {
242 :     # Here nothing matched.
243 : parrello 1.3 $varHash->{results} .= $cgi->h3("No match found.");
244 : parrello 1.1 } else {
245 :     # Here we have results. Save the result count and set up to display
246 :     # the first page of results.
247 :     $cgi->param(-name => "ResultCount", -value => $result_count);
248 :     $cgi->param(-name => "Page", -value => 1);
249 :     # Start with a message about how many matches we found.
250 :     my $countText = ($result_count == 1 ? "One match" : "$result_count matches");
251 : parrello 1.3 $varHash->{results} .= $cgi->h3("$countText found.");
252 : parrello 1.1 # Append the page display.
253 :     $varHash->{results} .= DisplayResults($shelp, $cgi);
254 :     }
255 :     }
256 :     # Save the result count so that the results helper text appears if it
257 :     # is needed. This text is in the template, but it's protected by a TMPL_IF
258 :     # on "result_count".
259 : parrello 1.3 $varHash->{result_count} = $result_count;
260 :     # If there are no results and the form was shown, add the help text. We are
261 :     # assuming that if the user got the search to work, he doesn't need help.
262 :     # In addition, if the form was not shown, a description of how to use it
263 :     # makes no sense.
264 :     if (! $result_count && $formShown) {
265 :     $varHash->{helptext} = $shelp->GetHelpText();
266 :     }
267 : parrello 1.1 }
268 :     };
269 :     if ($@) {
270 :     my $errorMessage = $@;
271 :     Trace("Script Error: $errorMessage") if T(0);
272 :     $varHash->{results} = $cgi->h3("Script Error: $errorMessage");
273 :     }
274 :     ScriptFinish("SproutSearch_tmpl.php", $varHash);
275 :    
276 :     =head3 DisplayResults
277 :    
278 :     C<< my $htmlText = DisplayResults($shelp, $cgi); >>
279 :    
280 :     Display the results of a search. A page of results will be displayed, along with links to get to
281 :     other pages. The HTML for the results display is returned.
282 :    
283 :     =over 4
284 :    
285 :     =item shelp
286 :    
287 :     Search helper object representing the search. The column headers and search rows will be
288 :     stored in the session file attached to it.
289 :    
290 :     =item cgi
291 :    
292 :     CGI query object for the current session. This includes the page number, size, and result
293 :     counts.
294 :    
295 :     =item RETURN
296 :    
297 :     Returns the HTML text for displaying the current page of search results.
298 :    
299 :     =back
300 :    
301 :     =cut
302 :    
303 :     sub DisplayResults {
304 :     # Get the parameters.
305 :     my ($shelp, $cgi) = @_;
306 :     # Declare the return variable.
307 :     my $retVal;
308 :     # Extract the result parameters.
309 :     my ($pageSize, $pageNum, $resultCount) = ($cgi->param('PageSize'),
310 :     $cgi->param('Page'),
311 :     $cgi->param('ResultCount'));
312 :     # Only proceed if there are actual results.
313 :     if ($resultCount <= 0) {
314 :     $retVal = $cgi->h3("No matches found.");
315 :     } else {
316 :     # Check the state of the session file.
317 :     my $fileName = $shelp->GetCacheFileName();
318 :     if (! -e $fileName) {
319 :     $retVal = $cgi->h3("Search session has expired. Please resubmit your query.");
320 :     } else {
321 :     # The file is here, so we can open it.
322 :     my $sessionH = Open(undef, "<$fileName");
323 : parrello 1.6 if (T(3)) {
324 :     my $fileData = stat($sessionH);
325 :     Trace($fileData->size . " bytes in $fileName.");
326 :     }
327 : parrello 1.1 # Read the column headers.
328 :     my @colHdrs = Tracer::GetLine($sessionH);
329 :     # Compute the page navigation string.
330 : parrello 1.14 my $formFlag = ($cgi->param('NoForm') ? 0 : 1);
331 :     my $pageNavigator = PageNavigator($shelp, $formFlag);
332 : parrello 1.1 # Now we need to find our page. The line number we compute will be
333 :     # zero-based. We'll read from the session file until it drops to zero.
334 :     # This may push us past end-of-file, but it won't cause an exception, and
335 :     # it's something that should only happen very rarely in any case.
336 : parrello 1.4 my $linesToSkip = ($pageNum - 1) * $pageSize;
337 :     Trace("Skipping $linesToSkip lines in session file $fileName.") if T(3);
338 :     for (my $lines = $linesToSkip; $lines > 0; $lines--) {
339 : parrello 1.1 Tracer::GetLine($sessionH);
340 :     }
341 :     # The session file is now positioned at the beginning of our line.
342 :     # We build the table rows one line at a time until we run out of data
343 :     # or exceed the page size.
344 :     my @tableRows = ();
345 :     my $linesLeft = $pageSize;
346 : parrello 1.5 Trace("$linesLeft lines to read from session file.") if T(3);
347 :     while ($linesLeft-- > 0) {
348 :     Trace("Reading line from session file.") if T(3);
349 :     my @cols = Tracer::GetLine($sessionH);
350 :     if (! @cols) {
351 :     Trace("End of file read.") if T(3);
352 :     $linesLeft = 0;
353 :     } else {
354 :     Trace("Line has " . scalar(@cols) . " columns. $linesLeft lines left.") if T(3);
355 :     # Check the columns for run-time generation.
356 :     my @actual = map { substr($_,0,2) eq "%%" ? $shelp->GetRunTimeValue($_) : $_ } @cols;
357 :     # Put the actual data into the table list.
358 :     push @tableRows, \@actual;
359 :     }
360 : parrello 1.1 }
361 :     # Now we're ready. We do a page navigator, a spacer, the table, a spacer,
362 :     # and another page navigator.
363 :     $retVal = join("\n", $pageNavigator,
364 :     $cgi->p("&nbsp;"),
365 : parrello 1.10 $cgi->h3("Search Results Page $pageNum"),
366 :     PageBuilder::MakeFancyTable($cgi, \@colHdrs, \@tableRows),
367 : parrello 1.1 $cgi->p("&nbsp;"),
368 :     $pageNavigator,
369 :     "");
370 :     }
371 :     }
372 :     # Return the result.
373 :     return $retVal;
374 :     }
375 :    
376 :     =head3 PageNavigator
377 :    
378 : parrello 1.14 C<< my $htmlText = PageNavigator($shelp, $formFlag); >>
379 : parrello 1.1
380 :     Return a page navigation string for the specified query.
381 :    
382 :     =over 4
383 :    
384 : parrello 1.14 =item shelp
385 :    
386 :     Search helper object for the current session.
387 :    
388 :     =item formFlag
389 :    
390 :     TRUE if a form has been displayed, else FALSE.
391 :    
392 :     =item RETURN
393 : parrello 1.1
394 : parrello 1.14 Returns a page navigation string for the specified search operation. If a form
395 :     has been displayed, the navigation elements will include the complete form
396 :     information; otherwise they will only include position and status.
397 : parrello 1.1
398 :     =back
399 :    
400 :     =cut
401 :    
402 :     sub PageNavigator {
403 :     # Get the parameters.
404 : parrello 1.14 my ($shelp, $formFlag) = @_;
405 :     # Get the CGI query object.
406 :     my $cgi = $shelp->Q();
407 : parrello 1.1 # Extract the result parameters.
408 :     my ($pageSize, $pageNum, $resultCount) = ($cgi->param('PageSize'),
409 :     $cgi->param('Page'),
410 :     $cgi->param('ResultCount'));
411 : parrello 1.4 # Declare the return variable.
412 :     my $retVal = "";
413 : parrello 1.1 # Compute the number of the last page.
414 :     my $lastPage = ceil($resultCount / $pageSize);
415 : parrello 1.4 # Only proceed if there's more than one page.
416 :     if ($lastPage > 1) {
417 :     # Create a URL without a page number. All the other URLs will be generated
418 :     # from this one by appending the new page number.
419 : parrello 1.14 my $url;
420 :     if ($formFlag) {
421 :     $url = $shelp->ComputeSearchURL(PageSize => $pageSize, ResultCount => $resultCount,
422 :     Search => undef, 'Search.x' => undef,
423 :     'Search.y' => undef, SessionID => $shelp->ID());
424 :     } else {
425 :     $url = StatusURL($cgi, Page => undef);
426 :     }
427 : parrello 1.4 # Now compute the start and end pages for the display. We display ten pages,
428 :     # with the current one more or less centered.
429 :     my $startPage = $pageNum - 4;
430 :     if ($startPage < 1) { $startPage = 1; }
431 :     my $endPage = $startPage + 9;
432 :     if ($endPage > $lastPage) { $endPage = $lastPage; }
433 :     # Create a list of URL/page-number combinations.
434 :     my @pageThings = ();
435 :     for (my $linkPage = $startPage; $linkPage <= $endPage; $linkPage++) {
436 :     # Check for the current page. It gets a page number with no link.
437 :     if ($linkPage == $pageNum) {
438 :     push @pageThings, $linkPage;
439 :     } else {
440 :     # This is not the current page, so it gets the full treatment.
441 :     push @pageThings, PageThing($cgi, $linkPage, $linkPage, $url);
442 :     }
443 : parrello 1.1 }
444 : parrello 1.4 # Now add some jump links at the end.
445 :     my @forePointers = ();
446 :     if ($endPage < $lastPage) {
447 :     for (my $pg = $endPage + 5; $pg < $lastPage; $pg += 15) {
448 :     push @forePointers, PageThing($cgi, $pg, $pg, $url);
449 :     }
450 :     push @forePointers, PageThing($cgi, ">>", $lastPage, $url);
451 : parrello 1.3 }
452 : parrello 1.4 # Finally, add some jump links at the front.
453 :     my @backPointers = ();
454 :     if ($startPage > 1) {
455 :     for (my $pg = $startPage - 5; $pg > 1; $pg -= 15) {
456 : parrello 1.6 unshift @backPointers, PageThing($cgi, $pg, $pg, $url);
457 : parrello 1.4 }
458 : parrello 1.6 unshift @backPointers, PageThing($cgi, "<<", 1, $url);
459 : parrello 1.3 }
460 : parrello 1.4 # Put it all together.
461 :     my $middle = join(" ", @pageThings);
462 :     $retVal = join " ... ", @backPointers, $middle, @forePointers;
463 : parrello 1.3 }
464 : parrello 1.1 # Return the result.
465 :     return $retVal;
466 :     }
467 :    
468 :     =head3 PageThing
469 :    
470 :     C<< my $htmlText = PageThing($cgi, $pageLabel, $pageNumber, $url); >>
471 :    
472 :     Create an entry for the page navigator. The entry consists of a label that
473 :     is hyperlinked to the specified page number of the search results.
474 :    
475 :     =over 4
476 :    
477 :     =item cgi
478 :    
479 :     CGI object, used to access the CGI HTML-building methods.
480 :    
481 :     =item pageLabel
482 :    
483 :     Text to be hyperlinked. This is usually the page number, but sometimes it will be
484 :     arrows.
485 :    
486 :     =item pageNumber
487 :    
488 :     Number of the page to be presented when the link is followed.
489 :    
490 :     =item url
491 :    
492 :     Base URL for viewing a page.
493 :    
494 :     =item RETURN
495 :    
496 :     Returns HTML for the specified label, hyperlinked to the desired page.
497 :    
498 :     =back
499 :    
500 :     =cut
501 :    
502 :     sub PageThing {
503 :     # Get the parameters.
504 :     my ($cgi, $pageLabel, $pageNumber, $url) = @_;
505 :     # Compute the full URL.
506 :     my $purl = "$url&Page=$pageNumber";
507 :     # Form it into a hyperlink.
508 :     my $retVal = "<a href=\"$purl\" title=\"Results page $pageNumber\">$pageLabel</a>";
509 :     # Return the result.
510 :     return $retVal;
511 :     }
512 :    
513 :     =head3 StatusURL
514 :    
515 :     C<< my $queryUrl = StatusURL($cgi, %overrides); >>
516 :    
517 :     Create a URL for the current script containing status information for the search in progress.
518 :     The values in the incoming CGI object will be used for all parameters except the ones
519 :     specified as overrides. So, for example
520 :    
521 :     StatusURL($cgi, PageNum => 3)
522 :    
523 :     would specify a page number of 3, but all the other parameters will be taken as is from
524 :     the CGI object. The complete list of session variables is given in the L</Session Data>
525 :     section.
526 :    
527 :     =over 4
528 :    
529 :     =item cgi
530 :    
531 :     CGI query object containing the session variables.
532 :    
533 :     =item overrides
534 :    
535 :     A hash mapping key names to override values. These are used to override values in the
536 :     I<$cgi> parameter.
537 :    
538 :     =item RETURN
539 :    
540 :     Returns a relative URL for the current page with GET-style values for all the session
541 :     variables.
542 :    
543 :     =back
544 :    
545 :     =cut
546 :    
547 :     sub StatusURL {
548 :     # Get the parameters.
549 :     my ($cgi, %overrides) = @_;
550 :     # Create a hash of the session variables we want to keep.
551 :     my %varHash;
552 :     for my $varKey (qw(SessionID Trace NoForm ResultCount Page PageSize Class SPROUT)) {
553 :     # Check for an override.
554 :     if (exists $overrides{$varKey}) {
555 :     my $override = $overrides{$varKey};
556 :     # Use the override if it is not null or undefined.
557 :     if (defined($override) && $override ne "") {
558 :     $varHash{$varKey} = $override;
559 :     }
560 :     } else {
561 :     # Check for a CGI value.
562 :     my $normal = $cgi->param($varKey);
563 :     # Use it if it exists.
564 :     if (defined($normal)) {
565 :     $varHash{$varKey} = $normal;
566 :     }
567 :     }
568 :     }
569 :     # Compute the full URL.
570 :     my $retVal = Tracer::GenerateURL($cgi->url(-relative => 1), %varHash);
571 :     # Return the result.
572 :     return $retVal;
573 :     }
574 :    
575 :     =head3 GetHelper
576 :    
577 :     C<< my $shelp = GetHelper($className); >>
578 :    
579 :     Return a helper object with the given class name. If no such class exists, an
580 :     error will be thrown.
581 :    
582 :     =over 4
583 :    
584 :     =item cgi
585 :    
586 :     Active CGI query object.
587 :    
588 :     =item className
589 :    
590 :     Class name for the search helper object, without the preceding C<SH>. This is
591 :     identical to what the script expects for the C<Class> parameter.
592 :    
593 :     =item RETURN
594 :    
595 :     Returns a search helper object for the specified class.
596 :    
597 :     =back
598 :    
599 :     =cut
600 :    
601 :     sub GetHelper {
602 :     # Get the parameters.
603 :     my ($cgi, $className) = @_;
604 :     # Try to create the search helper.
605 :     my $retVal = eval("SH$className->new(\$cgi)");
606 :     if (! defined $retVal) {
607 :     Confess("Could not find a search handler of type $className.");
608 :     }
609 :     # Return the result.
610 :     return $retVal;
611 :     }
612 :    
613 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3