Tim Bunce > Java-2Perl6API-0.11 > Java::Javap::Generator

Download:
Java-2Perl6API-0.11.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Java::Javap::Generator - Factory for Perl 6 generators

SYNOPSIS ^

    use Java::Javap::Generator;

    my $gen = Java::Javap::Generator->get_generator( 'NAME', @args );

    my $output = $gen->generate( @more_args );

DESCRIPTION ^

This is a factory class which returns a Java -> Perl 6 generator. All generators must live in the Java::Javap::Generator:: namespace. They must supply a new and generate methods.

To use a particular generator, see its POD.

KNOWN GENERATORS ^

    Java::Javap::Generator::Perl6 - uses TT templates

METHODS ^

This moduule provides only one method which returns an instance of the supplied generating class.

get_generator

Call get_generator with the name of the generator you want to use. Pass any additional arguments expected by the new method of your genertor's class. Example:

    my $generator = Java::Javap::Generator->get_generator( 'Perl6' );

GENERATOR API ^

Each generator must live in the Java::Javap::Generator:: namespace and must implement two methods:

new

A constructor called by get_generator in this module. Your constructor will receive all of the parameters passed to get_generator, except the name of the subclass (but new is invoked through the fully qualified subclass name, so you get that too).

java2perl6api allows callers to supply these parameters as a string on the command line with the -p (or --genopts) flag, whose value is split on whitespace before the call.

generate

This method returns a single string containing the full text of a Perl module corresponding to the abstract syntax tree of a Java module. Someone else will decide what to do with the output, all you need to do is make the string. See the test files t/02_interface.t and t/03_class.t for examples of the syntax tree data structure.

Parameters are supplied to your generate in a single hash reference. These are the ones supplied by the java2perl6api command line tool:

class_file

The name of the Java .class file which was run through javap.

ast

The abstract syntax tree made from the class file by Java::Javap::Grammar. Again, see the tests for examples of the tree data structure.

javap_flags

The command line flags passed to javap (like -classpath ...). These are included so you can dump them into a comment in the generated output.

EXPORT

None. Call get_generator as a class method.

SEE ALSO ^

All the modules in the Java::Javap::Generator:: namespace.

AUTHOR ^

Phil Crow, <crow.phil@gmail.com>

COPYRIGHT AND LICENSE ^

Copyright (C) 2007, Phil Crow

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: