http://qs1969.pair.com?node_id=525326
Category: CGI
Author/Contact Info Stephen Dolan, stedolan@gmail.com
Description: With this module, you can put Perl code inline in your HTML files, like PHP does. For example:
use InlineWeb; <html> <body> {{ my $header=2; }} <h{[$header]}>Hello, World</h{[$header]}> </body> </html>
becomes
<html> <body> <h2>Hello, World</h2> </body> </html>
#!/usr/bin/perl
########## InlineWeb.pm
package InlineWeb;
use Filter::Simple;
FILTER{
my $program="";

while (1){
  if (/\G{{/gc){
    /\G({+)/gc;
    my $braces = $1;
    $braces=~tr/{/}/;
    /\G(.*?)}}$braces/gcs;
    $program.=$1.qq[;\n];
    next;
  }elsif (/\G{\[/gc){
    /\G(\[+)/gc;
    my $sq = $1;
    $sq=~tr:\[:\]:;
    /\G(.*?)$sq]}/gcs;
    $program.=q[print scalar ].$1.qq[;\n];
    next;
  }else{
    /\G(.*?)(?=({\[|{{|$))/gcs;
    my $txt = $1;
    my $delim = $2;
    $txt=~s:':\\':g;
    $program.=q[print '].$txt.qq[';\n];
    next if $delim;
  }
  last;
}
$_=$program;
return $done=1;
};
1;
Replies are listed 'Best First'.
Re: InlineWeb
by jeffa (Bishop) on Jan 24, 2006 at 21:58 UTC

    This code can handle simple substituions, but how do you handle conditions and loops? Includes? Nested wrappers? Most of the work i deal with involves database lookups and displaying rows of information, which is why i turn to modules such as Template-Toolkit, HTML::Mason, and HTML::Template.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      Yep, it works. Try:
      {{ for (@array){ }} <b>{[$_]}</b> {{ } }}
Re: InlineWeb
by Aristotle (Chancellor) on Jan 26, 2006 at 00:24 UTC
Re: InlineWeb
by wazoox (Prior) on Jan 25, 2006 at 15:38 UTC
    You should be interested in PLP.