=encoding UTF-8 =head1 NAME Ruby - Perl interface to Ruby interpreter =head1 SYNOPSIS 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 &LWP::Simple::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 @_ }); =head1 DESCRIPTION This module provides an interface to a ruby interpreter that is installed in your machine. =head1 IMPORT COMMAND =over 4 =item -function => functions =item -variable => global_variables Imports I and/or I. C<-variable> is a synonym for C<-funcion>. =item -class => classes =item -module => modules Installs I and/or I of Ruby. C<-module> is a synonym for C. =item -all Does C<< -function => ':DEFAULT', -class => ':ALL', -literal >>. =item -require => libraries Loads I at the compile time. =item -eval => source_code Evals I, and imports the classes and functions that are defined in I. =item -base => base_class Sets up the is-a relationship with I, like C. =item -literal => [ 'all' | 'string' | 'numeric' | 'integer' | 'float' ] =item -no_literal Enables/Disables literal overloading. =item -autobox =item -no_autobox Enables/Disables literal autoboxing. =back =head1 INTERPRETER FEATURE =head2 Constants These are imported by default. =over 4 =item true =item false =item nil =back =head2 Functions These are imported by default. =over 4 =item rb_eval(source [, package [, file [, line]]]) Evals I as Ruby code. If I is suplied, those classes and functions that are defined in I are imported to I automatically. =item rb_require(library) Loads I at the run time. =item p(...), puts(...) Equivalent to ruby's C and C. =item rubyify(perldata) Rubyifies I to use some ruby-like methods. For example: rubyify(\%ENV)->each(sub{ my($key, $value) = @_; puts "$key=$value"; }); =back These functions are importable: =over 4 =item rb_c(class) =item rb_m(module) =item rb_e(exeption) Obtains the defined I, I or I object. =item rb_const(constant) Obtains the I. For example: p rb_const(RUBY_VERSION); p rb_const(File::Constant);# == rb_c(File::Constant) =back =head1 RUBY FUNCTIONS Those functions defined in Ruby interpreter are importable. For example: use Ruby qw(lambda(&)); my $lambda = lambda { ... }; $lambda->(...); =head1 NOTE =head2 Continuation, catch/throw Ruby's C and C will throw C. =head2 Ruby thread Ruby threads sometimes cause core dumps. =head2 Perl thread Perl threads often cause core dumps. =head1 BUGS Maybe there are a lot of bugs. =head1 SEE ALSO L =head1 AUTHOR Goro Fuji (藤 吾郎) Egfuji(at)cpan.orgE =head1 COPYRIGHT Copyright (c) Goro Fuji. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut