From 0037699647feb915a9091a57af1a264777bcaecb Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 28 May 2008 11:41:13 +0000 Subject: [PATCH 01/16] keep SCRIPT_* environment variables in CGI These are now identical to their PLP_* counterparts, and should be used instead for familiarity (why rename for no apparant reason; SCRIPT_* now contain their expected values so no reason to suggest otherwise). Apache already has both. --- lib/PLP.pm | 8 ++++++-- lib/PLP/Backend/CGI.pm | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/PLP.pm b/lib/PLP.pm index 03c4acb..acf3871 100644 --- a/lib/PLP.pm +++ b/lib/PLP.pm @@ -364,14 +364,18 @@ These are described in L. =over 22 -=item $ENV{PLP_NAME} +=item $ENV{SCRIPT_NAME} The URI of the PLP document, without the query string. (Example: C) -=item $ENV{PLP_FILENAME} +Used to be renamed to C<$ENV{PLP_NAME}>, which is still provided but deprecated. + +=item $ENV{SCRIPT_FILENAME} The filename of the PLP document. (Example: C) +C<$ENV{PLP_SCRIPT}> also still provided but deprecated. + =item $PLP::VERSION The version of PLP. diff --git a/lib/PLP/Backend/CGI.pm b/lib/PLP/Backend/CGI.pm index 5d45500..0005762 100644 --- a/lib/PLP/Backend/CGI.pm +++ b/lib/PLP/Backend/CGI.pm @@ -48,7 +48,6 @@ sub init { } delete @ENV{ - qw(SCRIPT_NAME SCRIPT_FILENAME), grep /^REDIRECT_/, keys %ENV }; -- 2.30.0 From fa3bff5b76161e1573a47623d0737a8e3a5d0dd9 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 29 May 2008 16:58:32 +0000 Subject: [PATCH 02/16] improve lighttpd configuration samples Use the merge (+=) syntax so the user doesn't have to integrate any existing options, and can simply add the snippet as is (even as a seperate include, especially easy in a Debian setup). Extend backend configuration examples with options for a directory index of index.plp, and (static) source rejection. --- lib/PLP.pm | 14 +++++--------- lib/PLP/Backend/CGI.pm | 10 +++++----- lib/PLP/Backend/FastCGI.pm | 18 +++++++++--------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/lib/PLP.pm b/lib/PLP.pm index acf3871..e3fe961 100644 --- a/lib/PLP.pm +++ b/lib/PLP.pm @@ -260,15 +260,11 @@ PLP - Perl in HTML pages F configuration using L: - server.modules = ( - "mod_fastcgi", - ) - fastcgi.server = ( - ".plp" => (( - "bin-path" => "/usr/bin/perl -MPLP::Backend::FastCGI", - "socket" => "/tmp/fcgi-plp.socket", - )), - ) + server.modules += ("mod_fastcgi") + fastcgi.server += (".plp" => (( + "bin-path" => "/usr/bin/perl -MPLP::Backend::FastCGI", + "socket" => "/tmp/fcgi-plp.socket", + ))) =head2 Apache installation diff --git a/lib/PLP/Backend/CGI.pm b/lib/PLP/Backend/CGI.pm index 0005762..1e8def9 100644 --- a/lib/PLP/Backend/CGI.pm +++ b/lib/PLP/Backend/CGI.pm @@ -93,12 +93,12 @@ Or install the C included with PLP. =head2 Lighttpd -Usually in F: -enable I (add/outcomment in server.modules), and add: +Add this to your configuration file (usually F): - cgi.assign = ( - ".plp" => "/foo/bar/plp.cgi", - ) + server.modules += ("mod_cgi") + cgi.assign += (".plp" => "/foo/bar/plp.cgi") + server.indexfiles += ("index.plp") + static-file.exclude-extensions += (".plp") =head2 Apache diff --git a/lib/PLP/Backend/FastCGI.pm b/lib/PLP/Backend/FastCGI.pm index b3c8c3a..4f14863 100644 --- a/lib/PLP/Backend/FastCGI.pm +++ b/lib/PLP/Backend/FastCGI.pm @@ -33,15 +33,15 @@ PLP::Backend::FastCGI - FastCGI interface for PLP =head2 Lighttpd -Edit the configuration file (usually F) -to enable I (add/outcomment in server.modules), and add: - - fastcgi.server = ( - ".plp" => (( - "bin-path" => "/usr/bin/perl -MPLP::Backend::FastCGI", - "socket" => "/tmp/fcgi-plp.socket", - )), - ) +Add this to your configuration file (usually F): + + server.modules += ("mod_fastcgi") + fastcgi.server += (".plp" => (( + "bin-path" => "/usr/bin/perl -MPLP::Backend::FastCGI", + "socket" => "/tmp/fcgi-plp.socket", + ))) + server.indexfiles += ("index.plp") + static-file.exclude-extensions += (".plp") =head2 Apache -- 2.30.0 From ec7d20c2e33d8c240c6687adecbefa92410a9b41 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 28 May 2008 07:09:41 +0000 Subject: [PATCH 03/16] v3.20 release --- Changes | 10 ++++++++++ MANIFEST | 6 ++++++ lib/PLP.pm | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 23aaab8..4d7a9b0 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,13 @@ +3.20 - May 29, 2008: +- MIT license +- FastCGI support +- mod_perl2 support (but not recommended; read docs!) +- Lighttpd and Apache2 support (either CGI or FastCGI) +- Seperate modules for backend-specific code +- Documentation updates +- Fix html of default error message +- Example plpinfo.plp, modeled after phpinfo + 3.19 - September 15, 2005: - New maintainer - Send headers when using C to start output diff --git a/MANIFEST b/MANIFEST index d5c325f..67ec531 100644 --- a/MANIFEST +++ b/MANIFEST @@ -8,10 +8,16 @@ plp.vim lib/PLP.pm lib/PLP/Fields.pm lib/PLP/Functions.pm +lib/PLP/Backend/CGI.pm +lib/PLP/Backend/FastCGI.pm +lib/PLP/Backend/Apache.pm lib/PLP/Tie/Delay.pm lib/PLP/Tie/Headers.pm lib/PLP/Tie/Print.pm lib/PLP/FAQ.pod lib/PLP/HowTo.pod bin/plp.cgi +bin/plp.fcgi t/Functions.t +t/pod.t +eg/plpinfo.plp diff --git a/lib/PLP.pm b/lib/PLP.pm index e3fe961..f1ad4f8 100644 --- a/lib/PLP.pm +++ b/lib/PLP.pm @@ -13,7 +13,7 @@ use File::Spec; use strict; -our $VERSION = '3.19'; +our $VERSION = '3.20'; # Subs in this package: # _default_error($plain, $html) Default error handler -- 2.30.0 From 566d87bdea774c73931c276af6a5f6ebaadaf3f7 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 28 May 2008 08:36:52 +0000 Subject: [PATCH 04/16] add a few todo entries --- TODO | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/TODO b/TODO index ea43eec..bd73751 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,10 @@ +In no particular order or significance: - lvalue %cookie (similar to AddCookie) - multipart posts [3.21] - install rules for servers - %header takes array ref +- test plp parsing +- redisplay include errors [3.21] +- object instead of $PLP:: +- document utf8 io +- update plp.shiar.net, maybe reg plpage.nl or something -- 2.30.0 From 2948db1f40f3b7c126732e0e662a28ffb43008b0 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 29 May 2008 20:04:40 +0200 Subject: [PATCH 05/16] fix META.yml syntax Bah, used lists where simple maps were expected (though this syntax is used with optional_features and another project of mine, so slightly excusable except for missing tests). Also, Test::YAML::Meta wants keys of optional_features to conform to /^[a-z_-]+$/. This isn't mentioned anywhere in the specifications, but a passing test is more useful than a minor stylistic detail. Finally, while 'repository' apparantly still isn't an official resources key, it _is_ mentioned as such (lowercased) in the specs. In fact everyone seems to use it like that, so I guess being technically incorrect will be supported better. --- Changes | 2 ++ META.yml | 20 ++++++++++---------- t/meta.t | 9 +++++++++ 3 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 t/meta.t diff --git a/Changes b/Changes index 4d7a9b0..258d9b2 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,5 @@ +- Fix META.yml syntax + 3.20 - May 29, 2008: - MIT license - FastCGI support diff --git a/META.yml b/META.yml index b6a10c5..de8628c 100644 --- a/META.yml +++ b/META.yml @@ -8,24 +8,24 @@ author: license: mit resources: homepage: http://plp.shiar.net/ - Repository: git://git.shiar.net/plp + repository: git://git.shiar.net/plp requires: - - perl: 5.6.0 + perl: 5.6.0 recommends: - - CGI::Cookie: 0 + CGI::Cookie: 0 optional_features: - mod_perl: description: mod_perl backend for Apache requires: Apache::Constants: 0 - - mod_perl2: + - mod_perl-two: description: mod_perl2 backend for Apache - requires: - Apache2::Const: 0 - Apache2::RequestRec: 0 - Apache2::RequestUtil: 0 - Apache2::RequestIO: 0 - - FastCGI: + requires: + Apache2::Const: 0 + Apache2::RequestRec: 0 + Apache2::RequestUtil: 0 + Apache2::RequestIO: 0 + - fastcgi: description: FastCGI backend requires: FCGI: 0.61 diff --git a/t/meta.t b/t/meta.t new file mode 100644 index 0000000..8d65d18 --- /dev/null +++ b/t/meta.t @@ -0,0 +1,9 @@ +use strict; +use warnings; + +use Test::More; +eval 'use Test::YAML::Meta'; +plan skip_all => "Test::YAML::Meta required for testing META.yml" if $@; + +meta_yaml_ok(); + -- 2.30.0 From e994dec90ddc213dccf471686d8abf04c7f9ad40 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 29 May 2008 20:13:29 +0000 Subject: [PATCH 06/16] improve plpinfo page Fix version display in Perl >= 5.10: $^V no longer consists out of single characters for each level. Use the recommended practise of formatting with sprintf (see perlvar) which seems to work in at least 5.6.1 (ie good enough). Add 'Perl API' version analogous to 'PHP API' in phpinfo(). Some fallbacks if variables are empty or undefined. --- eg/plpinfo.plp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/eg/plpinfo.plp b/eg/plpinfo.plp index 748d40c..9b3b704 100644 --- a/eg/plpinfo.plp +++ b/eg/plpinfo.plp @@ -25,9 +25,10 @@ use Config; printf "%s%s\n", @$_ for ( ["System" => qx(uname -snrvm)], ["Server API" => $PLP::interface ? $PLP::interface : "?"], - ["Perl" => join ".", map ord, split //, $^V], - ["Build Date" => $Config{cf_time}], - ["Debug Build" => $^P ? "yes" : "no"], + ["Perl" => sprintf '%vd', $^V], + ["Perl API" => $Config{api_versionstring} || "?"], + ["Build Date" => $Config{cf_time} || "?"], + ["Debug Build" => $^P ? "yes ($^P)" : "no"], ["Thread Safety" => $Config{usethreads} ? "enabled" : "disabled"], ["Include Path" => join "; ", @INC], ); @@ -40,13 +41,13 @@ printf "%s%s\n", @$_ for ( my %modules; s!/!::!g, s/\.pm$// and $modules{$_} = $_->VERSION || "" for keys %INC; printf "%s%s\n", @$_ for ( - ["Modules" => join "
\n", + ["Loaded Modules" => join "
\n", map "$_ $modules{$_}", sort grep /^PLP/, keys %modules ], - ["Debug Output" => join "; ", + ["Debug Output" => join("; ", $PLP::DEBUG & 1 ? "run-time errors" : (), $PLP::DEBUG & 2 ? "headers" : (), - ], + ) || "disabled"], ["Caching" => $PLP::use_cache ? "on" : "off"], #TODO ); :> -- 2.30.0 From d9f3acb221a71e094318c7b5d3809aa81dbb5bb3 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 29 May 2008 20:27:33 +0000 Subject: [PATCH 07/16] use warnings in all modules --- Changes | 1 + lib/PLP.pm | 1 + lib/PLP/Backend/Apache.pm | 1 + lib/PLP/Backend/CGI.pm | 1 + lib/PLP/Backend/FastCGI.pm | 1 + lib/PLP/Fields.pm | 1 + lib/PLP/Functions.pm | 6 ++++-- lib/PLP/Tie/Delay.pm | 1 + lib/PLP/Tie/Headers.pm | 1 + lib/PLP/Tie/Print.pm | 1 + 10 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 258d9b2..f02aa32 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ +- All modules use warnings - Fix META.yml syntax 3.20 - May 29, 2008: diff --git a/lib/PLP.pm b/lib/PLP.pm index f1ad4f8..42866dc 100644 --- a/lib/PLP.pm +++ b/lib/PLP.pm @@ -12,6 +12,7 @@ use File::Basename (); use File::Spec; use strict; +use warnings; our $VERSION = '3.20'; diff --git a/lib/PLP/Backend/Apache.pm b/lib/PLP/Backend/Apache.pm index 62caadc..6964b56 100644 --- a/lib/PLP/Backend/Apache.pm +++ b/lib/PLP/Backend/Apache.pm @@ -1,6 +1,7 @@ package PLP::Backend::Apache; use strict; +use warnings; our $VERSION = '1.00'; diff --git a/lib/PLP/Backend/CGI.pm b/lib/PLP/Backend/CGI.pm index 1e8def9..10b9b45 100644 --- a/lib/PLP/Backend/CGI.pm +++ b/lib/PLP/Backend/CGI.pm @@ -1,6 +1,7 @@ package PLP::Backend::CGI; use strict; +use warnings; our $VERSION = '1.02'; diff --git a/lib/PLP/Backend/FastCGI.pm b/lib/PLP/Backend/FastCGI.pm index 4f14863..92dda74 100644 --- a/lib/PLP/Backend/FastCGI.pm +++ b/lib/PLP/Backend/FastCGI.pm @@ -1,6 +1,7 @@ package PLP::Backend::FastCGI; use strict; +use warnings; use PLP::Backend::CGI (); use FCGI; diff --git a/lib/PLP/Fields.pm b/lib/PLP/Fields.pm index 7f07c4e..01f3baf 100644 --- a/lib/PLP/Fields.pm +++ b/lib/PLP/Fields.pm @@ -1,6 +1,7 @@ package PLP::Fields; use strict; +use warnings; # Has only one function: doit(), which ties the hashes %get, %post, %fields # and %header in PLP::Script. Also generates %cookie immediately. diff --git a/lib/PLP/Functions.pm b/lib/PLP/Functions.pm index 28815cd..18318ad 100644 --- a/lib/PLP/Functions.pm +++ b/lib/PLP/Functions.pm @@ -1,8 +1,10 @@ package PLP::Functions; -use base 'Exporter'; -use Fcntl qw(:flock); use strict; +use warnings; + +use Exporter qw(import); +use Fcntl qw(:flock); our @EXPORT = qw/Entity DecodeURI EncodeURI Include include PLP_END AddCookie ReadFile WriteFile AutoURL Counter exit/; diff --git a/lib/PLP/Tie/Delay.pm b/lib/PLP/Tie/Delay.pm index bf7a7a7..8be53af 100644 --- a/lib/PLP/Tie/Delay.pm +++ b/lib/PLP/Tie/Delay.pm @@ -2,6 +2,7 @@ package PLP::Tie::Delay; use strict; no strict 'refs'; +use warnings; =head1 PLP::Tie::Delay diff --git a/lib/PLP/Tie/Headers.pm b/lib/PLP/Tie/Headers.pm index df41fbe..ef12491 100644 --- a/lib/PLP/Tie/Headers.pm +++ b/lib/PLP/Tie/Headers.pm @@ -1,6 +1,7 @@ package PLP::Tie::Headers; use strict; +use warnings; use Carp; =head1 PLP::Tie::Headers diff --git a/lib/PLP/Tie/Print.pm b/lib/PLP/Tie/Print.pm index ef537a0..a2d22dd 100644 --- a/lib/PLP/Tie/Print.pm +++ b/lib/PLP/Tie/Print.pm @@ -1,6 +1,7 @@ package PLP::Tie::Print; use strict; +use warnings; =head1 PLP::Tie::Print -- 2.30.0 From b485fa6bb934e79d44a1be1b5e41e31f4e7129b1 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 29 May 2008 20:28:58 +0000 Subject: [PATCH 08/16] add version numbers to versionless modules --- Changes | 2 +- lib/PLP/Fields.pm | 2 ++ lib/PLP/Functions.pm | 1 + lib/PLP/Tie/Delay.pm | 2 ++ lib/PLP/Tie/Headers.pm | 2 ++ lib/PLP/Tie/Print.pm | 2 ++ 6 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index f02aa32..78da9d1 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,4 @@ -- All modules use warnings +- All modules use warnings and contain a $VERSION - Fix META.yml syntax 3.20 - May 29, 2008: diff --git a/lib/PLP/Fields.pm b/lib/PLP/Fields.pm index 01f3baf..cd68e36 100644 --- a/lib/PLP/Fields.pm +++ b/lib/PLP/Fields.pm @@ -3,6 +3,8 @@ package PLP::Fields; use strict; use warnings; +our $VERSION = '1.00'; + # Has only one function: doit(), which ties the hashes %get, %post, %fields # and %header in PLP::Script. Also generates %cookie immediately. sub doit { diff --git a/lib/PLP/Functions.pm b/lib/PLP/Functions.pm index 18318ad..90ff741 100644 --- a/lib/PLP/Functions.pm +++ b/lib/PLP/Functions.pm @@ -6,6 +6,7 @@ use warnings; use Exporter qw(import); use Fcntl qw(:flock); +our $VERSION = '1.00'; our @EXPORT = qw/Entity DecodeURI EncodeURI Include include PLP_END AddCookie ReadFile WriteFile AutoURL Counter exit/; diff --git a/lib/PLP/Tie/Delay.pm b/lib/PLP/Tie/Delay.pm index 8be53af..0a2a0d5 100644 --- a/lib/PLP/Tie/Delay.pm +++ b/lib/PLP/Tie/Delay.pm @@ -4,6 +4,8 @@ use strict; no strict 'refs'; use warnings; +our $VERSION = '1.00'; + =head1 PLP::Tie::Delay Delays hash generation. Unties the hash on first access, and replaces it by the generated one. diff --git a/lib/PLP/Tie/Headers.pm b/lib/PLP/Tie/Headers.pm index ef12491..c675f8a 100644 --- a/lib/PLP/Tie/Headers.pm +++ b/lib/PLP/Tie/Headers.pm @@ -4,6 +4,8 @@ use strict; use warnings; use Carp; +our $VERSION = '1.00'; + =head1 PLP::Tie::Headers Makes a hash case insensitive, and sets some headers. <_> equals <->, so C<$foo{CONTENT_TYPE}> is diff --git a/lib/PLP/Tie/Print.pm b/lib/PLP/Tie/Print.pm index a2d22dd..85788af 100644 --- a/lib/PLP/Tie/Print.pm +++ b/lib/PLP/Tie/Print.pm @@ -3,6 +3,8 @@ package PLP::Tie::Print; use strict; use warnings; +our $VERSION = '1.00'; + =head1 PLP::Tie::Print Just prints to stdout, but sends headers if not sent before. -- 2.30.0 From 4b924b1351d4a8ea42652533081a3ea62df110e4 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 29 May 2008 21:47:57 +0000 Subject: [PATCH 09/16] output multiline %headers as multiple headers of the same name MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Allowing repeated HTTP headers (RFC2616 §4.2) even though this didn't add much value afterall (one may also use commas). It does prevent (accidentally) malformed header values though, as most servers don't seem to handle continuation lines. --- Changes | 1 + TODO | 1 - lib/PLP.pm | 5 ++++- lib/PLP/Fields.pm | 4 ++++ lib/PLP/Functions.pm | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index 78da9d1..30bd1b8 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ +- %header values containing newlines will be sent as multiple fields - All modules use warnings and contain a $VERSION - Fix META.yml syntax diff --git a/TODO b/TODO index bd73751..508b2dc 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,6 @@ In no particular order or significance: - lvalue %cookie (similar to AddCookie) - multipart posts [3.21] - install rules for servers -- %header takes array ref - test plp parsing - redisplay include errors [3.21] - object instead of $PLP:: diff --git a/lib/PLP.pm b/lib/PLP.pm index 42866dc..37d95b1 100644 --- a/lib/PLP.pm +++ b/lib/PLP.pm @@ -94,7 +94,10 @@ sub handler { sub sendheaders () { $PLP::sentheaders ||= [ caller 1 ? (caller 1)[1, 2] : (caller)[1, 2] ]; print STDOUT "Content-Type: text/plain\n\n" if $PLP::DEBUG & 2; - print STDOUT map("$_: $PLP::Script::header{$_}\n", keys %PLP::Script::header), "\n"; + while (my ($header, $values) = each %PLP::Script::header) { + print STDOUT "$header: $_\n" for split /\n/, $values; + } + print STDOUT "\n"; } { diff --git a/lib/PLP/Fields.pm b/lib/PLP/Fields.pm index cd68e36..212dec5 100644 --- a/lib/PLP/Fields.pm +++ b/lib/PLP/Fields.pm @@ -117,6 +117,10 @@ when sending the headers is the one you used first. The following are equal: $header{Content_Type} $headers{CONTENT_type} +If a value contains newlines, the header is repeated for each line: + + $header{Allow} = "HEAD\nGET"; # equivalent to HEAD,GET + =back =head1 AUTHOR diff --git a/lib/PLP/Functions.pm b/lib/PLP/Functions.pm index 90ff741..f362167 100644 --- a/lib/PLP/Functions.pm +++ b/lib/PLP/Functions.pm @@ -75,7 +75,7 @@ sub EncodeURI (@) { sub AddCookie ($) { if ($PLP::Script::header{'Set-Cookie'}) { - $PLP::Script::header{'Set-Cookie'} .= "\nSet-Cookie: $_[0]"; + $PLP::Script::header{'Set-Cookie'} .= "\n" . $_[0]; } else { $PLP::Script::header{'Set-Cookie'} = $_[0]; } -- 2.30.0 From 439981a033a1133febc977bbf57dcc464bbf0d25 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Fri, 30 May 2008 02:38:00 +0000 Subject: [PATCH 10/16] test pod coverage as far as applicable --- Changes | 1 + t/pod-coverage.t | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 t/pod-coverage.t diff --git a/Changes b/Changes index 30bd1b8..a8d2b27 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ +- Test pod coverage - %header values containing newlines will be sent as multiple fields - All modules use warnings and contain a $VERSION - Fix META.yml syntax diff --git a/t/pod-coverage.t b/t/pod-coverage.t new file mode 100644 index 0000000..6a61ac4 --- /dev/null +++ b/t/pod-coverage.t @@ -0,0 +1,15 @@ +use strict; +use warnings; +use lib 'lib'; + +use Test::More; +eval 'use Test::Pod::Coverage'; +plan skip_all => "Test::Pod::Coverage required for testing POD coverage" if $@; + +plan tests => 1; +pod_coverage_ok($_, {nonwhitespace => 1}, $_) for 'PLP::Functions'; + +# Other modules can be assumed either private (Tie::*), +# simple includes (Backend::* - generally only accessed by constructor), +# or both (Fields - defying Coverage because it just exports variables). + -- 2.30.0 From b9208715f1af33e28a11156791c972d49a8363ec Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Fri, 30 May 2008 17:37:09 +0000 Subject: [PATCH 11/16] undefined warnings during Fields parsing Accessing undefined values pollutes error logs since d9f3acb221a71e094318c7b5d3809aa81dbb5bb3 (use warnings in all modules). --- lib/PLP/Fields.pm | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/PLP/Fields.pm b/lib/PLP/Fields.pm index 212dec5..52040e3 100644 --- a/lib/PLP/Fields.pm +++ b/lib/PLP/Fields.pm @@ -12,7 +12,7 @@ sub doit { # %get my $get = \%PLP::Script::get; - if (length $ENV{QUERY_STRING}){ + if (defined $ENV{QUERY_STRING} and length $ENV{QUERY_STRING}){ for (split /[&;]/, $ENV{QUERY_STRING}) { my @keyval = split /=/, $_, 2; PLP::Functions::DecodeURI(@keyval); @@ -25,13 +25,10 @@ sub doit { tie %PLP::Script::post, 'PLP::Tie::Delay', 'PLP::Script::post', sub { my %post; - my $post; - - return \%post if $ENV{CONTENT_TYPE} !~ - m!^(?:application/x-www-form-urlencoded|$)!; - - $post = $PLP::read->($ENV{CONTENT_LENGTH}) if $ENV{CONTENT_LENGTH}; + return \%post unless $ENV{CONTENT_TYPE} and $ENV{CONTENT_LENGTH} and + $ENV{CONTENT_TYPE} =~ m!^(?:application/x-www-form-urlencoded|$)!; + my $post = $PLP::read->($ENV{CONTENT_LENGTH}); return \%post unless defined $post and length $post; for (split /&/, $post) { -- 2.30.0 From 178a4a4de0bbc111bf376d6876af16c093e3c838 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Fri, 30 May 2008 18:34:45 +0000 Subject: [PATCH 12/16] add charset to default content-type header if STDOUT is in UTF-8 If output has utf8 layer enabled, it makes only sense to mark it as such to clients. Only available with PerlIO (as of Perl 5.8 afaict), but not fatal (assume non-utf8) if it doesn't work. Charset is only added at first read or change of the content-type value, so it's not hardcoded to site defaults. Requires an extra object variable unfortunately, but the only way to make it useful (no page runtime accomodation wouldn't give much advantage). --- Changes | 1 + lib/PLP/Tie/Headers.pm | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index a8d2b27..8d493cd 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ +- Add charset to Content-Type header for UTF-8 output - Test pod coverage - %header values containing newlines will be sent as multiple fields - All modules use warnings and contain a $VERSION diff --git a/lib/PLP/Tie/Headers.pm b/lib/PLP/Tie/Headers.pm index c675f8a..8e023fb 100644 --- a/lib/PLP/Tie/Headers.pm +++ b/lib/PLP/Tie/Headers.pm @@ -26,12 +26,18 @@ sub TIEHASH { { 'content-type' => 'Content-Type', 'x-plp-version' => 'X-PLP-Version', - } + }, + 1 # = content-type untouched ], $_[0]; } sub FETCH { my ($self, $key) = @_; + if ($self->[2] and defined $self->[0]->{'Content-Type'}) { + my $utf8 = eval { grep {$_ eq "utf8"} PerlIO::get_layers(*STDOUT) }; + $self->[0]->{'Content-Type'} .= '; charset=utf-8' if $utf8; + $self->[2] = 0; + } $key =~ tr/_/-/; return $self->[0]->{ $self->[1]->{lc $key} }; } @@ -50,6 +56,7 @@ sub STORE { } else { $self->[1]->{lc $key} = $key; } + $self->[2] = 0 if $key eq 'Content-Type'; return ($self->[0]->{$key} = $value); } -- 2.30.0 From 80bf896339924929e295784d34deb8bc6997de13 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 31 May 2008 18:51:02 +0000 Subject: [PATCH 13/16] order tests Prefix filenames so they sort in order of significance. --- t/{Functions.t => 10-functions.t} | 0 t/{meta.t => 91-meta.t} | 0 t/{pod.t => 92-pod.t} | 0 t/{pod-coverage.t => 93-podcover.t} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename t/{Functions.t => 10-functions.t} (100%) rename t/{meta.t => 91-meta.t} (100%) rename t/{pod.t => 92-pod.t} (100%) rename t/{pod-coverage.t => 93-podcover.t} (100%) diff --git a/t/Functions.t b/t/10-functions.t similarity index 100% rename from t/Functions.t rename to t/10-functions.t diff --git a/t/meta.t b/t/91-meta.t similarity index 100% rename from t/meta.t rename to t/91-meta.t diff --git a/t/pod.t b/t/92-pod.t similarity index 100% rename from t/pod.t rename to t/92-pod.t diff --git a/t/pod-coverage.t b/t/93-podcover.t similarity index 100% rename from t/pod-coverage.t rename to t/93-podcover.t -- 2.30.0 From 4e5e1c36af9687c173d2c27c93b08e378bc2476d Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 31 May 2008 19:02:45 +0000 Subject: [PATCH 14/16] fix PLP::everything() wrapper CGI initiator everything() was moved in 96959bff080392067524996e6edbf954 (move backend interface modules into PLP::Backend:: namespace) and made a method, but backwards compatibility wrapper doesn't call it as such. This breaks old plp.cgi scripts, completely negating the purpose of this feature. --- Changes | 1 + lib/PLP.pm | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 8d493cd..da4c3e2 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ +- Fix everything() wrapper (broke pre-3.20 CGI scripts on 3.20) - Add charset to Content-Type header for UTF-8 output - Test pod coverage - %header values containing newlines will be sent as multiple fields diff --git a/lib/PLP.pm b/lib/PLP.pm index 37d95b1..b9e3b7e 100644 --- a/lib/PLP.pm +++ b/lib/PLP.pm @@ -83,7 +83,7 @@ sub error { # Wrap old request handlers. sub everything { require PLP::Backend::CGI; - PLP::Backend::CGI::everything(); + PLP::Backend::CGI->everything(); } sub handler { require PLP::Backend::Apache; -- 2.30.0 From c867504b422dfa5cb72370fa828de007718a96b1 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 31 May 2008 19:30:19 +0000 Subject: [PATCH 15/16] only test PLP::Functions in t/10-functions.t Functions could be used seperately from the rest of PLP, so do not require everything. This test is covered by t/50-cgi.t now. --- t/10-functions.t | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/t/10-functions.t b/t/10-functions.t index a6c6e92..c921339 100644 --- a/t/10-functions.t +++ b/t/10-functions.t @@ -2,9 +2,7 @@ use strict; use Test::More tests => 6; -BEGIN { use_ok('PLP') } - -PLP::Functions->import(); +BEGIN { use_ok('PLP::Functions') } is( Entity(q{}), -- 2.30.0 From 7a089d571590f9de96bd54840263ce5376404e66 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 31 May 2008 19:57:57 +0000 Subject: [PATCH 16/16] fix undefined warning in apache cgi path PATH_INFO was intentionally declared undef in PLP::Backend::CGI, but would be concatenated later (in Apache mode at least), giving warnings since d9f3acb221a71e094318c7b5d3809aa81db (use warnings in all modules). --- lib/PLP/Backend/CGI.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/PLP/Backend/CGI.pm b/lib/PLP/Backend/CGI.pm index 10b9b45..e952c5a 100644 --- a/lib/PLP/Backend/CGI.pm +++ b/lib/PLP/Backend/CGI.pm @@ -17,7 +17,7 @@ sub init { # Run backwards through PATH_TRANSLATED to find target filename, # then get file (relative) by stripping PATH_INFO. my ($path, $rel) = (delete $ENV{PATH_TRANSLATED}, delete $ENV{PATH_INFO}); - my $path_info; + my $path_info = ''; while (not -f $path) { if (not $path =~ s/(\/+[^\/]*)$//) { printf STDERR "PLP: Not found: $path$path_info ($ENV{REQUEST_URI})\n"; @@ -27,7 +27,7 @@ sub init { # move last path element onto PATH_INFO $path_info = $1 . $path_info; } - if (defined $path_info) { + if ($path_info ne '') { $rel =~ s/\Q$path_info\E$//; $ENV{PATH_INFO} = $path_info; } -- 2.30.0