Permalink
Browse files

Rename Niecza::Interoperability to Niecza.

Make Niecza a full Module::Build using module with an XS part.
  • Loading branch information...
1 parent 4927ce0 commit 02fe910c951d4b48b0fdc018630b799b25ee3441 @pmurias pmurias committed Feb 24, 2012
View
@@ -3694,7 +3694,7 @@ public class DowncallReceiver : CallReceiver {
}
public static object unit_use_perl5_module(object[] args) {
string name = (string)args[2];
- Variable code = Kernel.BoxAnyMO<string>("Niecza::Interoperability::use_module('"+name+"')", Kernel.StrMO);
+ Variable code = Kernel.BoxAnyMO<string>("Niecza::Helpers::use_module('"+name+"')", Kernel.StrMO);
string sub = Kernel.UnboxAny<string>(Builtins.eval_perl5(code).Fetch());
return sub;
}
View
@@ -6,7 +6,7 @@
public class Perl5Interpreter : IForeignInterpreter {
[DllImport("p5embed", EntryPoint="p5embed_initialize")]
- public static extern void Initialize(string p5lib);
+ public static extern void Initialize(string path1,string path2);
[DllImport("p5embed", EntryPoint="p5embed_dispose")]
public static extern void Dispose();
@@ -86,8 +86,18 @@ int argument_n
public Perl5Interpreter() {
string location = System.Reflection.Assembly.GetExecutingAssembly().Location;
- string p5lib = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(location)),"perl5");
- Initialize(p5lib);
+
+ string[] paths = new string[] {"perl5/Niecza/blib/lib","perl5/Niecza/blib/arch"};
+
+ for (int i=0;i<2;i++) {
+ // Try to construct the path in a platform portable manner
+ string p5lib = Path.GetDirectoryName(Path.GetDirectoryName(location));
+ foreach (string part in paths[i].Split('/')) {
+ p5lib = Path.Combine(p5lib,part);
+ }
+ paths[i] = p5lib;
+ }
+ Initialize(paths[0],paths[1]);
}
~Perl5Interpreter() {
Dispose();
View
@@ -17,7 +17,7 @@ xs_init(pTHX)
}
static PerlInterpreter *my_perl;
-void p5embed_initialize(char* p5lib)
+void p5embed_initialize(char* path1,char* path2)
{
int argc = 1;
char *argv0[] = { "perl", NULL, 0 };
@@ -29,9 +29,13 @@ void p5embed_initialize(char* p5lib)
perl_parse(my_perl, xs_init, 3, embedding, NULL);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
AV* INC = get_av("INC",0);
- SV* p5lib_sv = newSVpv(p5lib,0);
- av_push(INC,p5lib_sv);
- eval_pv("use Niecza::Interoperability",TRUE);
+ char* path[2] = {path1,path2};
+ int i;
+ for (i=0;i<2;i++) {
+ SV* p5lib_sv = newSVpv(path[i],0);
+ av_push(INC,p5lib_sv);
+ }
+ eval_pv("use Niecza",TRUE);
}
SV* p5embed_eval(char* code) {
View
@@ -1,14 +1,14 @@
Build.PL
Changes
+ignore.txt
lib/Niecza.pm
lib/Niecza.xs
+lib/Niecza/Helpers.pm
lib/typemap
MANIFEST This list of files
ppport.h
README
-t/00-load.t
-t/01-object.t
-t/02-feature.t
+t/boilerplate.t
t/manifest.t
t/pod-coverage.t
t/pod.t
View
@@ -5,7 +5,7 @@ use strict;
=head1 NAME
-Niecza - The great new Niecza!
+Niecza - The perl5-niecza interoperability support;
=head1 VERSION
@@ -18,73 +18,20 @@ our $VERSION = '0.01';
require XSLoader;
XSLoader::load('Niecza', $VERSION);
-=head1 SYNOPSIS
-
-Quick summary of what the module does.
-
-Perhaps a little code snippet.
-
- use Niecza;
-
- my $foo = Niecza->new();
- ...
-
-=head1 EXPORT
-
-A list of functions that can be exported. You can delete this section
-if you don't export anything, such as for a purely object-oriented module.
-
-=head1 FUNCTIONS
-
-=head2 new
-
-Creates a new Niecza object. Takes the following optional parameters:
-
-=over 4
-
-=item value
+use Niecza::Helpers;
-If you pass a single numeric value, it will be stored in the 'value' slot
-of the object hash.
-
-=item key/value pair
-
-A generic input method which takes an unlimited number of key/value pairs
-and stores them in the object hash. Performs no validation.
-
-=back
-
-=cut
-
-#sub new {
-# Defined in the XS code
-#}
-
-=head2 increment
-
-An object method which increments the 'value' slot of the the object hash,
-if it exists. Called like this:
-
- my $obj = Niecza->new(5);
- $obj->increment(); # now equal to 6
-
-=cut
+=head1 SYNOPSIS
-#sub function2 {
-# Defined in the XS code
-#}
+use v6;
+eval(:lang<perl5>,"...");
=head1 AUTHOR
Paweł Murias, C<< <pawelmurias@gmail.com> >>
=head1 BUGS
-Please report any bugs or feature requests to
-C<bug-niecza@rt.cpan.org>, or through the web interface at
-L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Niecza>.
-I will be notified, and then you'll automatically be notified of progress on
-your bug as I make changes.
+Please report any bugs or feature requests on the #perl6 on freenode.org IRC channel or using the github bugtracker for niecza.
=head1 ACKNOWLEDGEMENTS
View
@@ -4,63 +4,6 @@
#include "ppport.h"
-typedef SV * Niecza;
MODULE = Niecza PACKAGE = Niecza
-Niecza
-new(...)
- INIT:
- char *classname;
- /* get the class name if called as an object method */
- if ( sv_isobject(ST(0)) ) {
- classname = HvNAME(SvSTASH(SvRV(ST(0))));
- }
- else {
- classname = (char *)SvPV_nolen(ST(0));
- }
-
- CODE:
- /* This is a standard hash-based object */
- RETVAL = (Niecza)newHV();
-
- /* Single init value */
- if ( items == 2 )
- hv_store((HV *)RETVAL, "value", 5, newSVsv(ST(1)), 0);
- /* name/value pairs */
- else if ( (items-1)%2 == 0 ) {
- int i;
- for ( i=1; i < items; i += 2 ) {
- hv_store_ent((HV *)RETVAL, ST(i), newSVsv(ST(i+1)), 0);
- }
- }
- /* odd number of parameters */
- else {
- Perl_croak(aTHX_
- "Usage: Niecza->new()\n"
- " or Niecza->new(number)\n"
- " or Niecza->new(key => value, ...)\n"
- );
- }
-
- OUTPUT:
- RETVAL
-
-IV
-increment(obj)
- Niecza obj
-
- INIT:
- RETVAL = 0;
- if ( items > 1 )
- Perl_croak(aTHX_ "Usage: Niecza->increment()");
-
- CODE:
- SV **svp;
- if ((svp = hv_fetch((HV*)obj, "value", 5, FALSE))) {
- RETVAL = SvIV(*svp);
- RETVAL++;
- hv_store((HV *)obj, "value", 5, newSViv(RETVAL), 0);
- }
- OUTPUT:
- RETVAL
@@ -0,0 +1,15 @@
+package Niecza::Helpers;
+use Package::Stash;
+my $id = 0;
+sub use_module {
+ my ($module) = @_;
+ my $stash = Package::Stash->new('main');#'Niecza::Stash::Interopability::TMP'.$id++);
+ eval("package ".$stash->name.";use $module;");
+ warn $@ if $@;
+ my @subs = $stash->list_all_symbols('CODE');
+ for my $symbol (@subs) {
+ #say "importing sub $symbol from $module";
+ }
+ $subs[0];
+}
+1;
View
@@ -1,9 +0,0 @@
-#!perl -T
-
-use Test::More tests => 1;
-
-BEGIN {
- use_ok( 'Niecza' ) || print "Bail out!\n";
-}
-
-diag( "Testing Niecza $Niecza::VERSION, Perl $], $^X" );
View
@@ -1,22 +0,0 @@
-
-use Test::More tests => 10;
-
-BEGIN {
-use_ok( 'Niecza' );
-}
-
-my $obj;
-
-ok( $obj = Niecza->new(), "no initializer");
-isa_ok($obj,"Niecza");
-
-ok( $obj = Niecza->new(1), "initial numeric value");
-ok($obj->{value} == 1, "implicit initializer");
-
-ok( $obj = Niecza->new("fish"), "initial string value");
-ok($obj->{value} eq "fish", "implicit initializer");
-
-ok( $obj = Niecza->new(color => "red", flavor => "sour"),
- "hash as initializer");
-ok( $obj->{color} eq "red", "first hash key");
-ok( $obj->{flavor} eq "sour", "first hash key");
@@ -1,13 +0,0 @@
-use Test::More tests => 5;
-
-BEGIN {
-use_ok( 'Niecza' );
-}
-
-my $obj = Niecza->new(1);
-ok( $obj->increment );
-ok( $obj->{value} == 2);
-
-$obj = Niecza->new(value => 3);
-ok( $obj->{value} == 3 );
-ok( $obj->increment == 4 );
View
@@ -17,3 +17,4 @@ chomp($ldopts);
my $cc = "$Config{cc} -m32 -shared";
system("$cc lib/p5embed.c -o $path $ccopts $ldopts");
+system("cd perl5/Niecza;perl Build.PL;perl Build");

0 comments on commit 02fe910

Please sign in to comment.