v3.01 release
[perl/plp/.git] / PLP.pm
diff --git a/PLP.pm b/PLP.pm
index 7d3bf99f5a3ba97d1f14fa1539664d5f936f4a89..704870c8f697fc5557d3f09e3c8d63b8e6892168 100644 (file)
--- a/PLP.pm
+++ b/PLP.pm
@@ -2,7 +2,7 @@ package PLP;
 
 # Not to be used without the CGI script;
 
-our $VERSION = '3.00';
+our $VERSION = '3.01';
 
 use PLP::Functions ();
 use PLP::Fields;
@@ -17,7 +17,9 @@ sub SendHeaders () {
 };
 
 sub source {
-    my ($path, $level) = @_;
+    my ($path, $level, $linespec) = @_;
+    $level = 0 if not defined $level;
+    $linespec = '1' if not defined $linespec;
     our ($inA, $inB);
     (my $file = $path) =~ s[.*/][];
     my $source = $level
@@ -27,7 +29,7 @@ sub source {
     local *SOURCE;
     open SOURCE, $path or return $level
        ? qq{\cQ; die qq[Can't open "\Q$path\E" (\Q$!\E)]; print q\cQ}
-       : qq{\ndie qq[Can't open "\Q$path\e" (\Q$!\E)];};
+       : qq{\n#line $linespec\ndie qq[Can't open "\Q$path\E" (\Q$!\E)];};
     LINE: while (defined (my $line = <SOURCE>)) {
        $linenr++;
        for (;;) {
@@ -68,5 +70,25 @@ sub source {
     return $source;
 }
 
+sub error {
+    my ($error, $type) = @_;
+    if (not defined $type or $type < 100) {
+       PLP::sendheaders unless $PLP::sentheaders;
+       $error =~ s/([<&>])/'&#' . ord($1) . ';'/ge;
+       print qq{<table border=1 class="PLPerror"><tr><td>},
+             qq{<span><b>Debug information:</b><BR>$error</td></tr></table>};
+    } else {
+       select STDOUT;
+       my ($short, $long) = @{ +{
+           404 => [ 'Not Found', "The requested URL $ENV{REQUEST_URI} was not found on this server." ],
+           403 => [ 'Forbidden', "You don't have permission to access $ENV{REQUEST_URI} on this server." ],
+       }->{$type} };
+       print "Status: $type\nContent-Type: text/html\n\n",
+             qq{<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n},
+             "<html><head>\n<title>--$type $short</title>\n</head></body>\n",
+             "<h1>$short</h1>\n$long<p>\n<hr>\n$ENV{SERVER_SIGNATURE}</body></html>";
+    }
+}
+
 1;