erlang_perl
is a linked-in driver, API, and OTP application that
embeds Perl interpreter in Erlang.
Originally created to facilitate usage of Riak’s MapReduce
by non-Erlang programmers, it supports runtime evaluation of Perl code, and
invocation of Perl functions.
You must have Erlang/OTP R13B04 or later and a GNU-style build
system to compile and run erlang_perl
.
git clone git://github.com/yko/erlang_perl.git
make all test
Start up an Erlang shell with the path to erlang_perl
included.
erl -pa path/to/erlang_perl/ebin -boot start_sasl
Start the erlang_perl
application and create a Javascript VM.
1> application:start(erlang_perl).
=PROGRESS REPORT==== 6-Dec-2014::23:30:38 ===
supervisor: {local,erlang_perl_sup}
started: [{pid,<0.47.0>},
{name,cache},
{mfargs,{js_cache,start_link,[]}},
{restart_type,permanent},
{shutdown,2000},
{child_type,worker}]
=PROGRESS REPORT==== 6-Dec-2014::23:30:38 ===
application: erlang_perl
started_at: nonode@nohost
ok
2> {ok, Perl} = perl_driver:new().
Now you can evaluate Perl expressions, install and call your own Perl subroutines.
3> {ok, Result} = perl:eval(Perl, <<"40 + 2">>).
{ok,42}
4> {ok, Sub} = perl:define(Perl, <<"sub { my $args = shift; $args->[0] + 1; }">>).
{ok,<<"_GEN_0">>}
5> perl:call_sub(Perl, Sub, [3]).
{ok,4}