Skip to content

Instantly share code, notes, and snippets.

@FROGGS
Last active December 30, 2015 15:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save FROGGS/392471225039d60749d7 to your computer and use it in GitHub Desktop.

is:

make p-install && RAKUDO_MODULE_DEBUG=1 perl6-p -e 'use Test; say GLOBAL::'
MODULE_DEBUG: loading blib/Perl6/BOOTSTRAP.pbc
MODULE_DEBUG: done loading blib/Perl6/BOOTSTRAP.pbc

%chosen is:
key => /home/froggs/dev/nqp/install/lib/parrot/5.9.0-devel/languages/perl6/lib/Test.pm
pm => /home/froggs/dev/nqp/install/lib/parrot/5.9.0-devel/languages/perl6/lib/Test.pm
load => /home/froggs/dev/nqp/install/lib/parrot/5.9.0-devel/languages/perl6/lib/Test.pir

MODULE_DEBUG: loading [...]/parrot/5.9.0-devel/languages/perl6/lib/Test.pir
MODULE_DEBUG: done loading [...]/parrot/5.9.0-devel/languages/perl6/lib/Test.pir
().hash

but should be:

make p-install && RAKUDO_MODULE_DEBUG=1 perl6-p -e 'use Test; say GLOBAL::'
MODULE_DEBUG: loading blib/Perl6/BOOTSTRAP.pbc
MODULE_DEBUG: done loading blib/Perl6/BOOTSTRAP.pbc

%chosen is:
key => /home/froggs/dev/nqp/install/lib/parrot/5.9.0-devel/languages/perl6/lib/Test.pm
pm => /home/froggs/dev/nqp/install/lib/parrot/5.9.0-devel/languages/perl6/lib/Test.pm
load => /home/froggs/dev/nqp/install/lib/parrot/5.9.0-devel/languages/perl6/lib/Test.pir
ver => *

MODULE_DEBUG: loading [...]/parrot/5.9.0-devel/languages/perl6/lib/Test.pir
MODULE_DEBUG: done loading [...]/parrot/5.9.0-devel/languages/perl6/lib/Test.pir
("Test" => Test).hash
class CompUnitRepo::Local::File {
has @!paths;
method new( *@location ) {
self.bless(:@location)
}
method BUILD( :@location ) {
@!paths = @location;
self
}
method install( $source, $from? ) {
...
}
method candidates( $longname, :$file, :$auth, :$ver ) {
my @candi;
my Mu $c := nqp::gethllsym('perl6', 'ModuleLoader').p6ml.locate_candidates(
$longname, nqp::p6listitems(nqp::decont([ @!paths, @*INC ])), :$file);
if $c[0] {
$c[0]<ver> = Version.new( '*' );
@candi.push: $c[0].item;
}
@candi
}
}
diff --git a/src/core/core_epilogue.pm b/src/core/core_epilogue.pm
index 96e75af..5b1cf96 100644
--- a/src/core/core_epilogue.pm
+++ b/src/core/core_epilogue.pm
@@ -14,4 +14,40 @@ BEGIN {
Perl6::Metamodel::GrammarHOW.HOW.compose(Perl6::Metamodel::GrammarHOW);
}
+my $prefix = ($*VM<properties><perl6.prefix> // $*VM<config><prefix>);
+if "$prefix/share/libraries.cfg".IO.e {
+ my @lines = slurp("$prefix/share/libraries.cfg").lines;
+ my %repos;
+ for @lines -> $repo {
+ next if $repo ~~ /^ '#'/;
+ if $repo ~~ / $<class>=[ <.ident>+ % '::' ] [ ':name<' $<libname>=\w+ '>' ]? '=' $<path>=.+ / {
+ my $libname = $<libname> // '';
+ %repos{~$<class>}{$libname} //= [];
+ %repos{~$<class>}{$libname}.push($<path>.IO.path.is-relative ?? "$prefix/share/$<path>" !! ~$<path>);
+ }
+ }
+ my @custom_libs = %*CUSTOM_LIB.values;
+ for %repos.kv -> $classname, $libnames {
+ for $libnames.kv -> $libname, $args {
+ if $classname eq 'CompUnitRepo::Local::File' {
+ CompUnitRepo.add_repo( CompUnitRepo::Local::File.new(|@$args), :name($libname) );
+ }
+ elsif $classname eq 'CompUnitRepo::Local::Installation' {
+ CompUnitRepo.add_repo( CompUnitRepo::Local::Installation.new(|@$args), :name($libname) );
+ }
+ else {
+ my $name = 'lib/' ~ $classname.split('::').join('/') ~ '.pm';
+ for @custom_libs -> $path {
+ if "$path/$name".IO.e {
+ require "$path/$name";
+ CompUnitRepo.add_repo( ::($classname).new(|@$args), :name($libname) );
+ }
+ }
+ }
+ }
+ }
+}
+
+nqp::bindhllsym('perl6', 'ModuleLoader', CompUnitRepo);
+
{YOU_ARE_HERE}
diff --git a/tools/build/Makefile-Parrot.in b/tools/build/Makefile-Parrot.in
index c6a6a0b..0c00dfd 100644
--- a/tools/build/Makefile-Parrot.in
+++ b/tools/build/Makefile-Parrot.in
@@ -239,6 +239,10 @@ P_CORE_SOURCES = \
src/core/terms.pm \
src/core/Deprecations.pm \
src/core/OS.pm \
+ src/core/JSON/Pretty.pm \
+ src/core/CompUnitRepo.pm \
+ src/core/CompUnitRepo/Local/File.pm \
+ src/core/CompUnitRepo/Local/Installation.pm \
src/core/core_epilogue.pm \
DOCS = README CREDITS LICENSE docs/*
class CompUnitRepo {
my Mu $p6ml := nqp::gethllsym('perl6', 'ModuleLoader');
my @repos;
method candidates($longname, :$file, :$auth, :$ver) {
my @candi;
for @repos {
@candi := (@candi, .candidates($longname, :$file, :$auth, :$ver)).flat
}
@candi.sort: { $^b<ver> cmp $^a<ver> }
}
method add_repo($repo, :$name) {
@repos.push: $repo;
%*CUSTOM_LIB{$name} := $repo if $name
}
method p6ml { $p6ml }
method load_module($module_name, %opts, *@GLOBALish, :$line, :$file) {
my $chosen = self.candidates($module_name, :auth(%opts<auth>), :ver(%opts<ver>))[0];
$p6ml.load_module($module_name, %opts, @GLOBALish, :$line, :$file, :$chosen);
}
method ctxsave() { $p6ml.ctxsave() }
method absolute_path($path) { $p6ml.absolute_path($path) }
method load_setting($setting_name) { $p6ml.load_setting($setting_name) }
method resolve_repossession_conflicts(@conflicts) { $p6ml.resolve_repossession_conflicts(@conflicts) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment