Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

philcrow (3401)

  (email not shown publicly)

Journal of philcrow (3401)

Thursday August 09, 2007
04:51 PM

Java to Perl Wrap-Up

[ #34065 ]

My life is full of news. So full I haven't even had time to tell all the relevant people about it. That includes those in the Perl community interested in my work on Java::Javap a Java to Perl 6 API translator.

Just in time for OSCON, I released version 0.04 of Java::Javap to CPAN. The module name comes from the Java development kit decompilation tool called javap. If you have that installed on your machine (and in your path), Java::Javap will translate .class files into corresponding Perl 6 .pm files which stub out the API of the Java module.

End users will be most interested in the command line tool java2perl6 (which someone pointed sounds like a lopsided world cup score with our favorite language having the better of it). Using the tool can be as simple as:

java2perl6 java.sql.Connection

That would create in the current directory. There are flags to control where the output lands and whether it falls into a normal directory hierarchy. The POD for the script has details and examples. If you add the -r (a.k.a. --recurse), java2perl6 will keep track of Java types encountered as super class types, return types, and method argument types and recursively translate their APIs as well (common types are skipped).

Those interested in details should read on for some of them. There are three phases to the translation. The first one just uses javap to decompile the requested class. The second uses a Parse::RecDescent grammar to parse the javap output into a simple (for some definition of simple) tree. The third phase takes the tree and makes output. java2perl6 takes a command line flag -g (a.k.a. --genwith) as the name of an output generator. All of these must live in the Java::Javap::Generator:: namespace. The POD for Java::Javap::Generator explains the API generators must implement. The test scripts have examples of the parse tree structure.

During this project, I only wrote one generator and it makes perl 6 output. It is Java::Javap::Generator::Std and uses Template Toolkit. Other generators are possible and the output is entirely up to their authors. For instance, it would not be that hard to generate Python (shudder).

I would like to thank the Perl Foundation for making the grant that supported this work; Jesse Vincent who coordinated the TPF end; Tim Bunce for suggesting the project, urging me to apply for the grant, and for his support, suggestions, and patches. Tim also gave a lightning talk at OSCON about this project, I thank him for that effort as well.

While I had hoped to write the code for this project in Perl 6, I am pleased with the result which is all in Perl 5. Comments, suggestions, questions, and patches are all welcome.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.