Stories
Slash Boxes
Comments
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)

philcrow
  (email not shown publicly)

Journal of philcrow (3401)

Monday September 15, 2008
09:58 AM

New Perl Patterns Book

Update: I am very sorry that spell checking fell off of my to do list for this book. I have corrected many annoying errors and a new version is available. If you bought one in the last 24 hours, please write to me at the email address in the preface, so that I may replace your copy.

I'm pleased to announce the arrival of Perlish Patterns, my new book responding to the patterns movement, available from my lulu storefront.

This book is an expansion of a series of articles I wrote once upon a time for perl.com. In the book, I address every pattern from the venerable Design Patterns by Gamma and others (the gang of four), plus some others. While the gang of four focus on object oriented solutions, I use a richer toolkit to explore other options available in Perl. For a fuller description, see www.perlishpatterns.com.

Also availble from my lulu store are a book on the Gantry web framework and a novella about how our corporate overlords could leverage networked computing to become as dangerous to free society as totalitarian governments.

Thursday August 09, 2007
04:51 PM

Java to Perl Wrap-Up

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 Connection.pm 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.

Wednesday July 18, 2007
05:55 PM

java2perl6 version 0.02

I have just uploaded version 0.02 of java2perl6 to CPAN (the dist is called Java::Javap in honor of the Java deparser).

The new version has one important bug fix (qualified module names are now qualified for Perl instead of java in generated perl code). But, mostly it has a working java2perl6 command line tool. The only flag not implemented is --recurse which will eventually recursively visit class files discovered in the class you specify on the command line (and the ones it finds in those...).

I also added a check to the tests so they won't run if javap is not in the installing user's path. Surprisingly enough many of the CPAN testers don't have Java development kits installed.

Phil

Update: Corrected spelling of missing flag name (nest already works, recurse is not in yet).

Wednesday July 04, 2007
09:11 AM

Where I have been

After I released the 0.01 version of Java::Javap to CPAN, my attention was diverted by YAPC::NA in Houston. I had a good time and was exhausted by Wednesday at noon. I'm not sure where people get the stamina for the final two days (I skipped those).

At YAPC I gave a talk about our framework http://usegantry.org/. The slides are on the site home page along with lots of other information, of course. There are also links to the slides on the YAPC Wiki and on my talk's abstract page.

I had hoped to gain some insight into how constructors ought to be written at YAPC. Either because I missed the session, or because I didn't ask the right people, I heard nothing about OO perl 6. I did learn lots of other interesting things and was introduced to many modules that will probably find their way into my code.

So, I am still at a loss about what to do with constructors in Perl 6 Java linkage APIs. I'm again reading the docs. By this weekend I will either pick a set of methods for classes or abandon the effort. In any case the CPAN module has a grammar for deparsed Java and a factory scheme to introducing generators at invocation time, so someone more familiar with Perl 6 classes will only need an interest in the problem and a small bit of time to finish that piece.

The only other thing that remains is to implement support for the rest of the command line flags. Thus, I hope to complete my work on this module by the end of the month.

Phil

Saturday June 16, 2007
01:23 PM

Java to Perl now on CPAN

You can now download Java::Javap from CPAN to get the java2perl6 command line tool (javap is the standard java decompilation tool). This is not a finished product. The script will work on Java interfaces (classes are not yet supported properly). Output dumps to the screen. That output is a Perl 6 role for the java interface.

I need to learn enough about Perl 6 classes to generate proper output before supporting classes. In the mean time I plan to add support for controlling where output goes and for recursing through encountered types. For instance, if a method in class org.example.Useless returns an object of type org.example.Useless.Helper, recursing would process Helper after Useless processing finished.

I will also be heading to YAPC a week from tomorrow, so I'm putting some work into my talk on our shop's web framework called Gantry.

Phil

Saturday June 09, 2007
11:20 AM

More work on emitting Perl 6 from Java

I can't claim to have done a lot this week. But, I did create a factory mechanism for generation so you aren't tied to how I turn ASTs into Perl 6 code.

I also started work on the command line tool. It closely mimics the two operative tests. It needs more features and has no POD.

There is one issue I need to resolve for classes. Currently, I'm correctly generating interfaces. But, classes are slightly different.

For interfaces, I've decided that roles are the proper Perl 6 structure. That can't exactly work for classes. They need constructors, which roles are not allowed to have. Probably Java interfaces will become Perl 6 roles, while classes will map to classes.

Even if I decide to use Perl 6 classes for Java classes, I still have to figure out how to handle constructors in Perl 6. That will take some more study on my part. I'm not comfortable with sub method BUILD etc. yet.

Phil

Saturday June 02, 2007
09:13 AM

Emitting a Perl 6 role

I have begun work on the last of the three steps in converting Java APIs to Perl 6 roles: emitting Perl 6. Now I have a method of turning this:

public interface IntTest {
    public static final int USELESS_CONSTANT = 4;
    public abstract int[][] array_returner(
        java.lang.String s, int i, float[] f, float[][] g
    );

    public abstract java.lang.String object_returner()
        throws java.lang.NumberFormatException, java.lang.Exception;
    public abstract java.lang.String object_returner( java.lang.String s )
        throws java.lang.NumberFormatException;

    public abstract void void_returner( int i );
}

Into:

# This file was automatically generated Sat Jun  2 09:06:47 2007# by java2perl6 0.1 from decompiling
# IntTest using command line flags:
#   --classpath testjavas

role IntTest {

    method array_returner(
        Str v1,
        Int v2,
        Array of Num v3,
        Array of Array of Num v4,
    ) returns Array of Array of Int { ... }

    multi method object_returner(
    ) returns Str { ... }

    multi method object_returner(
        Str v1,
    ) returns Str { ... }

    method void_returner(
        Int v1,
    )  { ... }

}

Some work remains. I need to finish the command line tool to smoothly make translations like the above. I need to make sure that classes work as well as interfaces. Some documentation is also essential but absent.

Phil

Tuesday May 15, 2007
06:25 PM

Java to Perl now in google code

In the last couple of weeks I've started writing tests, for the Java to Perl 6 API converter, which are repeatable. That meant writing my own Java code, so I know the API won't grow unexpectedly. The tests pointed out one rough spot in the parse tree that I need to knock flat.

I've also set up an svn repo for the project as part of google code. The project is called java2perl6. Interested parties are welcome to search for it at http://code.google.com.

In the next couple of weeks, I hope to fix the parse tree, and begin reading about Perl 6 roles. I think roles seem like the best concept in Perl 6 to target, as opposed to classes or regular modules.

Phil

Monday April 30, 2007
05:45 PM

javap Perl 5 grammar

I decided to take a temporary detour into perl 5, since named captures are not yet in pugs. I've finished the grammar and produced an Abstract Syntax Tree for javap output. The only thing I still want is to actually load the java classes so I can pull constant values from them. Other than that, the grammar is complete in Perl 5.

Now I must study Perl 6 role declarations so I can generate the ones that correspond to my ASTs.

I also need to give some thought to formal testing. So far, I've been manually checking the output for a couple of key class/interfaces. But, I don't trust them to be stable. So, I will have to write some reliable java myself. Then, I'll know that it won't change with Java updates.

Phil

Monday April 16, 2007
06:01 PM

Java to Perl Grammar snag

I've hit a snag with my Java to Perl 6 API converter. Apparently pugs grammars are not yet returning ASTs as the synopsis describes.

I'm still weighing what to do about that. There are several options. Of course, I could learn Haskell and pitch in on the grammar internals of Perl 6, but that seems unlikely. I'd be starting from scratch on Haskell, having never coded in a functional language before, with almost no background in grammar implementation (one admittedly close reading of the dragon book notwithstanding).

Alternatively, I could approach this as an exercise in Perl 6 generation where the implementation language of the generator is immaterial. This is not ideal, because part of why I wanted to work on this project was to learn about Perl 6 grammars. But it would enable me to implement something. Then I would implement the code in Perl 5, waiting for the right moment to translate it to Perl 6.

Or, if grammars building ASTs are imminent, I could wait for the features to appear, then start.

I'm leaning heavily toward implementing in Perl 5, but have not yet firmly decided.

In the meantime, I've been thinking (with help from Tim Bunce) about the structure of the AST I want the grammar to build. The design sketch is basically done.

All that is to say, that I hope to make some coding progress this week.

Phil