-#!/usr/bin/perl
+#!/usr/local/bin/perl
+use v5.6.0;
+use PLP;
use strict;
-use vars qw($VERSION %INTERNAL %get %post %fields %header %cookie %BLOCK $DEBUG $output);
-$VERSION = '2.22';
-$DEBUG = 1;
-
-# We put most everything in %INTERNAL, just so the user won't screw it.
-# We could also have used packages, but let's keep it simple.
-
-$INTERNAL{file} = $ENV{PATH_TRANSLATED};
-unless (-e $INTERNAL{file}){
- $ENV{REDIRECT_STATUS} = '404';
- print STDERR "htmpl: Not found: $INTERNAL{file}\n";
-
- #Change this if you have an error handling script.
- print `/vhost/COMMON/err.cgi` || "Status: 404 Not found\n\nFile not found";
-
- exit;
-}
-
-($INTERNAL{dir} = $INTERNAL{file}) =~ s{^(.*)/.*?$}[$1];
-chdir $INTERNAL{dir};
-
-($ENV{PLP_NAME} = $ENV{REQUEST_URI}) =~ s/\?.*$//;
-
-use plp;
-
-$INTERNAL{qq} = "\10"; #^P
-$INTERNAL{q} = "\17"; #^Q
-
-$header{'Content-Type'} = 'text/html';
-$header{Status} = '200 OK';
-
-$INTERNAL{code} = ReadFile($INTERNAL{file});
-
-while ($INTERNAL{code} =~ /<\((.*?)\)>/ ){
- ($INTERNAL{file} = $1) =~ s/[<>\|]//g;
- $INTERNAL{code} =~ s//ReadFile($INTERNAL{file})/e;
-}
-
-$INTERNAL{code} =~ s(<:)($INTERNAL{q};)g;
-$INTERNAL{code} =~ s(:>)(;\nprint q$INTERNAL{q})g;
-
-while ($INTERNAL{code} =~ /(<\[1(.*?)\]>(.*?)<\[2\]>(.*?)<\[3\]>)/s){
- $INTERNAL{naam} = $2;
- $BLOCK{"$INTERNAL{naam}-1"} = $3;
- $BLOCK{"$INTERNAL{naam}-2"} = $4;
- $INTERNAL{code} =~ s///; #Redo last match
-}
-$INTERNAL{code} =~ s(\\\\\r?\n)()g;
-$INTERNAL{code} =~ s(<\[([^>]*?):(.*?)\]>)($BLOCK{"${1}-1"}$2$BLOCK{"${1}-2"})g;
-$INTERNAL{code} =~ s(<\[(?!/)(.*?)\]>)($BLOCK{"${1}-1"})g;
-$INTERNAL{code} =~ s(<\[/(.*?)\]>)($BLOCK{"${1}-2"})g;
-
-
-$INTERNAL{code} =~ s(<{[ \08\09]*)($INTERNAL{q};print qq$INTERNAL{qq})g;
-$INTERNAL{code} =~ s([ \08\09]*}>)($INTERNAL{qq};print q$INTERNAL{q})g;
-$INTERNAL{code} = "print q$INTERNAL{q}$INTERNAL{code}$INTERNAL{q};";
-
-$INTERNAL{code} =~ s{print qq$INTERNAL{qq}$INTERNAL{qq};}[]g;
-$INTERNAL{code} =~ s{print q$INTERNAL{q}$INTERNAL{q};}[]g;
-
-
-while ($INTERNAL{code} =~ s/<_(.*?)_>//s){
- $INTERNAL{pre} = $1;
- {
- no strict;
- eval $INTERNAL{pre};
- if ($@ && $DEBUG){
- print "\nDebug:\n $@";
- }
- }
-}
-
-print "\n\n" if $DEBUG == 2;
+die 'Wrong module version' if $PLP::VERSION ne '3.05';
{
- my %HEADER;
- for (sort keys %header){ # Sort, so lowercase and underscores come first)
- my $copy = $_;
- tr/_/-/;
- s/\b(\w)(\w*)/\U$1\E\L$2\E/g;
- $HEADER{$_} = $header{$copy};
- }
- for (keys %HEADER){
- print "$_: $HEADER{$_}\n";
- }
- print "\n";
+ $PLP::code = '';
+ $PLP::sentheaders = 0;
+ $PLP::inA = 0;
+ $PLP::inB = 0;
+ $PLP::DEBUG = 1;
+ delete @ENV{ grep /^PLP_/, keys %ENV };
}
+PLP::start();
+
{
no strict;
- eval $INTERNAL{code};
- if ($@ && $DEBUG){
- print "<hr><b>Debug</b><br>", Entity($@);
+ PLP::Fields::doit();
+ {
+ package PLP::Script;
+ *headers = \%header;
+ *cookies = \%cookie;
+ PLP::Functions->import();
+ # No lexicals may exist at this point.
+ eval qq{package PLP::Script; $PLP::code};
}
+ PLP::error($@, 1) if $@;
+ select STDOUT;
+ undef *{"PLP::Script::$_"} for keys %PLP::Script::;
+ PLP::sendheaders() unless $PLP::sentheaders;
}
+