Introduction to Mason 19

Filtering Tricks: Highlight the Current URI

<&| /lib/highlight_current_link.mas &>
 <a href="/">Home</a>
 <a href="/news/">News</a>
 <a href="/events/">Events</a>
</&>
<%init>
# remember that $r global?
my $uri = $r->uri;

# Strip off any filename in the path
$uri =~ s{[^/]+$}{};

# Retrieve our caller's output.
my $content = $m->content;

# Find the matching URI in the content,
# and replace it with bold tags
s{<a href="$uri">([^<]+)</a>}
 {<b>$1</b>};

# output the altered content
$m->print($content);
</%init>