Suite Modeler's Rapid Prototype Code Generation Facility
Perl and PerlObjCBridge
Suite Modeler uses Perl and Apple's PerlObjCBridge.pm to generate source code in Objective-C (Java later?). Suite Modeler makes its Perl modules public in the application's resource bundle, so users can fine-tune them to their purposes.
Note that Suite Modeler does not use CamelBones. (Props to Sherm Pendley, nevertheless.) The issues that weighed in this design trade-off are these:
- CamelBones offers better Cocoa/Perl integration. I hope that Apple's PerlObjCBridge can quickly evolve in that direction. CamelBones itself seems to be a fine piece of equipment.
- But CamelBones adds "another moving part" with its own versions and the concomitant headaches.
- CamelBones compiles with many warnings (version from 2002/04/18).
In the end, I determined that to force Suite Modeler users and CamelBones on each other would prove unsatisfactory to all parties. Suite Modeler's public code generation API in Perl permits users to resort to CamelBones if they prefer. After all, in Perl, there is always more than one way to do it. For extensive revision, CamelBones may well prove beneficial.
Code Generation -- a Text Book Case for Perl
Suite Modeler's Rapid Prototype Code Generation Facility follows
- Advanced Programming in Perl — Foundations and Techniques for Perl Application Developers
- by Sriram Srinivasan
- August 1997 First Edition
- O'Reilly and Associates
- ISBN 1-56592-220-4
particularly, the "Jeeves" example of pages 116-119 of Chapter 17, "Template-Driven Code Generation." It relies on an abstract syntax tree (AST). Here, the AST appears as a NSDictionary from Suite Modeler. The Jeeves example uses a template file and for each class of the AST, the driver produces an intermediate file and then emits the final file. Where Jeeves emits files directly, the Suite Modeler Perl API returns an NSDictionary. Each entry in the dictionary is a file name as a key, with the file's contents, as a single string, as the key's value. Suite Modeler then uses typical Cocoa Objective-C API actually to emit the files (in a directory chosen by the user in a Save Panel), adding the *.script* plist files on its own.
Notes on the Abstract Syntax Tree
The AST differs from the Suite Modeler document plist archival form in a few ways:
- The AST reflects the presentation order explicitly, as an array of dictionaries; and
- Each Supported Command carries an array of its command's arguments, rather than a reference to the command.
- Each entity carries its own dictionary of code generation information, as determined by the user's fine-grain control.
These changes simplify the Perl problem. The first obviates a KVC sort. As for the second, it obviates either cross-document references in the Perl API, or multiple client-server messages. The third provides the fine-grain control, through the drawer view accessible via the ("<") button in the "Classes" tab view.
Overview -- NSDictionary In, NSDictionary Out
Suite Modeler launches a Distributed Objects (DO) server in Perl and connects to it as a client. The client sends to the server an NSDictionary that specifies the code to be generated for a suite. The client receives from the server an NSDictionary that specifies the files to emit. Each entry of the returned dictionary has as its key a file name and as its value the file's contents as a string.
User Control
The Preferences Panel provides coarse-grain control.
A drawer accessible from the "Classes" tab provides fine-grain control.