From 58ad0f73721365480cd2c2bc844af04146ba1941 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 4 Jun 2008 22:56:25 +0000 Subject: [PATCH] warn pre-start() errors Early warnings (cgi 403/404) should warn instead of print to STDERR. This allows them to be handled by $SIG{__WARN__} (usually not set, but used in tests). --- lib/PLP/Backend/CGI.pm | 8 ++++---- t/50-cgi.t | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/PLP/Backend/CGI.pm b/lib/PLP/Backend/CGI.pm index e952c5a..3acf63d 100644 --- a/lib/PLP/Backend/CGI.pm +++ b/lib/PLP/Backend/CGI.pm @@ -3,7 +3,7 @@ package PLP::Backend::CGI; use strict; use warnings; -our $VERSION = '1.02'; +our $VERSION = '1.03'; use PLP; @@ -20,7 +20,7 @@ sub init { my $path_info = ''; while (not -f $path) { if (not $path =~ s/(\/+[^\/]*)$//) { - printf STDERR "PLP: Not found: $path$path_info ($ENV{REQUEST_URI})\n"; + warn "PLP: Not found: $path$path_info ($ENV{REQUEST_URI})\n"; PLP::error(undef, 404); return; } @@ -35,7 +35,7 @@ sub init { $ENV{SCRIPT_NAME} = $rel; } elsif (not -f $ENV{SCRIPT_FILENAME}) { - print STDERR "PLP: Not found: $ENV{SCRIPT_FILENAME} ($ENV{REQUEST_URI})\n"; + warn "PLP: Not found: $ENV{SCRIPT_FILENAME} ($ENV{REQUEST_URI})\n"; PLP::error(undef, 404); return; } @@ -43,7 +43,7 @@ sub init { $ENV{"PLP_$_"} = $ENV{"SCRIPT_$_"} for qw/NAME FILENAME/; if (not -r $ENV{PLP_FILENAME}) { - print STDERR "PLP: Can't read: $ENV{PLP_FILENAME} ($ENV{REQUEST_URI})\n"; + warn "PLP: Can't read: $ENV{PLP_FILENAME} ($ENV{REQUEST_URI})\n"; PLP::error(undef, 403); return; } diff --git a/t/50-cgi.t b/t/50-cgi.t index d04e450..bf60143 100644 --- a/t/50-cgi.t +++ b/t/50-cgi.t @@ -37,6 +37,7 @@ sub plp_is { close STDOUT; open STDOUT, '>', \my $output; # STDOUT buffered to scalar + select STDOUT; # output before start() (which selects PLPOUT) eval { local $SIG{__WARN__} = sub { print $_[0] }; # enables warnings PLP::everything(); @@ -178,6 +179,7 @@ SKIP: { chmod 0244, $testfile or skip("changed permissions", 1); plp_is('permission denied', undef, < @@ -195,6 +197,7 @@ chmod 0644, $testfile; $ENV{PATH_TRANSLATED} = "$base/missinginclude/test/123"; plp_is('not found', undef, < -- 2.30.0