<%doc> Usage: <& view_source.html &> When called, with no arguments, inserts a link into the page along with the text "View Source". When called with argument caller displays the specified component with its syntax highlighted. When called with caller => 'self', inserts the calling component's source inline. required: none optional: caller => component name or 'self' view_source => string to insert as text of link, default is 'View Source' % unless (defined $caller) { <% $view_source %> % } <%init> if (defined $caller) { my $compiler; if ($caller eq 'self') { $compiler = Syntax::Highlight::Mason->new (preamble => '
',
       postamble => '
'); $caller = $m->request_comp->path if $caller eq 'self'; } else { $compiler = Syntax::Highlight::Mason->new(); } my $comp = $m->fetch_comp($caller); my $file = $comp->source_file($comp); local $/ = undef; open(my $io,$file) or die "$! at $file"; my $source = <$io>; close($io); $m->print($compiler->compile($source)); } <%args> $caller => undef $view_source => 'View Source' <%once> use Syntax::Highlight::Mason;