Leon Timmermans - Embedding perl into C++ applications

Title: Embedding perl into C++ applications

Name: Leon Timmermans

Grant Manager: Adrian Howard

Duration: three to four months

Started: October, 2008

Synopsis:
Currently embedding perl is too complicated. The API requires too much knowledge of internals to use and is too incompatible with other libraries (mainly due to the usage of macros). Therefore I've started a project to ease the embedding of Perl. Though the code works, it is not ready for public consumption yet. In this proposal I want to make it ready for widespread adoption.

Benefits to the Perl Community:
Currently perl is only embedded in a handful of application (Apache's mod_perl is the best known example of this). This library could lead to increased adoption of perl as an embedded language, a role it currently isn't particularly strong in.

Deliverables:

  • Document the whole API
  • Generate broad unit testing
  • Port the code to perl 5.10
  • Add regexp support (may not be workable on perl 5.8)
  • Make build process portable
  • Make exporting of functions, methods and constructors robust enough for real usage.

Project Details:
libperl++ is a C++ library that provides a more friendly interface for the perl API. It makes use of advanced features of C++ to make both embedding and extending perl as easy as possible. I guess an example is worth more than a description.

Interpreter universe;
Package dbi = universe.use("DBI");
Ref<Hash> foo = dbi.call("connect", "dbi:SQLite:dbname=dbfile", "", "");
Array bar = foo.call_array("selectrow_array", "SELECT * FROM test WHERE name = ?", universe.undef(), "a");
bar[2] = "c";
String packed = bar.pack("a*");

// These two do the same
std::foreach(bar.begin(), bar.end(), print);
bar.each(print);

Ref<Code> sub = universe.eval("sub { print \"@_\n\"}");
sub(bar);

Ref<Array> baz = bar.take_ref();

universe.export_sub("atan", atan);
Scalar angle = universe.eval("atan(1)");

Issues left:

Not all of the API has been documented, nor is there a proper tutorial. This obviously needs to be rectified.

Another major issue is that there is no unit testing yet. This is mainly because there is no proper C++ testing framework that outputs TAP. I've started writing just that, but I still have to make the tests themselves.

The code was written using PERL_NO_SHORT_NAMES on perl 5.8. However this has generated some incompatibilities with perl 5.10. These need to be fixed.

Regexp support is currently a rather notable missing feature in the library. This is because perl 5.8 is somewhat resistant to that. I'm having the impression it won't be too much work to add it with perl 5.10, and it can probably be wrapped into 5.8.

Currently the building process is a simple makefile. That obviously isn't a very portable or maintainable solution. Currently neither ExtUtils::MakeMaker nor Module::Build seem to be capable of making shared libraries. I'm planning to move to a better solution.

I have implemented exportation of C++ functions, methods and constructors to perl, but (specially the latter two) still have some issues left to make them more usable in real projects.

Naming issue:
There already is a library with a similar purpose and name. It's implementation is quite old and unmaintained, but of the name collision is too much of a hassle I can always rename it.

Project Schedule:
I can start in September. I think I can do the work spread out over a period of 3 or 4 months.

Bio:
I'm a 23 years old Dutch university student who has been programming perl for some 8 years. ve As the author of this project I am the most logical person to do it.

Amount Requested:
Since this is a big project I'd like to request the maximal amount of $3000.