1

I was wondering is there is any way to interact with Perl 5 code automatically, without creating explicit APIs and publishing it over some protocol. I don't want to limit this question to any specific ways of achieving that - I'm looking for any ideas.

Ruby can be accessed from JVM-based languages via JRuby for example; natively compiled languages are usually accessible via native shared libs / standard calling convention for that platform; others can have the interface autogenerated from code... What are the options for Perl?

viraptor
  • 33,322
  • 10
  • 107
  • 191
  • @Virator: I’m not at all sure what that means. Your first paragraph doesn’t map into any known slots in my brain, and the second is nearly as mysterious. Are you talking about XS stuff or what? – tchrist Nov 25 '10 at 00:44
  • @tchrist: I want to access some legacy Perl code (that I don't really want to touch) from some other language. Hopefully phasing out the Perl part over time. I'm looking for ways to do that. – viraptor Nov 25 '10 at 01:03
  • 1
    honestly, taking legacy Perl code and turning it into an API by writing some minor wrapper around it (from plain old pipe data passing to some socket communication to ...) sounds to me LOTS easier than trying to merge Perl and non-Perl code on native level. YMMV :) – DVK Nov 25 '10 at 02:25
  • @DVK: It's definitely an option. I'll just have to test both ways and see what's easier to use (and what requires less perl rewrites). – viraptor Nov 25 '10 at 02:31

2 Answers2

4

As one option, you can embed a Perl interpreter, as shown here or here or here

DVK
  • 126,886
  • 32
  • 213
  • 327
  • Following that idea, I found `pyperl` too http://search.cpan.org/~gaas/pyperl-1.0/perlmodule.pod - easy embedding of perl in python. – viraptor Nov 25 '10 at 00:51
4

There is library for embedding Perl into your program (see perlembed.pod) that is compiled automatically - any language can use it, pyperl for Python, PEAR "Perl" extension for PHP, several attempts on using Perl 5 from Perl 6, several attempts to run Perl from JVM (all not finished), Perl.NET.

Also you can go other way, embed program in other language in Perl and just call Perl subs from program in other language. Main Perl program would consist just of calling your program in other language. There is big number of CPAN modules that integrate other languages.

Alexandr Ciornii
  • 7,346
  • 1
  • 25
  • 29
  • I can see a lot of projects like that, but it's sometimes hard to see which ones are "proof of concept" type and which are serious projects published because they're actually used somewhere and maintained (which is what I'm looking for :) ) – viraptor Nov 25 '10 at 02:00
  • perlembed.pod is the very first link in my answer, FYI :) (you answer provides pretty good detail so i'm glad you gave it, though) – DVK Nov 25 '10 at 02:18