* Randal L. Schwartz <[EMAIL PROTECTED]> [2002-04-18 10:20]:
> Maybe we need a "patterns in TT" wiki or something.  Heck, we need
> a wiki in TT as well. :)

I started writing something like this, as a filter.  The entirety of it
was, basically:

  sub wiki_factory {
      my $base = shift;

      return sub {
          my $text = shift;
          $text =~ s{ \b([A-Z]\w+)\b }
                    {<a href="$base$1">$1</a>}gx;

          return $text;
      };
  }

  my $tf = Template->new({
      FILTERS => { wiki => wiki_factory("/process.tt?name=") }
  });

It's used a static filter, even though it looks like a dynamic
filter:

  [% FILTER wiki %]
  I am some WikiText.
  [% END %]

Gives you the predictible:

  I am some <a href="/process.tt?name=WikiText">WikiText</a>.

Not very exciting, or robust.  But it shows that the implementation is
straightforward.

Something like this might be more interesting:

  sub wiki_factory {
      my $sub = shift;

      return sub {
          my $text = shift;
          $text =~ s{ \b([A-Z]\w+ )\b}
                    { $sub->($1) }xeg

          return $text;
      };
  }

(darren)

-- 
Every program has at least one bug, and at least one line of code
that can be removed.  Therefore, by induction, every program can
be reduced to one line of code that doesn't work.


Reply via email to