Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > c0b2316b5320756fc35b43f35335d7ce > files > 135

perl-AcePerl-1.920.0-1mdv2010.0.i586.rpm

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Ace::Browser::AceSubs - Subroutines for AceBrowser</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>

<body style="background-color: white">


<!-- INDEX BEGIN -->
<div name="index">
<p><a name="__index__"></a></p>
<!--

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#subroutines">SUBROUTINES</a></li>
	<li><a href="#bugs">BUGS</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
	<li><a href="#author">AUTHOR</a></li>
</ul>

-->


</div>
<!-- INDEX END -->

<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Ace::Browser::AceSubs - Subroutines for AceBrowser</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
  use Ace;
  use Ace::Browser::AceSubs;
  use CGI qw(:standard);
  use CGI::Cookie;</pre>
<pre>
  my $obj = GetAceObject() || AceNotFound();
  PrintTop($obj);
  print $obj-&gt;asHTML;
  PrintBottom();</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>Ace::Browser::AceSubs exports a set of routines that are useful for
creating search pages and displays for AceBrowser CGI pages. See
<a href="http://stein.cshl.org/AcePerl/AceBrowser.">http://stein.cshl.org/AcePerl/AceBrowser.</a></p>
<p>The following subroutines are exported by default:</p>
<pre>
  AceError
  AceMissing
  AceNotFound
  Configuration
  DoRedirect
  GetAceObject
  Object2URL
  ObjectLink
  OpenDatabase
  PrintTop
  PrintBottom
  Url</pre>
<p>The following subroutines are exported if explicitly requested:</p>
<pre>
  AceAddCookie
  AceInit
  AceHeader
  AceMultipleChoices
  AceRedirect
  DB_Name
  Footer
  Header
  ResolveUrl
  Style
  Toggle
  TypeSelector</pre>
<p>To load the default subroutines load the module with:</p>
<pre>
   use Ace::Browser::AceSubs;</pre>
<p>To bring in a set of optionally routines, load the module with:</p>
<pre>
   use Ace::Browser::AceSubs qw(AceInit AceRedirect);</pre>
<p>To bring in all the default subroutines, plus some of the optional
ones:</p>
<pre>
   use Ace::Browser::AceSubs qw(:DEFAULT AceInit AceRedirect);</pre>
<p>There are two main types of AceBrowser scripts:</p>
<dl>
<dt><strong><a name="display_scripts" class="item">display scripts</a></strong>

<dd>
<p>These are called with the CGI parameters b&lt;name&gt; and b&lt;class&gt;,
corresponding to the name and class of an AceDB object to display.
The subroutine <a href="#getaceobject"><code>GetAceObject()</code></a> will return the requested object, or
undef if the object does not exist.</p>
</dd>
<dd>
<p>To retrieve the parameters, use the CGI.pm <code>param()</code> method:</p>
</dd>
<dd>
<pre>
  $name  = param('name');
  $class = param('class');</pre>
</dd>
</li>
<dt><strong><a name="search_scripts" class="item">search scripts</a></strong>

<dd>
<p>These are not called with any CGI parameters on their first
invocation, but can define their own parameter lists by creating
fill-out forms.  The AceBrowser system remembers the last search
performed by a search script in a cookie and regenerates the CGI
parameters the next time the user selects that search script.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="subroutines">SUBROUTINES</a></h1>
<p>The following sections describe the exported subroutines.</p>
<dl>
<dt><strong><a name="aceerror" class="item"><code>AceError($message)</code></a></strong>

<dd>
<p>This subroutine will print out an error message and exit the script.
The text of the message is taken from $message.</p>
</dd>
</li>
<dt><strong><a name="aceheader" class="item"><code>AceHeader()</code></a></strong>

<dd>
<p>This function prints the HTTP header and issues a number of cookies
used for maintaining AceBrowser state.  It is not exported by default.</p>
</dd>
</li>
<dt><strong><a name="aceaddcookie" class="item"><code>AceAddCookie(@cookies)</code></a></strong>

<dd>
<p>This subroutine, which must be called b&lt;after&gt; <a href="#opendatabase"><code>OpenDatabase()</code></a> and/or
<a href="#getaceobject"><code>GetAceObject()</code></a> and b&lt;before&gt; <a href="#printtop"><code>PrintTop()</code></a>, will add one or more cookies
to the outgoing HTTP headers that are emitted by <a href="#aceheader"><code>AceHeader()</code></a>.  
Cookies must be CGI::Cookie objects.</p>
</dd>
</li>
<dt><strong><a name="aceinit" class="item"><code>AceInit()</code></a></strong>

<dd>
<p>This subroutine initializes the AcePerl connection to the configured
database.  If the database cannot be opened, it generates an error
message and exits.  This subroutine is not exported by default, but is 
called by <a href="#printtop"><code>PrintTop()</code></a> and <a href="#header"><code>Header()</code></a> internally.</p>
</dd>
</li>
<dt><strong><a name="acemissing" class="item"><code>AceMissing([$class,$name])</code></a></strong>

<dd>
<p>This subroutine will print out an error message indicating that an
object is present in AceDB, but that the information the user
requested is absent. It will then exit the script. This is
infrequently encountered when following XREFed objects. If the class
and name of the object are not provided as arguments, they are taken
from CGI's <code>param()</code> function.</p>
</dd>
</li>
<dt><strong><a name="acemultiplechoices" class="item"><code>AceMultipleChoices($symbol,$report,$objects)</code></a></strong>

<dd>
<p>This function is called when a search has recovered multiple objects
and the user must make a choice among them.  The user is presented
with an ordered list of the objects, and asked to click on one of
them.</p>
</dd>
<dd>
<p>The three arguements are:</p>
</dd>
<dd>
<pre>
   $symbol   The keyword or query string the user was searching
             on, undef if none.</pre>
</dd>
<dd>
<pre>
   $report   The symbolic name of the current display, or undef
             if none.</pre>
</dd>
<dd>
<pre>
   $objects  An array reference containing the Ace objects in
             question.</pre>
</dd>
<dd>
<p>This subroutine is not exported by default.</p>
</dd>
</li>
<dt><strong><a name="acenotfound" class="item"><code>AceNotFound([$class,$name])</code></a></strong>

<dd>
<p>This subroutine will print out an error message indicating that the
requested object is not present in AceDB, even as a name. It will then
exit the script. If the class and name of the object are not provided
as arguments, they are taken from CGI's <code>param()</code> function.</p>
</dd>
</li>
<dt><strong><a name="acepicroot" class="item">($uri,$physical_path) = <code>AcePicRoot($directory)</code></a></strong>

<dd>
<p>This function returns the physical and URL paths of a temporary
directory in which the pic script can write pictures.  Not exported by
default.  Returns a two-element list containing the URL and physical
path.</p>
</dd>
</li>
<dt><strong><a name="aceredirect" class="item"><code>AceRedirect($report,$object)</code></a></strong>

<dd>
<p>This function redirects the user to a named display script for viewing 
an Ace object.  It is used, for example, to convert a request for a
sequence into a request for a protein:</p>
</dd>
<dd>
<pre>
  $obj = GetAceObject();
  if ($obj-&gt;CDS) {
    my $protein = $obj-&gt;Corresponding_protein;
    AceRedirect('protein',$protein);
  }</pre>
</dd>
<dd>
<p>AceRedirect must be called b&lt;before&gt; <a href="#printtop"><code>PrintTop()</code></a> or  <a href="#aceheader"><code>AceHeader()</code></a>.  It
invokes <code>exit()</code>, so it will not return.</p>
</dd>
<dd>
<p>This subroutine is not exported by default.  It differs from
<a href="#doredirect"><code>DoRedirect()</code></a> in that it displays a message to the user for two seconds
before it generates the new page. It also allows the display to be set
explicitly, rather than determined automatically by the AceBrowser
system.</p>
</dd>
</li>
<dt><strong><a name="configuration" class="item">$configuration = <code>Configuration()</code></a></strong>

<dd>
<p>The <a href="#configuration"><code>Configuration()</code></a> function returns the Ace::Browser::SiteDefs object
for the current session.  From this object you can retrieve
information from the configuration file.</p>
</dd>
</li>
<dt><strong><a name="db_name" class="item">$name = <code>DB_Name()</code></a></strong>

<dd>
<p>This function returns the symbolic name of the current database, for
example &quot;default&quot;.</p>
</dd>
</li>
<dt><strong><a name="doredirect" class="item"><code>DoRedirect($object)</code></a></strong>

<dd>
<p>This subroutine immediately redirects to the default display for the
Ace::Object indicated by $object and exits the script.  It must be
called before <a href="#printtop"><code>PrintTop()</code></a> or any other HTML-generating code.  It
differs from <a href="#aceredirect"><code>AceRedirect()</code></a> in that it generates a fast redirect
without alerting the user.</p>
</dd>
<dd>
<p>This function is not exported by default.</p>
</dd>
</li>
<dt><strong><a name="footer" class="item">$footer = <code>Footer()</code></a></strong>

<dd>
<p>This function returns the contents of the footer as a string, but does 
not print it out.  It is not exported by default.</p>
</dd>
</li>
<dt><strong><a name="getaceobject" class="item">$object = <code>GetAceObject()</code></a></strong>

<dd>
<p>This function is called by display scripts to return the
Ace::Object.that the user wishes to view.  It automatically opens or
refreshes the database, and performs the request using the values of the
&quot;name&quot; and &quot;class&quot; CGI variables.</p>
</dd>
<dd>
<p>If a single object is found, the function returns it as the function
result.  If no objects are found, it returns undef.  If more than one
object is found, the function invokes <a href="#acemultiplechoices"><code>AceMultipleChoices()</code></a> and exits
the script.</p>
</dd>
</li>
<dt><strong><a name="header" class="item">$html = <code>Header()</code></a></strong>

<dd>
<p>This subroutine returns the boilerplate at the top of the HTML page as 
a string, but does not print it out.  It is not exported by default.</p>
</dd>
</li>
<dt><strong><a name="object2url" class="item">$url = Object2URL($object)</a></strong>

<dt><strong>$url = Object2URL($name,$class)</strong>

<dd>
<p>In its single-argument form, this function takes an AceDB Object and
returns an AceBrowser URL.  The URL chosen is determined by the
configuration settings.</p>
</dd>
<dd>
<p>It is also possible to pass Object2URL an object name and class, in
the case that an AceDB object isn't available.</p>
</dd>
<dd>
<p>The return value is a URL.</p>
</dd>
</li>
<dt><strong><a name="objectlink" class="item">$link = ObjectLink($object [,$link_text])</a></strong>

<dd>
<p>This function converts an AceDB object into a hypertext link.  The
first argument is an Ace::Object.  The second, optional argument is
the text to use for the link.  If not provided, the object's name
becomes the link text.</p>
</dd>
<dd>
<p>This function is used extensively to create cross references between
Ace::Objects on AceBrowser pages.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
  my $author = $db-&gt;fetch(Author =&gt; 'Sulston JE');
  print ObjectLink($author,$author-&gt;Full_name);</pre>
</dd>
<dd>
<p>This will print out a link to a page that will display details on the
author page.  The text of the link will be the value of the Full_name
tag.</p>
</dd>
</li>
<dt><strong><a name="opendatabase" class="item">$db = <code>OpenDatabase()</code></a></strong>

<dd>
<p>This function opens the Acedb database designated by the configuration
file.  In modperl environments, this function caches database handles
and reuses them, pinging and reopening them in the case of timeouts.</p>
</dd>
<dd>
<p>This function is not exported by default.</p>
</dd>
</li>
<dt><strong><a name="printtop" class="item"><code>PrintTop($object,$class,$title,@html_headers)</code></a></strong>

<dd>
<p>The <a href="#printtop"><code>PrintTop()</code></a> function generates all the boilerplate at the top of a
typical AceBrowser page, including the HTTP header information, the
page title, the navigation bar for searches, the web site banner, the
type selector for choosing alternative displays, and a level-one
header.</p>
</dd>
<dd>
<p>Call it with one or more arguments.  The arguments are:</p>
</dd>
<dd>
<pre>
  $object    An AceDB object.  The navigation bar and title will be
             customized for the object.</pre>
</dd>
<dd>
<pre>
  $class     If no AceDB object is available, then you can pass 
             a string containing the AceDB class that this page is
             designed to display.</pre>
</dd>
<dd>
<pre>
  $title     A title to use for the HTML page and the first level-one
             header.  If not provided, a generic title &quot;Report for
             Object&quot; is generated.</pre>
</dd>
<dd>
<pre>
  @html_headers  Additional HTML headers to pass to the the CGI.pm
             start_html.</pre>
</dd>
</li>
<dt><strong><a name="printbottom" class="item"><code>PrintBottom()</code></a></strong>

<dd>
<p>The <a href="#printbottom"><code>PrintBottom()</code></a> function outputs all the boilerplate at the bottom
of a typical AceBrowser page.  If a user-defined footer is present in
the configuration file, that is printed.  Otherwise, the method prints 
a horizontal rule followed by links to the site home page, the AcePerl 
home page, the privacy policy, and the feedback page.</p>
</dd>
</li>
<dt><strong><a name="style" class="item">$hashref = <code>Style()</code></a></strong>

<dd>
<p>This subroutine returns a hashref containing a reference to the
configured stylesheet, in the following format:</p>
</dd>
<dd>
<pre>
  { -src =&gt; '/ace/stylesheets/current_stylesheet.css' }</pre>
</dd>
<dd>
<p>This hash is suitable for passing to the -style argument of CGI.pm's
<code>start_html()</code> function, or for use as an additional header in
<a href="#printtop"><code>PrintTop()</code></a>.  You may add locally-defined stylesheet elements to the
hash before calling <code>start_html()</code>.  See the pic script for an example
of how this is done this.</p>
</dd>
<dd>
<p>This function is not exported by default.</p>
</dd>
</li>
<dt><strong><a name="resolveurl" class="item">$url = <code>ResolveUrl($url,$param)</code></a></strong>

<dd>
<p>Given a URL and a set of parameters, this function does the necessary
magic to add the symbolic database name to the end of the URL (if
needed) and then tack the parameters onto the end.</p>
</dd>
<dd>
<p>A typical call is:</p>
</dd>
<dd>
<pre>
  $url = ResolveUrl('/cgi-bin/ace/generic/tree','name=fred;class=Author');</pre>
</dd>
<dd>
<p>This function is not exported by default.</p>
</dd>
</li>
<dt><strong><a name="toggle" class="item">$boolean = <code>Toggle($section,[$label,$object_count,$add_plural,$add_count])</code></a></strong>

<dt><strong>($link,$bool) = <code>Toggle($section,$label,$object_count,$add_plural,$add_count)</code></strong>

<dd>
<p>The <a href="#toggle"><code>Toggle()</code></a> subroutine makes it easy to create HTML sections that
open and close when the user selects a toggle icon (a yellow
triangle).</p>
</dd>
<dd>
<p><a href="#toggle"><code>Toggle()</code></a> can be used to manage multiple collapsible HTML sections, but
each section must have a unique name.  The required first argument is
the section name.  Optional arguments are:</p>
</dd>
<dd>
<pre>
  $label         The text of the generated link, for example &quot;sequence&quot;</pre>
</dd>
<dd>
<pre>
  $object_count  The number of objects that opening the section will reveal</pre>
</dd>
<dd>
<pre>
  $add_plural    If true, the label will be pluralized when
                 appropriate</pre>
</dd>
<dd>
<pre>
  $add_count     If true, the label will have the object count added
                 when appropriate</pre>
</dd>
<dd>
<p>In a scalar context, <a href="#toggle"><code>Toggle()</code></a> prints the link HTML and returns a
boolean flag.  A true result indicates that the section is expanded
and should be generated.  A false result indicates that the section is 
collapsed.</p>
</dd>
<dd>
<p>In a list context, <a href="#toggle"><code>Toggle()</code></a> returns a two-element list.  The first
element is the HTML link that expands and contracts the section.  The
second element is a boolean that indicates whether the section is
currently open or closed.</p>
</dd>
<dd>
<p>This example indicates typical usage:</p>
</dd>
<dd>
<pre>
  my $sequence = GetAceObject();
  print &quot;sequence name = &quot;,$sequence,&quot;\n&quot;;
  print &quot;sequence clone = &quot;,$sequence-&gt;Clone,&quot;\n&quot;;
  if (Toggle('dna','Sequence DNA')) {
      print $sequence-&gt;asDNA;
  }</pre>
</dd>
<dd>
<p>An alternative way to do the same thing:</p>
</dd>
<dd>
<pre>
  my $sequence = GetAceObject();
  print &quot;sequence name = &quot;,$sequence,&quot;\n&quot;;
  print &quot;sequence clone = &quot;,$sequence-&gt;Clone,&quot;\n&quot;;
  my ($link,$open) = Toggle('dna','Sequence DNA');
  print $link;
  print $sequence-&gt;asDNA if $open;</pre>
</dd>
</li>
<dt><strong><a name="typeselector" class="item">$html = <code>TypeSelector($name,$class)</code></a></strong>

<dd>
<p>This subroutine generates the HTML for the type selector navigation
bar.  The links in the bar are dynamically generated based on the
values of $name and $class.  This function is called by <a href="#printtop"><code>PrintTop()</code></a>.
It is not exported by default.</p>
</dd>
</li>
<dt><strong><a name="url" class="item">$url = <code>Url($display,$params)</code></a></strong>

<dd>
<p>Given a symbolic display name, such as &quot;tree&quot; and a set of parameters, 
this function looks up its URL and then calls <a href="#resolveurl"><code>ResolveUrl()</code></a> to create a 
single Url.</p>
</dd>
<dd>
<p>When hard-coding relative URLs into AceBrowser scripts, it is
important to pass them through <a href="#url"><code>Url()</code></a>.  The reason for this is that
AceBrowser may need to attach the database name to the URL in order to
identify it.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
  my $url = Url('../sequence_dump',&quot;name=$name;long_dump=yes&quot;);
  print a({-href=&gt;$url},'Dump this sequence');</pre>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="bugs">BUGS</a></h1>
<p>Please report them.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="/AcePerl/docs/./Ace/Object.html">the Ace::Object manpage</a>, <a href="/AcePerl/docs/./Ace/Browser/SiteDefs.html">the Ace::Browser::SiteDefs manpage</a>, <a href="/AcePerl/docs/Ace/Browsr/SearchSubs.html">the Ace::Browsr::SearchSubs manpage</a>,
the README.ACEBROWSER file.</p>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>Lincoln Stein &lt;<a href="mailto:lstein@cshl.org">lstein@cshl.org</a>&gt;.</p>
<p>Copyright (c) 2001 Cold Spring Harbor Laboratory</p>
<p>This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.  See DISCLAIMER.txt for
disclaimers of warranty.</p>

</body>

</html>