} or 1;
sub _plp_run {
- my ($src, $env, $in) = @_;
+ my ($src, $env, $input) = @_;
%ENV = (
REQUEST_METHOD => 'GET',
$env ? %{$env} : (),
); # Apache/2.2.4 CGI environment
- if (defined $in) {
- $ENV{CONTENT_LENGTH} //= length $in;
+ if (defined $input) {
+ $ENV{CONTENT_LENGTH} //= length $input;
$ENV{CONTENT_TYPE} //= 'application/x-www-form-urlencoded';
close STDIN;
- open STDIN, '<', $in;
+ open STDIN, '<', $input;
}
close STDOUT;
}
sub plp_is {
- my ($name, $src, $expect, $env, $in) = @_;
+ my ($name, $src, $expect, $env, $input) = @_;
my $tb = __PACKAGE__->builder;
local $Test::Builder::Level = $Test::Builder::Level + 1;
- my ($output, $failure) = _plp_run($src, $env, $in);
+ my ($output, $failure) = _plp_run($src, $env, $input);
if ($failure) {
$tb->ok(0, $name);
$tb->diag(" Error: $failure");
(my $name = $file) =~ s/[.][^.]+$//;
$file = "$name.html";
- my $infile = delete $replace{-input} // "$name.plp";
- my $addin = -e "$name.txt" && "$name.txt";
+ my $src = delete $replace{-input} // "$name.plp";
+ my $input = -e "$name.txt" && "$name.txt";
$name =~ s/^(\d*)-// and $name .= " ($1)";
DecodeURI($name);
- my $out = eval {
+ my $output = eval {
local $/ = undef; # slurp
open my $fh, '<', $file or die "$!\n";
return readline $fh;
};
- if (not defined $out) {
+ if (not defined $output) {
$tb->ok(0, $name);
$tb->diag("error reading output from $file: $@");
return;
my $env = delete $replace{-env};
$replace{HEAD} //= "Content-Type: text/html\nX-PLP-Version: $PLP::VERSION\n";
$replace{VERSION } //= $PLP::VERSION;
- $replace{SCRIPT_NAME } //= $infile;
- $replace{SCRIPT_FILENAME} //= "./$infile";
+ $replace{SCRIPT_NAME } //= $src;
+ $replace{SCRIPT_FILENAME} //= "./$src";
- chomp $out;
- $out =~ s/\$$_/$replace{$_}/g for keys %replace;
- $out =~ s{
+ chomp $output;
+ $output =~ s/\$$_/$replace{$_}/g for keys %replace;
+ $output =~ s{
<eval \s+ line="([^"]*)"> (.*?) </eval>
- }{ _getwarning($2, $1, $infile) }msxge;
+ }{ _getwarning($2, $1, $src) }msxge;
- plp_is($name, $infile, $out, $env, $addin);
+ plp_is($name, $src, $output, $env, $input);
}