AcePerl
view release on metacpan or search on metacpan
Ace/Browser/AceSubs.pm view on Meta::CPAN
needed) and then tack the parameters onto the end.
A typical call is:
$url = ResolveUrl('/cgi-bin/ace/generic/tree','name=fred;class=Author');
This function is not exported by default.
=cut
sub ResolveUrl {
my ($url,$param) = @_;
my ($main,$query,$frag) = $url =~ /^([^?\#]+)\??([^\#]*)\#?(.*)$/ if defined $url;
$main ||= '';
if (!defined $APACHE_CONF) {
$APACHE_CONF = eval { Apache->request->dir_config('AceBrowserConf') } ? 1 : 0;
}
$main = Configuration()->resolvePath($main) unless $main =~ m!^/!;
if (my $id = get_symbolic()) {
$main .= "/$id" unless $main =~ /$id/ or $APACHE_CONF;
}
$main .= "?$query" if $query; # put the query string back
$main .= "?$param" if $param and !$query;
$main .= ";$param" if $param and $query;
$main .= "#$frag" if $frag;
return $main;
}
# A consistent stylesheet across pages
sub Style {
my $stylesheet = Configuration()->Stylesheet;
return { -src => $stylesheet };
}
=item $boolean = Toggle($section,[$label,$object_count,$add_plural,$add_count])
=item ($link,$bool) = Toggle($section,$label,$object_count,$add_plural,$add_count)
The Toggle() subroutine makes it easy to create HTML sections that
open and close when the user selects a toggle icon (a yellow
triangle).
Toggle() 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:
$label The text of the generated link, for example "sequence"
$object_count The number of objects that opening the section will reveal
$add_plural If true, the label will be pluralized when
appropriate
$add_count If true, the label will have the object count added
when appropriate
In a scalar context, Toggle() 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.
In a list context, Toggle() 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.
This example indicates typical usage:
my $sequence = GetAceObject();
print "sequence name = ",$sequence,"\n";
print "sequence clone = ",$sequence->Clone,"\n";
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)
( run in 2.519 seconds using v1.01-cache-2.11-cpan-d8267643d1d )