Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

InlineWeb

by Anonymous Monk
on Jan 24, 2006 at 21:49 UTC ( #525326=sourcecode: print w/replies, xml ) Need Help??
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://525326]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2022-07-02 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (103 votes). Check out past polls.

    Notices?