Skip to content

Commit

Permalink
Localize $0 when evaluating .psgi so that FindBin etc. should DWIM
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Feb 23, 2011
1 parent 0725390 commit 3da9baf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Plack/Util.pm
Expand Up @@ -105,6 +105,8 @@ sub _load_sandbox {
my $_package = $_file;
$_package =~ s/([^A-Za-z0-9_])/sprintf("_%2x", unpack("C", $1))/eg;

local $0 = $_file; # so FindBin etc. works

return eval sprintf <<'END_EVAL', $_package;
package Plack::Sandbox::%s;
{
Expand Down
2 changes: 2 additions & 0 deletions t/Plack-Util/bin/findbin.psgi
@@ -0,0 +1,2 @@
use FindBin;
sub { [ 200, [ "Content-Type", "text/plain" ], [ "$FindBin::Bin" ] ] };
7 changes: 7 additions & 0 deletions t/Plack-Util/load.t
Expand Up @@ -45,4 +45,11 @@ use Test::More;
unlike $@, qr/Died/;
}

{
my $app = Plack::Util::load_psgi("t/Plack-Util/bin/findbin.psgi");
test_psgi $app, sub {
like $_[0]->(GET "/")->content, qr!t[/\\]Plack-Util[/\\]bin$!;
}
}

done_testing;

0 comments on commit 3da9baf

Please sign in to comment.