Getting information from matching records
The fetch method
The IMu::Module
class fetch
method is used to get information from the
matching records once the search of a module has been run. The server maintains
the set of matching records in a list and the fetch
method can be used to
retrieve any information from any contiguous block of records in the list.
Specifying columns
This section specifies the values that can be included or used as the
columns
arguments to the IMu::Module
class fetch
method.
A Simple example
In this example we build a simple Perl CGI (Common Gateway Interface)-based web page to search the Parties module by last name and display the full set of results.
First build the search page , which is a plain HTML form:
<head>
<title>Party Search</title>
</head>
<body>
<form action="/cgi-bin/a-simple-example.pl">
<p>Enter a last name to search for (e.g. Smith):</p>
<input type="text" name="name"/>
<input type="submit" value="Search"/>
</form>
</body>
Next build the results page (source code), which runs the search and displays the results:
#!/usr/bin/env perl use strict;use warnings;use FindBin qw($RealBin);use lib "$RealBin/../../lib";use IMu::Module;use IMu::Session;use IMu::Terms;use CGI;use CGI::Carp qw(fatalsToBrowser); my $cgi = CGI->new();my $name = $cgi->param('name');if (! defined($name) || $name eq '') { print($cgi->header('text/html','400 Bad Request')); die("missing 'name' parameter\n"); } my $terms = IMu::Terms->new(); $terms->add('NamLast', $name); my $session = IMu::Session->new('imu.mel.kesoftware.com', 40136);my $parties = IMu::Module->new('eparties', $session);my $hits = $parties->findTerms($terms); my $columns = [ 'NamFirst', 'NamLast' ];my $results = $parties->fetch('start', 0, -1, $columns); print($cgi->header()); print($cgi->start_html(-title => 'IMu Perl API - A Simple Example')); print($cgi->p("Number of matches: $hits")); print($cgi->start_table()); foreach my $row (@{$results->{'rows'}}) { my $rowNum = $row->{'rownum'}; my $firstName = $row->{'NamFirst'}; my $lastName = $row->{'NamLast'}; print($cgi->start_Tr()); print($cgi->start_td(), "$rowNum.", $cgi->end_td()); print($cgi->start_td(), "$lastName, $firstName", $cgi->end_td()); print($cgi->end_Tr()); } print($cgi->end_table(), "\n"); print($cgi->end_html()); exit(0);
In this example the name
parameter entered via the HTML search page is
submitted to the Perl CGI script. The script searches for parties records
that have the entered value as a last name and display the parties first and
last names in an HTML table.
For more information about the Perl CGI module & running CGI under apache see: