Skip to content

Commit

Permalink
Merge branch 'master' into extract-interpreter-binding
Browse files Browse the repository at this point in the history
Fixing minor conflict
  • Loading branch information
Brock Wilcox committed Jan 12, 2017
2 parents 82fe889 + 5781f8c commit 252c440
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 235 deletions.
10 changes: 7 additions & 3 deletions Build.pm
@@ -1,9 +1,7 @@
use v6;
use Panda::Builder;
use Shell::Command;
use LibraryMake;

class Build is Panda::Builder {
class Build {
method build($dir) {
shell('perl -e "use v5.18;"')
or die "\nPerl 5 version requirement not met\n";
Expand All @@ -23,6 +21,12 @@ class Build is Panda::Builder {
shell(%vars<MAKE>);
chdir($goback);
}

# only needed for older versions of panda
method isa($what) {
return True if $what.^name eq 'Panda::Builder';
callsame;
}
}

# vim: ft=perl6
2 changes: 1 addition & 1 deletion META.info
@@ -1,6 +1,6 @@
{
"name" : "Inline::Perl5",
"version" : "0.21",
"version" : "0.22",
"perl" : "6.c",
"author" : "github:niner",
"authors" : [ "Stefan Seifert" ],
Expand Down
13 changes: 10 additions & 3 deletions README.md
Expand Up @@ -53,6 +53,13 @@ Inline::Perl5's use() method maps to Perl 5's use statement:
$p5.use('Test::More');
```

To load a Perl 5 module from a specific folder:

```
use lib:from<Perl5> 'lib';
use MyModule:from<Perl5>;
```

## Load a Perl 5 module and import functions

Just list the functions or groups you want to import
Expand Down Expand Up @@ -304,14 +311,14 @@ can be caught like any other Perl 5 exceptions:

## Mix Perl 5 and Perl 6 code in the same file

Inline::Perl5 creates a virtual module called "v6::inline". By saying
"use v6::inline;" in a Perl 5 module, you can declare that the rest of the file
Inline::Perl5 creates a virtual module called "v6-inline". By saying
"use v6-inline;" in a Perl 5 module, you can declare that the rest of the file
is written in Perl 6:

```
package Some::Perl5::Module;
use v6::inline;
use v6-inline;
has $.name;
Expand Down
68 changes: 20 additions & 48 deletions lib/Inline/Perl5.pm6
Expand Up @@ -785,20 +785,17 @@ method init_callbacks {
return bless $self, $class;
}
my $delete_key = 'DELETE-KEY';
sub DELETE {
my ($self, $key) = @_;
return Perl6::Object::call_method('DELETE-KEY', $self->[0], $key);
}
sub CLEAR {
die 'CLEAR NYI';
}
my $exists_key = 'EXISTS-KEY';
sub EXISTS {
my ($self, $key) = @_;
return Perl6::Object::call_method('EXISTS-KEY', $self->[0], $key);
}
my $pull_one = 'pull-one';
sub FIRSTKEY {
my ($self) = @_;
$self->[1] = [ Perl6::Object::call_method('keys', $self->[0]) ];
Expand Down Expand Up @@ -878,12 +875,6 @@ method init_callbacks {
v6::invoke($static_class, 'new_shadow_of_p5_object', $object);
return $object;
}
sub import {
die 'v6-inline got renamed to v6::inline to allow passing an import list';
}
package v6::inline;
use mro;
sub install_function {
Expand All @@ -899,33 +890,17 @@ method init_callbacks {
my ($package, $name, @attributes) = @_;
no strict 'refs';
*{"${package}::$name"} = my $code = v6::set_subname("${package}::", $name, sub {
return Perl6::Object::call_method($name, @_);
return Perl6::Object::call_extension_method($p6, $package, $name, @_);
});
attributes->import($package, $code, @attributes) if @attributes;
return;
}
{
my @inlined;
BEGIN {
no strict "refs";
*{"CORE::GLOBAL::bless"} = sub {
my ($self, $class) = @_;
$class //= scalar caller;
CORE::bless($self, $class);
foreach my $package (@inlined) {
if ($self->isa($package)) {
v6::shadow_object($package, $class, $self);
last;
}
}
$self
};
};
my $package_to_create;
sub import {
my ($class, %args) = @_;
my $package = $package_to_create = scalar caller;
push @inlined, $package;
}
Expand All @@ -936,6 +911,11 @@ method init_callbacks {
};
}
package v6::inline;
sub import {
die 'v6::inline got renamed to v6-inline for compatibility with older Perl 5 versions. Sorry for the back and forth about this.';
}
$INC{'v6.pm'} = '';
$INC{'v6/inline.pm'} = '';
Expand All @@ -961,7 +941,7 @@ method rebless(Perl5Object $obj, Str $package, $p6obj) {
}

method install_wrapper_method(Str:D $package, Str $name, *@attributes) {
self.call('v6::inline::install_p6_method_wrapper', $package, $name, |@attributes);
self.call('v6::install_p6_method_wrapper', $package, $name, |@attributes);
}

role Perl5Package[Inline::Perl5 $p5, Str $module] {
Expand Down Expand Up @@ -1067,8 +1047,10 @@ method require(Str $module, Num $version?) {
$ns := $ns{$_}.WHO;
}
my @existing = $ns{$inner}.WHO.pairs;
$ns{$inner} := $class;
$class.WHO{$_.key} := $_.value for @existing;
unless $ns{$inner}:exists {
$ns{$inner} := $class;
$class.WHO{$_.key} := $_.value for @existing;
}

if $first-time {
# install subs like Test::More::ok
Expand Down Expand Up @@ -1223,25 +1205,15 @@ method BUILD(*%args) {
}
else {
my @args = @*ARGS;
$!p5 = @args
?? Inline::Perl5::Interpreter::p5_init_perl(
@args.elems + 4,
CArray[Str].new('', '-e', '0', '--', |@args),
&call_method,
&call_callable,
&free_p6_object,
&hash_at_key,
&hash_assign_key,
)
!! Inline::Perl5::Interpreter::p5_init_perl(
3,
CArray[Str].new('', '-e', '0'),
&call_method,
&call_callable,
&free_p6_object,
&hash_at_key,
&hash_assign_key,
);
$!p5 = Inline::Perl5::Interpreter::p5_init_perl(
@args.elems + 4,
CArray[Str].new('', '-e', '0', '--', |@args, Str),
&call_method,
&call_callable,
&free_p6_object,
&hash_at_key,
&hash_assign_key,
);
X::Inline::Perl5::NoMultiplicity.new.throw unless $!p5.defined;
}

Expand Down

0 comments on commit 252c440

Please sign in to comment.