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

Annotation of /FigWebServices/SearchSkeleton.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (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 :     if (!$cgi->param("Search") && !$cgi->param("Search.x")) {
213 :     # No button, so check for results. If this is a new session, we do
214 :     # nothing. The form is displayed and nothing else need be done.
215 : parrello 1.7 # Otherwise, we go into display-results mode.
216 : parrello 1.1 Trace("No search requested.") if T(3);
217 :     if (! $shelp->IsNew()) {
218 :     $varHash->{results} = DisplayResults($shelp, $cgi);
219 :     }
220 :     } else {
221 :     # Here we have a button press, so we need to find stuff and
222 : parrello 1.3 # then display it..
223 : parrello 1.1 Trace("Performing the search.") if T(3);
224 : parrello 1.3 # Clear the result area.
225 :     $varHash->{results} = "";
226 :     # Now we process the showURL thing. If showURL is checked, then
227 : parrello 1.4 # we will display a hyperlink to this search. Note that we only
228 :     # do it if the form was shown. If the form was not shown, the
229 :     # code for computing the URL won't work.
230 :     if ($cgi->param('ShowURL') && $formShown) {
231 : parrello 1.3 my $searchURL = $shelp->ComputeSearchURL();
232 :     $varHash->{results} .= $cgi->p("<a href=\"$searchURL\">Right-click to save a URL for this search</a>");
233 :     }
234 : parrello 1.4 # Perform the search.
235 : parrello 1.15 Trace("Calling FIND method.") if T(3);
236 : parrello 1.3 $result_count = $shelp->Find();
237 : parrello 1.15 Trace("Processing results.") if T(3);
238 : parrello 1.1 # Check to see what kind of results we got.
239 : parrello 1.2 if (! defined($result_count)) {
240 : parrello 1.1 # Here an error occurred, so we display the error message.
241 : parrello 1.3 $varHash->{results} .= $cgi->h3("ERROR: " . $shelp->Message());
242 :     $result_count = 0;
243 : parrello 1.1 } elsif ($result_count == 0) {
244 :     # Here nothing matched.
245 : parrello 1.3 $varHash->{results} .= $cgi->h3("No match found.");
246 : parrello 1.1 } else {
247 :     # Here we have results. Save the result count and set up to display
248 :     # the first page of results.
249 :     $cgi->param(-name => "ResultCount", -value => $result_count);
250 :     $cgi->param(-name => "Page", -value => 1);
251 :     # Start with a message about how many matches we found.
252 :     my $countText = ($result_count == 1 ? "One match" : "$result_count matches");
253 : parrello 1.3 $varHash->{results} .= $cgi->h3("$countText found.");
254 : parrello 1.1 # Append the page display.
255 :     $varHash->{results} .= DisplayResults($shelp, $cgi);
256 :     }
257 :     }
258 :     # Save the result count so that the results helper text appears if it
259 :     # is needed. This text is in the template, but it's protected by a TMPL_IF
260 :     # on "result_count".
261 : parrello 1.3 $varHash->{result_count} = $result_count;
262 :     # If there are no results and the form was shown, add the help text. We are
263 :     # assuming that if the user got the search to work, he doesn't need help.
264 :     # In addition, if the form was not shown, a description of how to use it
265 :     # makes no sense.
266 :     if (! $result_count && $formShown) {
267 :     $varHash->{helptext} = $shelp->GetHelpText();
268 :     }
269 : parrello 1.1 }
270 :     };
271 :     if ($@) {
272 :     my $errorMessage = $@;
273 :     Trace("Script Error: $errorMessage") if T(0);
274 :     $varHash->{results} = $cgi->h3("Script Error: $errorMessage");
275 :     }
276 :     ScriptFinish("SproutSearch_tmpl.php", $varHash);
277 :    
278 :     =head3 DisplayResults
279 :    
280 :     C<< my $htmlText = DisplayResults($shelp, $cgi); >>
281 :    
282 :     Display the results of a search. A page of results will be displayed, along with links to get to
283 :     other pages. The HTML for the results display is returned.
284 :    
285 :     =over 4
286 :    
287 :     =item shelp
288 :    
289 :     Search helper object representing the search. The column headers and search rows will be
290 :     stored in the session file attached to it.
291 :    
292 :     =item cgi
293 :    
294 :     CGI query object for the current session. This includes the page number, size, and result
295 :     counts.
296 :    
297 :     =item RETURN
298 :    
299 :     Returns the HTML text for displaying the current page of search results.
300 :    
301 :     =back
302 :    
303 :     =cut
304 :    
305 :     sub DisplayResults {
306 :     # Get the parameters.
307 :     my ($shelp, $cgi) = @_;
308 :     # Declare the return variable.
309 :     my $retVal;
310 :     # Extract the result parameters.
311 :     my ($pageSize, $pageNum, $resultCount) = ($cgi->param('PageSize'),
312 :     $cgi->param('Page'),
313 :     $cgi->param('ResultCount'));
314 :     # Only proceed if there are actual results.
315 :     if ($resultCount <= 0) {
316 :     $retVal = $cgi->h3("No matches found.");
317 :     } else {
318 :     # Check the state of the session file.
319 :     my $fileName = $shelp->GetCacheFileName();
320 :     if (! -e $fileName) {
321 :     $retVal = $cgi->h3("Search session has expired. Please resubmit your query.");
322 :     } else {
323 :     # The file is here, so we can open it.
324 :     my $sessionH = Open(undef, "<$fileName");
325 : parrello 1.6 if (T(3)) {
326 :     my $fileData = stat($sessionH);
327 :     Trace($fileData->size . " bytes in $fileName.");
328 :     }
329 : parrello 1.1 # Read the column headers.
330 :     my @colHdrs = Tracer::GetLine($sessionH);
331 :     # Compute the page navigation string.
332 : parrello 1.14 my $formFlag = ($cgi->param('NoForm') ? 0 : 1);
333 :     my $pageNavigator = PageNavigator($shelp, $formFlag);
334 : parrello 1.1 # Now we need to find our page. The line number we compute will be
335 :     # zero-based. We'll read from the session file until it drops to zero.
336 :     # This may push us past end-of-file, but it won't cause an exception, and
337 :     # it's something that should only happen very rarely in any case.
338 : parrello 1.4 my $linesToSkip = ($pageNum - 1) * $pageSize;
339 :     Trace("Skipping $linesToSkip lines in session file $fileName.") if T(3);
340 :     for (my $lines = $linesToSkip; $lines > 0; $lines--) {
341 : parrello 1.1 Tracer::GetLine($sessionH);
342 :     }
343 :     # The session file is now positioned at the beginning of our line.
344 :     # We build the table rows one line at a time until we run out of data
345 :     # or exceed the page size.
346 :     my @tableRows = ();
347 :     my $linesLeft = $pageSize;
348 : parrello 1.5 Trace("$linesLeft lines to read from session file.") if T(3);
349 :     while ($linesLeft-- > 0) {
350 :     Trace("Reading line from session file.") if T(3);
351 :     my @cols = Tracer::GetLine($sessionH);
352 :     if (! @cols) {
353 :     Trace("End of file read.") if T(3);
354 :     $linesLeft = 0;
355 :     } else {
356 :     Trace("Line has " . scalar(@cols) . " columns. $linesLeft lines left.") if T(3);
357 :     # Check the columns for run-time generation.
358 :     my @actual = map { substr($_,0,2) eq "%%" ? $shelp->GetRunTimeValue($_) : $_ } @cols;
359 :     # Put the actual data into the table list.
360 :     push @tableRows, \@actual;
361 :     }
362 : parrello 1.1 }
363 :     # Now we're ready. We do a page navigator, a spacer, the table, a spacer,
364 :     # and another page navigator.
365 :     $retVal = join("\n", $pageNavigator,
366 :     $cgi->p("&nbsp;"),
367 : parrello 1.10 $cgi->h3("Search Results Page $pageNum"),
368 :     PageBuilder::MakeFancyTable($cgi, \@colHdrs, \@tableRows),
369 : parrello 1.1 $cgi->p("&nbsp;"),
370 :     $pageNavigator,
371 :     "");
372 :     }
373 :     }
374 :     # Return the result.
375 :     return $retVal;
376 :     }
377 :    
378 :     =head3 PageNavigator
379 :    
380 : parrello 1.14 C<< my $htmlText = PageNavigator($shelp, $formFlag); >>
381 : parrello 1.1
382 :     Return a page navigation string for the specified query.
383 :    
384 :     =over 4
385 :    
386 : parrello 1.14 =item shelp
387 :    
388 :     Search helper object for the current session.
389 :    
390 :     =item formFlag
391 :    
392 :     TRUE if a form has been displayed, else FALSE.
393 :    
394 :     =item RETURN
395 : parrello 1.1
396 : parrello 1.14 Returns a page navigation string for the specified search operation. If a form
397 :     has been displayed, the navigation elements will include the complete form
398 :     information; otherwise they will only include position and status.
399 : parrello 1.1
400 :     =back
401 :    
402 :     =cut
403 :    
404 :     sub PageNavigator {
405 :     # Get the parameters.
406 : parrello 1.14 my ($shelp, $formFlag) = @_;
407 :     # Get the CGI query object.
408 :     my $cgi = $shelp->Q();
409 : parrello 1.1 # Extract the result parameters.
410 :     my ($pageSize, $pageNum, $resultCount) = ($cgi->param('PageSize'),
411 :     $cgi->param('Page'),
412 :     $cgi->param('ResultCount'));
413 : parrello 1.4 # Declare the return variable.
414 :     my $retVal = "";
415 : parrello 1.1 # Compute the number of the last page.
416 :     my $lastPage = ceil($resultCount / $pageSize);
417 : parrello 1.4 # Only proceed if there's more than one page.
418 :     if ($lastPage > 1) {
419 :     # Create a URL without a page number. All the other URLs will be generated
420 :     # from this one by appending the new page number.
421 : parrello 1.14 my $url;
422 :     if ($formFlag) {
423 :     $url = $shelp->ComputeSearchURL(PageSize => $pageSize, ResultCount => $resultCount,
424 :     Search => undef, 'Search.x' => undef,
425 :     'Search.y' => undef, SessionID => $shelp->ID());
426 :     } else {
427 :     $url = StatusURL($cgi, Page => undef);
428 :     }
429 : parrello 1.4 # Now compute the start and end pages for the display. We display ten pages,
430 :     # with the current one more or less centered.
431 :     my $startPage = $pageNum - 4;
432 :     if ($startPage < 1) { $startPage = 1; }
433 :     my $endPage = $startPage + 9;
434 :     if ($endPage > $lastPage) { $endPage = $lastPage; }
435 :     # Create a list of URL/page-number combinations.
436 :     my @pageThings = ();
437 :     for (my $linkPage = $startPage; $linkPage <= $endPage; $linkPage++) {
438 :     # Check for the current page. It gets a page number with no link.
439 :     if ($linkPage == $pageNum) {
440 :     push @pageThings, $linkPage;
441 :     } else {
442 :     # This is not the current page, so it gets the full treatment.
443 :     push @pageThings, PageThing($cgi, $linkPage, $linkPage, $url);
444 :     }
445 : parrello 1.1 }
446 : parrello 1.4 # Now add some jump links at the end.
447 :     my @forePointers = ();
448 :     if ($endPage < $lastPage) {
449 :     for (my $pg = $endPage + 5; $pg < $lastPage; $pg += 15) {
450 :     push @forePointers, PageThing($cgi, $pg, $pg, $url);
451 :     }
452 :     push @forePointers, PageThing($cgi, ">>", $lastPage, $url);
453 : parrello 1.3 }
454 : parrello 1.4 # Finally, add some jump links at the front.
455 :     my @backPointers = ();
456 :     if ($startPage > 1) {
457 :     for (my $pg = $startPage - 5; $pg > 1; $pg -= 15) {
458 : parrello 1.6 unshift @backPointers, PageThing($cgi, $pg, $pg, $url);
459 : parrello 1.4 }
460 : parrello 1.6 unshift @backPointers, PageThing($cgi, "<<", 1, $url);
461 : parrello 1.3 }
462 : parrello 1.4 # Put it all together.
463 :     my $middle = join(" ", @pageThings);
464 :     $retVal = join " ... ", @backPointers, $middle, @forePointers;
465 : parrello 1.3 }
466 : parrello 1.1 # Return the result.
467 :     return $retVal;
468 :     }
469 :    
470 :     =head3 PageThing
471 :    
472 :     C<< my $htmlText = PageThing($cgi, $pageLabel, $pageNumber, $url); >>
473 :    
474 :     Create an entry for the page navigator. The entry consists of a label that
475 :     is hyperlinked to the specified page number of the search results.
476 :    
477 :     =over 4
478 :    
479 :     =item cgi
480 :    
481 :     CGI object, used to access the CGI HTML-building methods.
482 :    
483 :     =item pageLabel
484 :    
485 :     Text to be hyperlinked. This is usually the page number, but sometimes it will be
486 :     arrows.
487 :    
488 :     =item pageNumber
489 :    
490 :     Number of the page to be presented when the link is followed.
491 :    
492 :     =item url
493 :    
494 :     Base URL for viewing a page.
495 :    
496 :     =item RETURN
497 :    
498 :     Returns HTML for the specified label, hyperlinked to the desired page.
499 :    
500 :     =back
501 :    
502 :     =cut
503 :    
504 :     sub PageThing {
505 :     # Get the parameters.
506 :     my ($cgi, $pageLabel, $pageNumber, $url) = @_;
507 :     # Compute the full URL.
508 :     my $purl = "$url&Page=$pageNumber";
509 :     # Form it into a hyperlink.
510 :     my $retVal = "<a href=\"$purl\" title=\"Results page $pageNumber\">$pageLabel</a>";
511 :     # Return the result.
512 :     return $retVal;
513 :     }
514 :    
515 :     =head3 StatusURL
516 :    
517 :     C<< my $queryUrl = StatusURL($cgi, %overrides); >>
518 :    
519 :     Create a URL for the current script containing status information for the search in progress.
520 :     The values in the incoming CGI object will be used for all parameters except the ones
521 :     specified as overrides. So, for example
522 :    
523 :     StatusURL($cgi, PageNum => 3)
524 :    
525 :     would specify a page number of 3, but all the other parameters will be taken as is from
526 :     the CGI object. The complete list of session variables is given in the L</Session Data>
527 :     section.
528 :    
529 :     =over 4
530 :    
531 :     =item cgi
532 :    
533 :     CGI query object containing the session variables.
534 :    
535 :     =item overrides
536 :    
537 :     A hash mapping key names to override values. These are used to override values in the
538 :     I<$cgi> parameter.
539 :    
540 :     =item RETURN
541 :    
542 :     Returns a relative URL for the current page with GET-style values for all the session
543 :     variables.
544 :    
545 :     =back
546 :    
547 :     =cut
548 :    
549 :     sub StatusURL {
550 :     # Get the parameters.
551 :     my ($cgi, %overrides) = @_;
552 :     # Create a hash of the session variables we want to keep.
553 :     my %varHash;
554 :     for my $varKey (qw(SessionID Trace NoForm ResultCount Page PageSize Class SPROUT)) {
555 :     # Check for an override.
556 :     if (exists $overrides{$varKey}) {
557 :     my $override = $overrides{$varKey};
558 :     # Use the override if it is not null or undefined.
559 :     if (defined($override) && $override ne "") {
560 :     $varHash{$varKey} = $override;
561 :     }
562 :     } else {
563 :     # Check for a CGI value.
564 :     my $normal = $cgi->param($varKey);
565 :     # Use it if it exists.
566 :     if (defined($normal)) {
567 :     $varHash{$varKey} = $normal;
568 :     }
569 :     }
570 :     }
571 :     # Compute the full URL.
572 :     my $retVal = Tracer::GenerateURL($cgi->url(-relative => 1), %varHash);
573 :     # Return the result.
574 :     return $retVal;
575 :     }
576 :    
577 :     =head3 GetHelper
578 :    
579 :     C<< my $shelp = GetHelper($className); >>
580 :    
581 :     Return a helper object with the given class name. If no such class exists, an
582 :     error will be thrown.
583 :    
584 :     =over 4
585 :    
586 :     =item cgi
587 :    
588 :     Active CGI query object.
589 :    
590 :     =item className
591 :    
592 :     Class name for the search helper object, without the preceding C<SH>. This is
593 :     identical to what the script expects for the C<Class> parameter.
594 :    
595 :     =item RETURN
596 :    
597 :     Returns a search helper object for the specified class.
598 :    
599 :     =back
600 :    
601 :     =cut
602 :    
603 :     sub GetHelper {
604 :     # Get the parameters.
605 :     my ($cgi, $className) = @_;
606 :     # Try to create the search helper.
607 :     my $retVal = eval("SH$className->new(\$cgi)");
608 :     if (! defined $retVal) {
609 :     Confess("Could not find a search handler of type $className.");
610 :     }
611 :     # Return the result.
612 :     return $retVal;
613 :     }
614 :    
615 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3