philcrow's Journal philcrow's use Perl Journal en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:43:00+00:00 pudge Technology hourly 1 1970-01-01T00:00+00:00 philcrow's Journal New Perl Patterns Book <b>Update:</b> 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. <p> I'm pleased to announce the arrival of <i>Perlish Patterns</i>, my new book responding to the patterns movement, available from <a href="">my lulu storefront</a>. </p><p> This book is an expansion of <a href=""> a series of articles</a> I wrote once upon a time for In the book, I address every pattern from the venerable <i>Design Patterns</i> 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 <a href=""></a>. </p><p> Also availble from <a href="">my lulu store</a> are a book on the <a href="">Gantry web framework</a> and a novella about how our corporate overlords could leverage networked computing to become as dangerous to free society as totalitarian governments. </p> philcrow 2008-09-15T14:58:42+00:00 books Java to Perl Wrap-Up <p> 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. </p><p> 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<nobr> <wbr></nobr>.class files into corresponding Perl 6<nobr> <wbr></nobr>.pm files which stub out the API of the Java module. </p><p> 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: </p><p> <code> java2perl6 java.sql.Connection </code> </p><p> 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). </p><p> 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. </p><p> 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). </p><p> 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. </p><p> 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. </p> philcrow 2007-08-09T21:51:07+00:00 journal java2perl6 version 0.02 <p> I have just uploaded version 0.02 of java2perl6 to CPAN (the dist is called Java::Javap in honor of the Java deparser). </p><p> 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...). </p><p> 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. </p><p> Phil </p><p> <b>Update: </b> Corrected spelling of missing flag name (nest already works, recurse is not in yet).</p> philcrow 2007-07-18T22:55:43+00:00 journal Where I have been <p> 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). </p><p> At YAPC I gave a talk about our framework <a href=""></a>. 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. </p><p> 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. </p><p> 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. </p><p> 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. </p><p> Phil </p> philcrow 2007-07-04T14:11:55+00:00 journal Java to Perl now on CPAN <p> 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. </p><p> 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. </p><p> 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. </p><p> Phil</p> philcrow 2007-06-16T18:23:43+00:00 journal More work on emitting Perl 6 from Java <p> 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. </p><p> I also started work on the command line tool. It closely mimics the two operative tests. It needs more features and has no POD. </p><p> There is one issue I need to resolve for classes. Currently, I'm correctly generating interfaces. But, classes are slightly different. </p><p> 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. </p><p> 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. </p><p> Phil</p> philcrow 2007-06-09T16:20:18+00:00 journal Emitting a Perl 6 role <p> 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: </p><blockquote><div><p> <tt>public interface IntTest {<br>&nbsp; &nbsp; public static final int USELESS_CONSTANT = 4;<br>&nbsp; &nbsp; public abstract int[][] array_returner(<br>&nbsp; &nbsp; &nbsp; &nbsp; java.lang.String s, int i, float[] f, float[][] g<br>&nbsp; &nbsp; );<br> <br>&nbsp; &nbsp; public abstract java.lang.String object_returner()<br>&nbsp; &nbsp; &nbsp; &nbsp; throws java.lang.NumberFormatException, java.lang.Exception;<br>&nbsp; &nbsp; public abstract java.lang.String object_returner( java.lang.String s )<br>&nbsp; &nbsp; &nbsp; &nbsp; throws java.lang.NumberFormatException;<br> <br>&nbsp; &nbsp; public abstract void void_returner( int i );<br>}</tt></p></div> </blockquote><p> Into: </p><blockquote><div><p> <tt># This file was automatically generated Sat Jun&nbsp; 2 09:06:47 2007# by java2perl6 0.1 from decompiling<br># IntTest using command line flags:<br>#&nbsp; &nbsp;--classpath testjavas<br> <br>role IntTest {<br> <br>&nbsp; &nbsp; method array_returner(<br>&nbsp; &nbsp; &nbsp; &nbsp; Str v1,<br>&nbsp; &nbsp; &nbsp; &nbsp; Int v2,<br>&nbsp; &nbsp; &nbsp; &nbsp; Array of Num v3,<br>&nbsp; &nbsp; &nbsp; &nbsp; Array of Array of Num v4,<br>&nbsp; &nbsp; ) returns Array of Array of Int {<nobr> <wbr></nobr>... }<br> <br>&nbsp; &nbsp; multi method object_returner(<br>&nbsp; &nbsp; ) returns Str {<nobr> <wbr></nobr>... }<br> <br>&nbsp; &nbsp; multi method object_returner(<br>&nbsp; &nbsp; &nbsp; &nbsp; Str v1,<br>&nbsp; &nbsp; ) returns Str {<nobr> <wbr></nobr>... }<br> <br>&nbsp; &nbsp; method void_returner(<br>&nbsp; &nbsp; &nbsp; &nbsp; Int v1,<br>&nbsp; &nbsp; )&nbsp; {<nobr> <wbr></nobr>... }<br> <br>}</tt></p></div> </blockquote><p> 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. </p><p> Phil </p> philcrow 2007-06-02T14:13:47+00:00 journal Java to Perl now in google code <p> 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. </p><p> 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 </p><p> 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. </p><p> Phil</p> philcrow 2007-05-15T23:25:39+00:00 journal javap Perl 5 grammar <p> 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. </p><p> Now I must study Perl 6 role declarations so I can generate the ones that correspond to my ASTs. </p><p> 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. </p><p> Phil</p> philcrow 2007-04-30T22:45:07+00:00 journal Java to Perl Grammar snag <p>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. </p><p> 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). </p><p> 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. </p><p> Or, if grammars building ASTs are imminent, I could wait for the features to appear, then start. </p><p> I'm leaning heavily toward implementing in Perl 5, but have not yet firmly decided. </p><p> 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. </p><p> All that is to say, that I hope to make some coding progress this week. </p><p> Phil</p> philcrow 2007-04-16T23:01:55+00:00 journal Java to Perl Micro Grant <p> I'm a very pleased to receive a Perl Foundation microgrant. For the grant, I'm writing a Java to Perl 6 API converter. This will create the potential for highly similar APIs in both languages. </p><p> I originally wrote a Java API parser for Java::Swing, where I used it to feed a code generator which built the Java-Perl glue for event listener callbacks. Now I will convert that from Perl 5 to Perl 6 and make it more general and user friendly. </p><p> Thanks to Tim Bunce for suggesting the idea and for encouraging me to apply for the grant. He has some plan to use the result to aid development of the Perl 6 DBI, but Perl's DBI is unlikely to emulate Java's JDBC. </p><p> I've already begun planning the code. My initial thought is that there will be three modules. The first will simply shell out to the Java deparser 'javap'. That tool comes with the standard Java dev kit. Users of my module would need to have the tool. In the future, shelling out might not be necessary when the Perl 6 (or Parrot) equivalent of Inline::Java is available. Then the first module could use Java classes from the 'Axis' Apache foundation project instead. </p><p> The second module would take the raw output of javap and parse it using a Perl 6 grammar. Learning about Perl 6 rules is my primary motivation for taking on this task. </p><p> Finally, using the parse tree from the second module, would be a third module (or set of modules) to emit Perl 6 code. </p><p> Tying the three modules together will be a command line script. </p><p> More later...</p> philcrow 2007-04-03T23:15:06+00:00 perl6 Contest over, final thoughts <p> I'm back at my desk in Kansas after spendning most of last week at the Plat_Forms contest in Nurenberg Germany. </p><p> Our team made some strategic time management mistakes which kept us from fully completing the task assigned. But I don't think any team actually finished it. </p><p> The hardest part was attempting to serve soap through our framework in compliance with an exteranlly mandated WSDL file. Perhaps we could have done that with more intimate knowledge of SOAP::Lite. Perhaps Perl needs better SOAP support. Perhaps SOAP is fading into the dark history of computing to join the likes of RPC schemes like DCE. It's hard for me to say. </p><p> We enjoyed touring Nurenberg. The old city is quite old, but it is vibrant with shops and shoppers who were in no way deterred by the snow. About a foot of it fell beginning Tuesday. Thankfully, that is started after we arrived. It continued to fall most of the days we were there. </p><p> Mass transit is wonderful. They have efficient trains, trams, and busses. </p><p> Now it's back to the normal grind, which will be easier when the jet lag wears off. </p><p> Phil</p> philcrow 2007-01-30T22:06:13+00:00 journal In Germany, Plat_Forms contest tomorrow <p> We arrived in Germany on Tuesday and spent Wednesday seeing the German National Museum and walking around snow covered Nurenberg. By now about a foot of snow has fallen. Our friends from this side of the atlantic have been delayed by the snow. We are waiting in the contest room for them to arrive. They have our server. We hope they do arrive tonight, but aren't too worried... yet. </p><p> I owe thanks to a committee of locals who helped me get to my hotel last night after I got off at the wrong train stop. </p><p> Phil</p> philcrow 2007-01-24T17:03:27+00:00 journal Plat_Forms contest: you can be involved <p> We are making our final preparations for the Plat_Forms contest. Our power cord adapters are in hand and our hotel rooms are booked. </p><p> <a href="">Gantry</a> is sporting a bit of clean up and a new SOAP capability (responses are prepared with SOAP::Lite, requests are integrated into Gantry). Bigtop generates all the code except the part that does the real work. For now, it only works for mod_perl 2.0. Time permitting we will make it work for mod_perl 1.0 and CGI after the contest. </p><p> <b>We could use your help</b> </p><p> The contest organizers are going to set up a <a href="">blog server</a> where contestants can get feedback from the public during the contest time. You can help us by visiting the blog during that time and providing feedback. The contest is from Thursday 8:00 UTC until Friday 15:00 UTC. Helpful comments will be greatly appreciated. </p><p> There will be two other perl teams. Please give them comments too. Help all of us make Perl look good. </p><p> Phil</p> philcrow 2007-01-19T21:53:51+00:00 journal Plat_Forms physical preparation <p> Our tickets are now booked to Nurenburg for the Plat_Forms contest. You can see <a href="">a list of all the teams</a> on the contest site. </p><p> I found a lovely power adapter at a big box retailer in town. It tells me I can use it to plug my laptop into EU, UK, Australia, and New Zealand power outlets. I hope that includes Germany. We'll see. </p><p> We've also added a couple of useful things to our <a href=";mode=all"> code generation framework</a>. They should appear on CPAN sometime in the next month. They're already in the svn trunk. </p><p> The contest requires serving SOAP, which don't do. So, we are studying SOAP::Lite and planning our possible approaches. </p><p> Phil</p> philcrow 2006-12-29T15:46:58+00:00 journal Gantry going to Plat_Forms <p> On Friday last week we got the notice that our team will be going to Germany to hold high the banner of Perl in the Plat_Forms contest. </p><p> Our team is sponsered by the <a href="">German Perl Workshop</a>, <a href="">Revolution Systems</a>, and the indivdual members: Frank Wiles, Tim Keefer and Me (Phil Crow). </p><p> We will be using the <a href="">Gantry framework</a> running under mod_perl 2. </p><p> The first order of business was booking flights from Kansas City to Nurenburg. Next up is finding power cords or adapters for our various laptops. </p><p> More later... </p><p> Phil </p> philcrow 2006-12-18T19:33:05+00:00 journal