%args>
$type => 'top'
%args>
<%perl>
# @menu is declared as mason global in the fcgi handler script,
# and set n a <%once> block in a syshandler.
# set selector code based on menu type
my $selector = $type eq 'top'
? q[class="sf-menu sf-js-enabled sf-shadow"]
: q[id="footerNavigation"];
# recursive closure with y-combinator to generate nested list
my $path = $r->path_info(''); # set path context
my $hash2menu = sub {
my ( $item, $code, $self ) = @_;
if ( defined($code) && $code ne q{} ) {
print qq[\n
\n];
}
else {
print qq[\n\n];
}
ELEMENT:
foreach my $this ( @$item ) {
# skip bottom menu elements if not flagged
next ELEMENT if $type ne 'top' && !exists($this->{bottom});
# determine if this is the currently selected menu item
my $regex = $this->{regex} || qr/^$/o;
# regex debugging
# print " ";
# determine if this is the 'current' menu item or not
if ( $path =~ $regex && $type eq 'top' ) {
print qq[- ];
print qq[$this->{title}];
}
else {
print qq[
- ];
print qq[$this->{title}];
}
# if there is a submenu, process it for top menu only
# submenus do not get selector codes
if ( defined( $this->{submenu} ) && $type eq 'top' ) {
$self->( $this->{submenu}, undef, $self );
}
# close this list item
print qq[
\n];
}
# put topbutton on footer menu only
if ( $type ne 'top' ) {
print qq[
],
qq[ \n];
}
# close the outer list
print qq[
\n];
};
# invoke the function
$hash2menu->( \@menu, $selector, $hash2menu );
%perl>