code cleanup (mainly improving comments)
[perl/plp/.git] / PLP.pm
diff --git a/PLP.pm b/PLP.pm
index 36951ac95a9d5d16201db6f62fddd89da6095b95..c78af4163f560d7ef16feb7ebe4fd104aa2431bc 100644 (file)
--- a/PLP.pm
+++ b/PLP.pm
@@ -1,6 +1,4 @@
-#--------------#
-  package PLP;
-#--------------#
+package PLP;
 
 use v5.6;
 
@@ -36,24 +34,18 @@ sub sendheaders () {
     our $sentheaders = 1;
     print STDOUT "Content-Type: text/plain\n\n" if $PLP::DEBUG & 2;
     print STDOUT map("$_: $PLP::Script::header{$_}\n", keys %PLP::Script::header), "\n";
-};
+}
 
-# Given a filename and optional level (level should be 0 if the caller isn't
-# source() itself), and optional linespec (used by PLP::Functions::Include),
-# this function parses a PLP file and returns Perl code, ready to be eval'ed
 {
-    my %cached; # Conceal cached sources
-    
-    # %cached = (
-    #  $filename => [
-    #      [ dependency, dependency, dependency ], # <(...)>
-    #      'source',
-    #      -M
-    #  ]
-    # );
+    my %cached; # Conceal cached sources: ( path => [ [ deps ], source, -M ] )
     
+    # Given a filename and optional level (level should be 0 if the caller isn't
+    # source() itself), and optional linespec (used by PLP::Functions::Include),
+    # this function parses a PLP file and returns Perl code, ready to be eval'ed
     sub source {
        my ($file, $level, $linespec, $path) = @_;
+       # $file is displayed, $path is used. $path is constructed from $file if
+       # not given.
        $level = 0      if not defined $level;
        $linespec = '1' if not defined $linespec;
        
@@ -150,8 +142,7 @@ sub sendheaders () {
     }
 }
 
-# Handles errors, uses the sub reference $PLP::ERROR that gets two arguments:
-# the error message in plain text, and the error message with html entities
+# Handles errors, uses subref $PLP::ERROR (default: \&_default_error)
 sub error {
     my ($error, $type) = @_;
     if (not defined $type or $type < 100) {
@@ -204,8 +195,7 @@ sub clean {
 #  o  Set $ENV{PLP_*} and makes PATH_INFO if needed
 #  o  Change the CWD
 
-# This sub is meant for CGI requests only, and takes apart PATH_TRANSLATED
-# to find the file.
+# CGI initializer: parses PATH_TRANSLATED
 sub cgi_init {
     my $path = $ENV{PATH_TRANSLATED};
     $ENV{PLP_NAME} = $ENV{PATH_INFO};
@@ -240,8 +230,7 @@ sub cgi_init {
     $PLP::code = PLP::source($file, 0, undef, $path);
 }
 
-# This is the mod_perl initializer.
-# Returns 0 on success.
+# mod_perl initializer: returns 0 on success, Apache error code on failure
 sub mod_perl_init {
     my $r = shift;
     
@@ -294,11 +283,7 @@ sub start {
 #    The above does not work. TODO - find out why not.
 }
 
-# This is run by the CGI script.
-# The CGI script is just:
-#   #!/usr/bin/perl
-#   use PLP;
-#   PLP::everything();
+# This is run by the CGI script. (#!perl \n use PLP; PLP::everything;)
 sub everything {
     clean();
     cgi_init();
@@ -487,7 +472,9 @@ efficiency. To set headers, you must assign to C<$header{ $header_name}> before
 any output. This means the opening C<< <: >> have to be the first characters in
 your document, without any whitespace in front of them. If you start output and
 try to set headers later, an error message will appear telling you on which
-line your output started.
+line your output started. An alternative way of setting headers is using Perl's
+BEGIN blocks. BEGIN blocks are executed as soon as possible, before anything
+else.
 
 Because the interpreter that mod_perl uses never ends, C<END { }> blocks won't
 work properly. You should use C<PLP_END { };> instead. Note that this is a not
@@ -514,7 +501,7 @@ responsibility.
 
 =head1 AUTHOR
 
-Juerd Waalboer <juerd@juerd.nl>
+Juerd Waalboer <juerd@cpan.org>
 
 =head1 SEE ALSO