
Ruby - Perl interface to Ruby interpreter

use Ruby
':DEFAULT',
-require => 'complex', # load Ruby's library
'digest/md5', # load Ruby's extention
-function => 'Rational', # import Ruby's function
-class => qw(GC Object), # import Ruby's classes
-module => qw(Kernel), # synonym for -class
-variable => ['$!' => '$rb_errinfo'], # $! as $rb_errinfo
-function => ['String' => 's'], # String() as &s()
-class => ['Config' => 'RubyConfig'], # Config as RubyConfig
-literal => 'all', # literals are overloaded
-no_literal => 'all',
-autobox, # literals are autoboxed
-no_autobox,
-eval => <<'EOR', # eval and import 'add()', 'MyObject'
def add(x,y)
x.to_f + x.to_f
end
class MyObject
def my_method
"OK"
end
end
EOR
;
use Ruby -all; # -function => ':DEFAULT' && -class => ':ALL' && -literal
p($Ruby::Version); # => "1.8.6", for example
p(add(1, 2)); # => 3.0
p(MyObject->my_method); # => "OK"
rb_eval(<<'EOS', __PACKAGE__);
p __PACKAGE__; # => "main"
Perl::eval("use LWP::Simple");
# should be Perl's string
uri = Perl.String("http://www.ruby-lang.org/");
getprint(uri); # call # &main::getprint
EOS
use Ruby -literal;
# String/Integer/Float are overloaded
p "foo"->class; # String
p ref("foo"); # "Ruby::Object"
10->times(sub{ p @_ });
p "foo"->upcase;
use Ruby -autobox;
[qw(foo bar baz)]->each(sub{ p @_ });

This module provides an interface to a ruby interpreter that is installed in your machine.

Imports functions and/or global_variables.
-variable is a synonym for -funcion.
Installs classes and/or modules of Ruby.
-module is a synonym for class.
Does -function => ':DEFAULT', -class => ':ALL', -literal.
Loads libraries at the compile time.
Evals source_code, and imports the classes and functions that are defined in source_code.
Sets up the is-a relationship with base_class, like base.pm.
Enables/Disables literal overloading.
Enables/Disables literal autoboxing.

These are imported by default.
These are imported by default.
Evals source as Ruby code.
If package is supplied, those classes and functions that are defined in source are exported to package automatically.
Loads library at the run time.
Equivalent to ruby's p() and puts().
Rubyifies perldata to use some ruby-like methods.
For example:
rubyify(\%ENV)->each(sub{
my($key, $value) = @_;
puts "$key=$value";
});
This method doesn't convert perldata to Ruby data. It wraps perldata with Ruby object.
These functions are importable:
Obtains the defined class, module or exception object.
Obtains the constant.
For example:
p rb_const(RUBY_VERSION);
p rb_const(File::Constant);# == rb_c(File::Constant)

Those functions defined in Ruby interpreter are importable.
For example:
use Ruby qw(lambda(&));
my $lambda = lambda { ... };
$lambda->(...);

Ruby's callcc and catch/throw functions throw LocalJumpError.
Ruby threads may cause core dumps.
Perl threads will cause core dumps.

This module is very experimental. There are a lot of bugs.


Goro Fuji (藤 吾郎) <gfuji(at)cpan.org>

Copyright (c) 2008, Goro Fuji. Some rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.