From 693387f6e6cf5efde73b10242253bb38baf1612a Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Sat, 31 Mar 2007 02:11:22 +0200 Subject: [PATCH] code cleanup (mainly improving comments) --- PLP.pm | 43 +++++++++++++++---------------------------- PLP/FAQ.pod | 6 +++++- PLP/Fields.pm | 5 ++--- PLP/Functions.pm | 12 ++++++------ PLP/Tie/Delay.pm | 7 +++---- PLP/Tie/Headers.pm | 5 ++--- PLP/Tie/Print.pm | 5 ++--- 7 files changed, 35 insertions(+), 48 deletions(-) diff --git a/PLP.pm b/PLP.pm index 8826b28..c78af41 100644 --- 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 blocks won't work properly. You should use C instead. Note that this is a not diff --git a/PLP/FAQ.pod b/PLP/FAQ.pod index 2aac805..da4fbe7 100644 --- a/PLP/FAQ.pod +++ b/PLP/FAQ.pod @@ -1,4 +1,8 @@ -=head1 Frequently Asked Questions about PLP +=head1 NAME + +PLP::FAQ - Frequently Asked Questions about PLP + +=head1 FAQ =over 10 diff --git a/PLP/Fields.pm b/PLP/Fields.pm index 3c09977..7120c06 100644 --- a/PLP/Fields.pm +++ b/PLP/Fields.pm @@ -1,6 +1,5 @@ -#----------------------# - package PLP::Fields; -#----------------------# +package PLP::Fields; + use strict; # Has only one function: doit(), which ties the hashes %get, %post, %fields and %header in diff --git a/PLP/Functions.pm b/PLP/Functions.pm index debb767..ea30488 100644 --- a/PLP/Functions.pm +++ b/PLP/Functions.pm @@ -1,6 +1,5 @@ -#-------------------------# - package PLP::Functions; -#-------------------------# +package PLP::Functions; + use base 'Exporter'; use Fcntl qw(:flock); use strict; @@ -16,7 +15,7 @@ sub Include ($) { local $@; eval 'package PLP::Script; ' . PLP::source($PLP::file, 0, join ' ', (caller)[2,1]); if ($@) { - PLP::Functions::exit if $@ =~ /\cS\cT\cO\cP/; + PLP::Functions::exit() if $@ =~ /\cS\cT\cO\cP/; PLP::error($@, 1); } } @@ -67,9 +66,9 @@ sub Entity (@) { return defined wantarray ? (wantarray ? @$ref : "@$ref") : undef; } -# Browsers do s/ /+/ - I don't care about RFC's, but I do care about real-life -# situations. sub DecodeURI (@) { + # Browsers do s/ /+/ - I don't care about RFC's, but I do care about real-life + # situations. my @r; local $_; for (@_) { @@ -85,6 +84,7 @@ sub DecodeURI (@) { } return defined wantarray ? (wantarray ? @r : "@r") : undef; } + sub EncodeURI (@) { my @r; local $_; diff --git a/PLP/Tie/Delay.pm b/PLP/Tie/Delay.pm index ea136b8..1200651 100644 --- a/PLP/Tie/Delay.pm +++ b/PLP/Tie/Delay.pm @@ -1,6 +1,5 @@ -#--------------------------# - package PLP::Tie::Delay; -#--------------------------# +package PLP::Tie::Delay; + use strict; no strict 'refs'; @@ -69,7 +68,7 @@ sub NEXTKEY { } sub UNTIE { } -sub DESTORY { } +sub DESTROY { } 1; diff --git a/PLP/Tie/Headers.pm b/PLP/Tie/Headers.pm index e8f961c..f6c4319 100644 --- a/PLP/Tie/Headers.pm +++ b/PLP/Tie/Headers.pm @@ -1,6 +1,5 @@ -#----------------------------# - package PLP::Tie::Headers; -#----------------------------# +package PLP::Tie::Headers; + use strict; use Carp; diff --git a/PLP/Tie/Print.pm b/PLP/Tie/Print.pm index 4c6983f..3d5027a 100644 --- a/PLP/Tie/Print.pm +++ b/PLP/Tie/Print.pm @@ -1,6 +1,5 @@ -#--------------------# - package PLP::Tie::Print; -#--------------------# +package PLP::Tie::Print; + use strict; =head1 PLP::Tie::Print -- 2.30.0