develooper Front page | perl.perl6.users | Postings from July 2021

Re: use lib and locations in a variable

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
July 11, 2021 06:14
Subject:
Re: use lib and locations in a variable
Message ID:
f55a071f-68e8-6b2f-10c6-c93dd6ca7d76@zoho.com
On 7/10/21 4:11 PM, Joseph Brenner wrote:
> I want my test files to be able to find the modules they're testing
> just using their relative locations, given the usual layout of "lib"
> and "t" locations in parallel inside the project directory.
> 
> I find that while this works:
> 
>      use lib $*PROGRAM.parent.add('../lib');
> 
> This doesn't work:
> 
>      my $lib_loc = $*PROGRAM.parent.add('../lib');
>      use lib "$lib_loc";
> 
> I get a compile time error
> 
>      Use of uninitialized value $lib_loc of type Any in string context.
>      ...
>      Repository specification can not be an empty string.  Did you mean
> 'use lib "."' ?
> 
> I thought that this would fix the problem, but I see the same
> compile time error with it:
> 
>      BEGIN {
>        my $lib_loc = $*PROGRAM.parent.add('../lib');
>        use lib "$lib_loc";
>      }
> 
> Does that make sense to anyone?  It feels like a bug to me.
> 


Hi Joseph,

Okay, not what you asked. BUT WHEN DOES THAT STOP ME !!!
<maniacal laughter>

$*PROGRAM.parent is just a silly dot.  You an
hard code that yourself.

     $ p6 'print $*PROGRAM.parent ~ "\n";'
     .

You can get the silly dot with curdir too

     $ p6 'print $*SPEC.curdir ~ "\n";'
     .

If you want the full path, use `$*CWD.Str`:
     $ p6 'print $*CWD.Str ~ "\n";'
     /home/linuxutil

print does not need the .Str, but assigning it
to a string does.

-T

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About