AcePerl
view release on metacpan or search on metacpan
Ace/Browser/AceSubs.pm view on Meta::CPAN
($name,$class) = ($object,$object->class);
} else {
($name,$class) = ($object,$extra);
}
my $display = url(-relative=>1);
my ($disp,$parameters) = Configuration()->map_url($display,$name,$class);
return $disp unless $parameters;
return Url($disp,$parameters);
}
=item $link = ObjectLink($object [,$link_text])
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.
This function is used extensively to create cross references between
Ace::Objects on AceBrowser pages.
Example:
my $author = $db->fetch(Author => 'Sulston JE');
print ObjectLink($author,$author->Full_name);
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.
=cut
sub ObjectLink {
my $object = shift;
my $link_text = shift;
my $target = shift;
my $url = Object2URL($object,@_) or return ($link_text || "$object");
my @targ = $target ? (-target=>$target) : ();
return a({-href=>Object2URL($object,@_),-name=>"$object",@targ},($link_text || "$object"));
}
=item $db = OpenDatabase()
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.
This function is not exported by default.
=cut
use Carp 'cluck';
################ open a database #################
sub OpenDatabase {
my $name = shift || get_symbolic();
AceInit();
$name =~ s!/$!!;
my $db = $DB{$name};
return $db if $db && $db->ping;
my ($host,$port,$user,$password,
$cache_root,$cache_size,$cache_expires,$auto_purge_interval)
= getDatabasePorts($name);
my @auth = (-user=>$user,-pass=>$password) if $user && $password;
my @cache = (-cache => { cache_root=>$cache_root,
max_size => $cache_size || $Cache::SizeAwareCache::NO_MAX_SIZE || -1, # hardcoded $NO_MAX_SIZE constant
default_expires_in => $cache_expires || '1 day',
auto_purge_interval => $auto_purge_interval || '6 hours',
}
) if $cache_root;
$DB{$name} = Ace->connect(-host=>$host,-port=>$port,-timeout=>50,@auth,@cache);
return $DB{$name};
}
=item PrintTop($object,$class,$title,@html_headers)
The PrintTop() 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.
Call it with one or more arguments. The arguments are:
$object An AceDB object. The navigation bar and title will be
customized for the object.
$class If no AceDB object is available, then you can pass
a string containing the AceDB class that this page is
designed to display.
$title A title to use for the HTML page and the first level-one
header. If not provided, a generic title "Report for
Object" is generated.
@html_headers Additional HTML headers to pass to the the CGI.pm
start_html.
=cut
# boilerplate for the top of the page
sub PrintTop {
my ($object,$class,$title,@additional_header_stuff) = @_;
return if $TOP++;
$class = $object->class if defined $object && ref($object);
$class ||= param('class') unless defined($title);
AceHeader();
$title ||= defined($object) ? "$class Report for: $object" : $class ? "$class Report" : ''
unless defined($title);
print start_html (
'-Title' => $title,
'-Style' => Style(),
@additional_header_stuff,
);
print Header();
print TypeSelector($object,$class) if defined $object;
print h1($title) if $title;
}
=item PrintBottom()
The PrintBottom() function outputs all the boilerplate at the bottom
of a typical AceBrowser page. If a user-defined footer is present in
( run in 1.746 second using v1.01-cache-2.11-cpan-99c4e6809bf )