Created
July 10, 2016 12:23
-
-
Save peschwa/9f3236e85041550a5bacda6bc4752cab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CompUnit::Repository::Java does CompUnit::Repository does CompUnit::Repository::Locally { | |
has $!interop; | |
method need( | |
CompUnit::DependencySpecification $spec, | |
CompUnit::PrecompilationRepository $precomp = self.precomp-repository(), | |
) | |
returns CompUnit:D | |
{ | |
if $spec.from eq 'Java' { | |
$!interop = nqp::jvmrakudointerop() unless nqp::isconcrete($!interop); | |
my $jtype = $!interop.typeForName($spec.short-name.subst(/'::'/, '.', :g), $.prefix.abspath); | |
# register the class by its name (cf. Inline::Perl5, nine++) | |
my @parts = $spec.short-name.split('::'); | |
my $inner = @parts.pop; | |
my $ns := ::GLOBAL.WHO; | |
for @parts { | |
$ns{$_} := Metamodel::PackageHOW.new_type(name => $_) unless $ns{$_}:exists; | |
$ns := $ns{$_}.WHO; | |
} | |
my @existing = $ns{$inner}.WHO.pairs; | |
$ns{$inner} := $jtype; | |
# $jtype.WHO{$_.key} := $_.value for @existing; | |
nqp::setwho(::($spec.short-name), Stash.new()); | |
::($spec.short-name).WHO<EXPORT> := Metamodel::PackageHOW.new(); | |
::($spec.short-name).WHO<&EXPORT> := sub EXPORT(*@args) { | |
Map.new($inner => nqp::decont($jtype)); | |
} | |
return CompUnit.new( | |
:short-name($spec.short-name), | |
:handle(CompUnit::Handle.from-unit(::($spec.short-name).WHO)), | |
:repo(self), | |
:repo-id($spec.short-name), | |
:from($spec.from), | |
); | |
} | |
return self.next-repo.need($spec, $precomp) if self.next-repo; | |
X::CompUnit::UnsatisfiedDependency.new(:specification($spec)).throw; | |
} | |
method loaded() { | |
[] | |
} | |
method id() { | |
'Java' | |
} | |
method path-spec() { | |
'java#' | |
} | |
method short-id { | |
'java' | |
} | |
} | |
# vim: ft=perl6 expandtab sw=4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment