X-Git-Url: http://git.shiar.net/perl/plp/.git/blobdiff_plain/b7a10718f1c1e5d0028cd367c337e9f85dc56618..4cbac41f4d1bef193cf955c6c854c8a9ed258119:/plp.cgi diff --git a/plp.cgi b/plp.cgi index 2158b60..a16835c 100755 --- a/plp.cgi +++ b/plp.cgi @@ -1,101 +1,38 @@ #!/usr/local/bin/perl - -use vars qw(%INTERNAL %get %post %fields %header %cookie %BLOCK $DEBUG $output); +use v5.6.0; +use PLP; use strict; -sub SendHeaders(){ - $INTERNAL{sentheaders} = 1; - print STDOUT "Content-Type: text/plain\n\n" if $DEBUG & 2; - print STDOUT map("$_: $header{$_}\n", keys %header), "\n"; -}; - -sub rawprint(@){ - print STDOUT (@_); -} - - -$ENV{PLP_VERSION} = '2.40'; -$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 "PLP: 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; -} - -require plp; - -($INTERNAL{dir} = $INTERNAL{file}) =~ s{^(.*)/(.*?)$}[$1]; -$ENV{FILE_NAME} = $2; -chdir $INTERNAL{dir}; - -($ENV{PLP_NAME} = $ENV{REQUEST_URI}) =~ s/\?.*$//; - - -$INTERNAL{qq} = ""; #^P -$INTERNAL{q} = ""; #^Q +die 'Wrong module version' if $PLP::VERSION ne '3.06'; -$INTERNAL{code} = ReadFile($INTERNAL{file}); - -while ($INTERNAL{code} =~ /<\((.*?)\)>/ ){ - (my $file = $1) =~ tr/[<>|//d; - $INTERNAL{code} =~ s//ReadFile($file)/e; -} - -$INTERNAL{code} =~ s(<:)($INTERNAL{q};)g; -$INTERNAL{code} =~ s(:>)(;\nprint q$INTERNAL{q})g; - -while ($INTERNAL{code} =~ /(<\[1(.*?)\]>(.*?)<\[2\]>(.*?)<\[3\]>)/s){ - $BLOCK{"$2-1"} = $3; - $BLOCK{"$2-2"} = $4; - $INTERNAL{code} =~ s///; #Redo last match +{ + @PLP::END = (); + $PLP::code = ''; + $PLP::sentheaders = 0; + $PLP::inA = 0; + $PLP::inB = 0; + $PLP::DEBUG = 1; + delete @ENV{ grep /^PLP_/, keys %ENV }; } -$INTERNAL{code} =~ s(\\\\\r?\n)()g; - -# This is bad and subject to removal. -$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; - -# This too is bad and subject to removal. -$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; +PLP::start(); -tie %header, 'PLP::Headers'; -tie *PLPOUT, 'PLP::Print'; - -# This is VERY bad, and will probably be removed. Use <: BEGIN { ... } -# :> instead -while ($INTERNAL{code} =~ s/<_(.*?)_>//s){ - $INTERNAL{pre} = $1; - { - no strict; - eval $INTERNAL{pre}; - if ($@ && $DEBUG & 1){ - print "\nDebug:\n $@"; - } - } -} - -#$INTERNAL{headers}->(); -select PLPOUT; { no strict; - eval $INTERNAL{code}; - SendHeaders() unless $INTERNAL{sentheaders}; - if ($@ && $DEBUG & 1){ - print "
Debug
", 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 $@ and $@ !~ /\cS\cT\cO\cP/; + eval { package PLP::Script; $_->() for reverse @PLP::END }; + PLP::error($@, 1) if $@ and $@ !~ /\cS\cT\cO\cP/; } + PLP::sendheaders() unless $PLP::sentheaders; + select STDOUT; + undef *{"PLP::Script::$_"} for keys %PLP::Script::; } +