App-Kit

 view release on metacpan or  search on metacpan

lib/App/Kit/Obj/FS.pm  view on Meta::CPAN

);

has bindir => (
    'is'   => 'rw',
    'lazy' => '1',

    # 'isa'     => sub { die "'bindir' must be a directory" unless -d $_[1] },
    'default' => sub {

        # PSGI/Plack $0
        #   1. starman worker -Ilib … t/test.psgi
        #   2. 500 error: Cannot find current script 'starman worker -Ilib … t/test.psgi' at …/FindBin.pm line 166.
        local $0 = $0;
        if ( $0 =~ m/(\S+\.psgi)/ ) {
            $0 = $1;
        }
        require FindBin;
        require Cwd;
        return $FindBin::Bin || FindBin->again() || Cwd::cwd();
    },
);

t/07.fs-psgi.t  view on Meta::CPAN

my $tdir  = $app->fs->tmpdir;
my $fsdir = $tdir->{'REALNAME'};    # necessary here to string-match bindir’s Cwd calls/logic results

chdir $fsdir || die "Could not go chdir to tmp dir: $!";
mkdir 'foo'  || die "Could not mkdir foo: $!";
my $foodir = $app->fs->spec->catdir( "$fsdir", 'foo' );
my $fsfile = $app->fs->spec->catfile( $foodir, 'test.psgi' );
$app->fs->write_file( $fsfile, "sub {}" );

{
    local $0 = 'starman worker -Ilib … foo/test.psgi';
    is $app->fs->bindir, $foodir, 'bindir w/ PSGI/Plack $0';
    is( $0, 'starman worker -Ilib … foo/test.psgi', '$0 not changed by bindir()' );
}

chdir $cwd || die "Could not go back to starting dir: $!";

done_testing;



( run in 0.536 second using v1.01-cache-2.11-cpan-e93a5daba3e )