Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
allow CUR classname in RAKUDOLIB, PERL6LIB and -I
-Ifoo stills results in a CompUnitRepo::Local::File(foo), but now one
has the opportunity to get a CUR::Local::Installation by doing:
-ICompUnitRepo::Local::Installation=foo. Also, CURs only take a single
path now, since we can group every kind of CUR by putting it into an
array-group in @*INC.
  • Loading branch information
FROGGS committed May 31, 2014
1 parent e88e462 commit 7d6acc7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 57 deletions.
16 changes: 8 additions & 8 deletions src/core/CompUnitRepo/Local/File.pm
@@ -1,16 +1,16 @@
class CompUnitRepo::Local::File {
has @!paths;
method new( *@location ) {
self.bless(:@location)
has $!path;
method new( $path ) {
self.bless(:$path)
}

method BUILD(:@location) {
@!paths = @location>>.map(*.path);
method BUILD(:$path) {
$!path = $path.path;
self
}

method Str { @!paths.Str }
method gist { "CompUnitRepo::Local::File(" ~ @!paths.Str ~ ')' }
method Str { $!path.Str }
method gist { "CompUnitRepo::Local::File(" ~ $!path.Str ~ ')' }

method install($source, $from?) {
...
Expand All @@ -22,7 +22,7 @@ class CompUnitRepo::Local::File {
method candidates($name, :$file, :$auth, :$ver) {
my @candi;
my Mu $c := nqp::gethllsym('perl6', 'ModuleLoader').p6ml.locate_candidates(
$name, nqp::p6listitems(nqp::decont([ @!paths ])), :$file);
$name, nqp::p6listitems(nqp::decont([ $!path ])), :$file);
if $c[0] {
my $candi;
$candi<ver> = Version.new('0');
Expand Down
18 changes: 8 additions & 10 deletions src/core/CompUnitRepo/Local/Installation.pm
Expand Up @@ -32,18 +32,16 @@ class CompUnitRepo::Local::Installation {
has %!dists;
has $!cver = nqp::hllize(nqp::atkey(nqp::gethllsym('perl6', '$COMPILER_CONFIG'), 'version'));
has $.path;
method new(*@locations) {
self.bless(:@locations)
method new($path) {
self.bless(:$path)
}

method BUILD(:@locations) {
for @locations -> $path {
$!path = $path.path unless $!path;
%!dists{$path} = "$path/MANIFEST".IO.e ?? from-json( slurp "$path/MANIFEST" ) !! {};
%!dists{$path}<file-count> //= 0;
%!dists{$path}<dist-count> //= 0;
%!dists{$path}<dists> //= [ ];
}
method BUILD(:$path) {
$!path = $path.path unless $!path;
%!dists{$path} = "$path/MANIFEST".IO.e ?? from-json( slurp "$path/MANIFEST" ) !! {};
%!dists{$path}<file-count> //= 0;
%!dists{$path}<dist-count> //= 0;
%!dists{$path}<dists> //= [ ];
}

method Str { $!path.Str }
Expand Down
96 changes: 57 additions & 39 deletions src/core/Inc.pm
Expand Up @@ -8,12 +8,58 @@
#?if !jvm
my $pathsep := $*VM.config<osname> eq 'MSWin32' ?? ';' !! ':';
#?endif
@INC.push(CompUnitRepo::Local::File.new(%*ENV<RAKUDOLIB>.split($pathsep))) if %*ENV<RAKUDOLIB>;
@INC.push(CompUnitRepo::Local::File.new(%*ENV<PERL6LIB>.split($pathsep))) if %*ENV<PERL6LIB>;

my @all_paths;
sub make-cur($class, $path) {
@all_paths.push: $path;
if $class eq 'CompUnitRepo::Local::File' {
CompUnitRepo::Local::File.new($path);
}
elsif $class eq 'CompUnitRepo::Local::Installation' {
CompUnitRepo::Local::Installation.new($path);
}
else {
my $name = 'lib/' ~ $class.split('::').join('/') ~ '.pm';
for @all_paths -> $previous_path {
if "$previous_path/$name".IO.e {
require "$previous_path/$name";
return ::($class).new($path);
}
}
}
}

# Add CompUnitRepos to @*INC and also to %*CUSTOM_LIB if they have a name.
sub add-curs($line, $sep = ',') {
my %options;
if $line && $line ~~ /^ [ $<class>=[ <.ident>+ % '::' ] [ ':' $<n>=\w+ <[<([]> $<v>=<[\w-]>+ <[>)\]]> { %options{$<n>} = $<v> } ]* '=' ]? $<path>=.+ $/ {
my $class = $<class> ?? ~$<class> !! 'CompUnitRepo::Local::File';
my @paths = $<path>.split($sep);
for @paths -> $path {
my $cur = make-cur($class, $path);
%CUSTOM_LIB{~%options<name>} = $cur if %options<name>;
@INC.push: $cur
}
}
}

my $I := nqp::atkey(nqp::atkey(%*COMPILING, '%?OPTIONS'), 'I');
if nqp::defined($I) {
if nqp::islist($I) {
my Mu $iter := nqp::iterator($I);
add-curs(nqp::p6box_s(nqp::shift($iter))) while $iter;
}
else {
add-curs(nqp::p6box_s($I));
}
}

add-curs(%*ENV<RAKUDOLIB>, $pathsep) if %*ENV<RAKUDOLIB>;
add-curs(%*ENV<PERL6LIB>, $pathsep) if %*ENV<PERL6LIB>;

#?if jvm
for nqp::jvmclasspaths() -> $path {
@INC.push(CompUnitRepo::Local::File.new($path)) if nqp::stat($path, nqp::const::STAT_ISDIR);
add-curs($path, $pathsep) if nqp::stat($path, nqp::const::STAT_ISDIR);
}
#?endif

Expand All @@ -32,37 +78,21 @@
if "$prefix/share/libraries.json".IO.e {
my $config = "$prefix/share/libraries.json".IO.e ?? from-json( slurp "$prefix/share/libraries.json" ) !! [];

my @all_paths;
sub make-cur($class, *@paths) {
@all_paths.push: @paths;
if $class eq 'CompUnitRepo::Local::File' {
CompUnitRepo::Local::File.new(|@paths);
}
elsif $class eq 'CompUnitRepo::Local::Installation' {
CompUnitRepo::Local::Installation.new(|@paths);
}
else {
my $name = 'lib/' ~ $class.split('::').join('/') ~ '.pm';
for @all_paths -> $path {
if "$path/$name".IO.e {
require "$path/$name";
return ::($class).new(|@paths);
}
}
}
}

for $config.list -> @group {
my @cur_group;
for @group>>.kv -> $class, $props {
for $props.list -> $prop {
if $prop ~~ Associative {
my $cur = make-cur($class, $prop.value.flat);
@cur_group.push: $cur;
%CUSTOM_LIB{$prop.key} = $cur;
for $prop.value.flat -> $path {
my $cur = make-cur($class, $path);
@cur_group.push: $cur;
%CUSTOM_LIB{$prop.key} = $cur;
}
}
else {
@cur_group.push: make-cur($class, $prop.flat)
for $prop.flat -> $path {
@cur_group.push: make-cur($class, $path)
}
}
}
}
Expand All @@ -89,18 +119,6 @@
@INC.push([@cur_inst]);
}

# TODO Allow to pass Repo class to -I as well as the path.
my $I := nqp::atkey(nqp::atkey(%*COMPILING, '%?OPTIONS'), 'I');
if nqp::defined($I) {
if nqp::islist($I) {
my Mu $iter := nqp::iterator($I);
@INC.unshift: CompUnitRepo::Local::File.new(nqp::p6box_s(nqp::shift($iter))) while $iter;
}
else {
@INC.unshift: CompUnitRepo::Local::File.new(nqp::p6box_s($I));
}
}

PROCESS::<@INC> := @INC;
PROCESS::<%CUSTOM_LIB> := %CUSTOM_LIB;

Expand Down

0 comments on commit 7d6acc7

Please sign in to comment.