AcePerl
view release on metacpan or search on metacpan
Ace/Browser/AceSubs.pm view on Meta::CPAN
AceRedirect
DB_Name
Footer
Header
ResolveUrl
Style
Toggle
TypeSelector
To load the default subroutines load the module with:
use Ace::Browser::AceSubs;
To bring in a set of optionally routines, load the module with:
use Ace::Browser::AceSubs qw(AceInit AceRedirect);
To bring in all the default subroutines, plus some of the optional
ones:
use Ace::Browser::AceSubs qw(:DEFAULT AceInit AceRedirect);
There are two main types of AceBrowser scripts:
=over 4
=item display scripts
These are called with the CGI parameters b<name> and b<class>,
corresponding to the name and class of an AceDB object to display.
The subroutine GetAceObject() will return the requested object, or
undef if the object does not exist.
To retrieve the parameters, use the CGI.pm param() method:
$name = param('name');
$class = param('class');
=item search scripts
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.
=back
=head1 SUBROUTINES
The following sections describe the exported subroutines.
=over 4
=cut
use strict;
use Ace::Browser::SiteDefs;
use Ace 1.76;
use CGI qw(:standard escape);
use CGI::Cookie;
use File::Path 'mkpath';
use vars qw/@ISA @EXPORT @EXPORT_OK $VERSION %EXPORT_TAGS
%DB %OPEN $HEADER $TOP @COOKIES
$APACHE_CONF/;
require Exporter;
@ISA = qw(Exporter);
$VERSION = 1.21;
######################### This is the list of exported subroutines #######################
@EXPORT = qw(
GetAceObject AceError AceNotFound AceMissing DoRedirect
OpenDatabase Object2URL Url
ObjectLink Configuration PrintTop PrintBottom);
@EXPORT_OK = qw(AceRedirect Toggle ResolveUrl AceInit AceAddCookie
AceHeader TypeSelector Style AcePicRoot
Header Footer DB_Name AceMultipleChoices);
%EXPORT_TAGS = ( );
use constant DEFAULT_DATABASE => 'default';
use constant PRIVACY => 'misc/privacy'; # privacy/cookie statement
use constant SEARCH_BROWSE => 'search'; # a fallback search script
my %VALID; # cache for get_symbolic() lookups
=item AceError($message)
This subroutine will print out an error message and exit the script.
The text of the message is taken from $message.
=cut
sub AceError {
my $msg = shift;
PrintTop(undef,undef,'Error');
print CGI::font({-color=>'red'},$msg);
PrintBottom();
Apache->exit(0) if defined &Apache::exit;
exit(0);
}
=item AceHeader()
This function prints the HTTP header and issues a number of cookies
used for maintaining AceBrowser state. It is not exported by default.
=cut
=item AceAddCookie(@cookies)
This subroutine, which must be called b<after> OpenDatabase() and/or
GetAceObject() and b<before> PrintTop(), will add one or more cookies
to the outgoing HTTP headers that are emitted by AceHeader().
Cookies must be CGI::Cookie objects.
=cut
sub AceAddCookie {
push @COOKIES,@_; # add caller's to our globals
Ace/Browser/AceSubs.pm view on Meta::CPAN
=item $configuration = Configuration()
The Configuration() function returns the Ace::Browser::SiteDefs object
for the current session. From this object you can retrieve
information from the configuration file.
=cut
# get the configuration object for this database
sub Configuration {
my $s = get_symbolic()||return;
return Ace::Browser::SiteDefs->getConfig($s);
}
=item $name = DB_Name()
This function returns the symbolic name of the current database, for
example "default".
=cut
*DB_Name = \&get_symbolic;
=item DoRedirect($object)
This subroutine immediately redirects to the default display for the
Ace::Object indicated by $object and exits the script. It must be
called before PrintTop() or any other HTML-generating code. It
differs from AceRedirect() in that it generates a fast redirect
without alerting the user.
This function is not exported by default.
=cut
# redirect to the URL responsible for an object
sub DoRedirect {
my $obj = shift;
print redirect(Object2URL($obj));
Apache->exit(0) if defined &Apache::exit;
exit(0);
}
=item $footer = Footer()
This function returns the contents of the footer as a string, but does
not print it out. It is not exported by default.
=cut
# Contents of the HTML footer. It gets printed immediately before the </BODY> tag.
# The one given here generates a link to the "feedback" page, as well as to the
# privacy statement. You may or may not want these features.
sub Footer {
if (my $footer = Configuration()->Footer) {
return $footer;
}
my $webmaster = $ENV{SERVER_ADMIN} || 'webmaster@sanger.ac.uk';
my $obj_name = escape(param('name'));
my $obj_class = escape(param('class')) || ucfirst url(-relative=>1);
my $referer = escape(self_url());
my $name = get_symbolic();
# set up the feedback link
my $feedback_link = Configuration()->Feedback_recipients &&
$obj_name &&
(url(-relative=>1) ne 'feedback') ?
a({-href=>ResolveUrl("misc/feedback/$name","name=$obj_name;class=$obj_class;referer=$referer")},
"Click here to send data or comments to the maintainers")
: '';
# set up the privacy statement link
my $privacy_link = ( Configuration()->Print_privacy_statement &&
url(-relative=>1) ne PRIVACY())
?
a({ -href=>ResolveUrl(PRIVACY."/$name") },'Privacy Statement')
: '';
my ($home,$label) = @{Configuration()->Home};
my $hlink = $home ? a({-href=>$home},$label) : '';
# Either generate a pointer to ACeDB home page, or the copyright statement.
my $clink = Configuration()->Copyright ? a({-href=>Configuration()->Copyright,-target=>"_new"},'Copyright Statement')
: qq(<A HREF="http://stein.cshl.org/AcePerl">AcePerl Home Page</A>);
return <<END;
<TABLE WIDTH="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR CLASS="technicalinfo">
<TD CLASS="small" VALIGN="TOP">
$hlink<br>$clink
</TD>
<TD CLASS="small" ALIGN=RIGHT VALIGN=TOP><p><strong>$feedback_link</strong><br>
$privacy_link<br>
<A HREF="mailto:$webmaster"><address>$webmaster</address></A><br>
</TD>
</TR>
</TABLE>
END
}
=item $object = GetAceObject()
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
"name" and "class" CGI variables.
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 AceMultipleChoices() and exits
the script.
=cut
# open database, return object requested by CGI parameters
sub GetAceObject {
my $db = OpenDatabase() || AceError("Couldn't open database."); # exits
my $name = param('name') or return;
my $class = param('class') or return;
my @objs = $db->fetch($class => $name);
Ace/Browser/AceSubs.pm view on Meta::CPAN
if (Toggle('dna','Sequence DNA')) {
print $sequence->asDNA;
}
An alternative way to do the same thing:
my $sequence = GetAceObject();
print "sequence name = ",$sequence,"\n";
print "sequence clone = ",$sequence->Clone,"\n";
my ($link,$open) = Toggle('dna','Sequence DNA');
print $link;
print $sequence->asDNA if $open;
=cut
# Toggle a subsection open and close
sub Toggle {
my ($section,$label,$count,$addplural,$addcount,$max_open) = @_;
$OPEN{$section}++ if defined($max_open) && $count <= $max_open;
my %open = %OPEN;
$label ||= $section;
my $img;
if (exists $open{$section}) {
delete $open{$section};
$img = img({-src=>'/ico/triangle_down.gif',-alt=>'^',
-height=>6,-width=>11,-border=>0}),
} else {
$open{$section}++;
$img = img({-src=>'/ico/triangle_right.gif',-alt=>'>',
-height=>11,-width=>6,-border=>0}),
my $plural = ($addplural and $label !~ /s$/) ? "${label}s" : "$label";
$label = font({-class=>'toggle'},!$addcount ? $plural : "$count $plural");
}
param(-name=>'open',-value=>join(' ',keys %open));
my $url = url(-absolute=>1,-path_info=>1,-query=>1);
my $link = a({-href=>"$url#$section",-name=>$section},$img.' '.$label);
if (wantarray ){
return ($link,$OPEN{$section})
} else {
print $link,br;
return $OPEN{$section};
}
}
=item $html = TypeSelector($name,$class)
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 PrintTop().
It is not exported by default.
=cut
# Choose a set of displayers based on the type.
sub TypeSelector {
my ($name,$class) = @_;
return unless $class;
my ($n,$c) = (escape("$name"),escape($class));
my @rows;
# add the special displays
my @displays = Configuration()->class2displays($class,$name);
my @basic_displays = Configuration()->class2displays('default');
@basic_displays = Ace::Browser::SiteDefs->getConfig(DEFAULT_DATABASE)->class2displays('default')
unless @basic_displays;
my $display = url(-absolute=>1,-path=>1);
foreach (@displays,@basic_displays) {
my ($url,$icon,$label) = @{$_}{qw/url icon label/};
next unless $url;
my $u = ResolveUrl($url,"name=$n;class=$c");
($url = $u) =~ s/[?\#].*$//;
my $active = $url =~ /^$display/;
my $cell;
unless ($active) {
$cell = defined $icon ? a({-href=>$u,-target=>'_top'},
img({-src=>$icon,-border=>0}).br().$label)
: a({-href=>$u,-target=>'_top'},$label);
} else {
$cell = defined $icon ? img({-src=>$icon,-border=>0}).br().font({-color=>'red'},$label)
: font({-color=>'red'},$label);
}
push (@rows,td({-align=>'CENTER',-class=>'small'},$cell));
}
return table({-width=>'100%',-border=>0,-class=>'searchtitle'},
TR({-valign=>'bottom'},@rows));
}
=item $url = Url($display,$params)
Given a symbolic display name, such as "tree" and a set of parameters,
this function looks up its URL and then calls ResolveUrl() to create a
single Url.
When hard-coding relative URLs into AceBrowser scripts, it is
important to pass them through Url(). The reason for this is that
AceBrowser may need to attach the database name to the URL in order to
identify it.
Example:
my $url = Url('../sequence_dump',"name=$name;long_dump=yes");
print a({-href=>$url},'Dump this sequence');
=cut
sub Url {
my ($display,$parameters) = @_;
my $url = Configuration()->display($display,'url');
return ResolveUrl($url,$parameters);
}
sub Open_table{
print '<table width=660>
<tr>
( run in 1.293 second using v1.01-cache-2.11-cpan-5a3173703d6 )