Hi everyone,
After more than a year of putting it off, I finally sat down this week and
started Inline::Ruby. It's still young, but already code like this works:
----8<----
use Inline Ruby;
my $obj = new Iterator(1, "2", [3], {4 => 5});
$obj->each_iter(sub {
use Data::Dumper;
my $element = shift;
print "It looks like Ruby passed me this: ", Dumper($element);
});
__END__
__Ruby__
class Iterator
def initialize(*elements)
@elements = elements
end
def each
@elements.each { |x| yield x }
end
end
---->8----
The output is (edited for brevity):
----8<----
ttul:~/dev/cpan/Inline-Ruby$ perl -Mblib t.pl
Using /home/nwatkiss/dev/cpan/Inline-Ruby/blib
It looks like Ruby passed me this: $VAR1 = 1;
It looks like Ruby passed me this: $VAR1 = [3];
It looks like Ruby passed me this: $VAR1 = '2';
It looks like Ruby passed me this: $VAR1 = {'4' => 5};
---->8----
I've tested it with Ruby 1.6.3 through 1.6.6, against Perl 5.6.0 and 5.6.1.
I've only tried it on Linux so far. All helpers are welcome!
Some things which aren't working:
+ can't bind to functions (only classes & methods).
+ using iterators requires you to add "_iter" to the end of the method name
(ugly, confusing)
Where to get it:
http://ttul.org/~nwatkiss/CPAN/dev/Inline-Ruby-0.01-pre2.tar.gz
I think that's it. This module is still riddled with bugs; feel free to email
test cases or patches to me as you find them. There's actually quite a lot of
documentation in the distro, but no README yet (sorry!).
Thanks,
Neil
PS - writing this module has made me fall in love with Ruby. I have to get
back into Perl mode before I go back to work next week!