File Coverage

lib/Java/Javap/Generator.pm
Criterion Covered Total %
statement 9 16 56.2
branch n/a
condition n/a
subroutine 3 4 75.0
pod 1 1 100.0
total 13 21 61.9


line stmt bran cond sub pod time code
1             package Java::Javap::Generator;
2 4     4   1867 use strict; use warnings;
  4     4   7  
  4         168  
  4         23  
  4         7  
  4         105  
3              
4 4     4   23 use File::Spec;
  4         7  
  4         688  
5              
6             sub get_generator {
7 0     0 1   my $class = shift;
8 0           my $subclass = shift;
9 0           my $module = join '::', $class, $subclass;
10              
11 0           my @classpath = split /::/, $class;
12 0           my $pm_file = File::Spec->catfile( @classpath, "$subclass.pm" );
13              
14 0           require $pm_file;
15              
16 0           return $module->new( @_ );
17             }
18              
19             1;
20              
21             =head1 NAME
22              
23             Java::Javap::Generator - Factory for Perl 6 generators
24              
25             =head1 SYNOPSIS
26              
27             use Java::Javap::Generator;
28              
29             my $gen = Java::Javap::Generator->get_generator( 'NAME', @args );
30              
31             my $output = $gen->generate( @more_args );
32              
33             =head1 DESCRIPTION
34              
35             This is a factory class which returns a Java -> Perl 6 generator.
36             All generators must live in the Java::Javap::Generator:: namespace.
37             They must supply a C and C methods.
38              
39             To use a particular generator, see its POD.
40              
41             =head1 KNOWN GENERATORS
42              
43             Java::Javap::Generator::Perl6 - uses TT templates
44              
45             =head1 METHODS
46              
47             This moduule provides only one method which returns an instance of the
48             supplied generating class.
49              
50             =head2 get_generator
51              
52             Call C with the name of the generator you want to use.
53             Pass any additional arguments expected by the C method of your
54             genertor's class. Example:
55              
56             my $generator = Java::Javap::Generator->get_generator( 'Perl6' );
57              
58             =head1 GENERATOR API
59              
60             Each generator must live in the Java::Javap::Generator:: namespace and
61             must implement two methods:
62              
63             =head2 new
64              
65             A constructor called by C in this module. Your constructor
66             will receive all of the parameters passed to C, except
67             the name of the subclass (but C is invoked through the fully
68             qualified subclass name, so you get that too).
69              
70             C allows callers to supply these parameters as a string on the
71             command line with the C<-p> (or C<--genopts>) flag, whose value is split
72             on whitespace before the call.
73              
74             =head2 generate
75              
76             This method returns a single string containing the full text of a Perl
77             module corresponding to the abstract syntax tree of a Java module.
78             Someone else will decide what to do with the output, all you need to do
79             is make the string. See the test files C and
80             C for examples of the syntax tree data structure.
81              
82             Parameters are supplied to your C in a single hash reference.
83             These are the ones supplied by the C command line tool:
84              
85             =over 4
86              
87             =item class_file
88              
89             The name of the Java .class file which was run through javap.
90              
91             =item ast
92              
93             The abstract syntax tree made from the class file by C.
94             Again, see the tests for examples of the tree data structure.
95              
96             =item javap_flags
97              
98             The command line flags passed to javap (like -classpath ...). These
99             are included so you can dump them into a comment in the generated output.
100              
101             =back
102              
103             =head2 EXPORT
104              
105             None. Call C as a class method.
106              
107             =head1 SEE ALSO
108              
109             All the modules in the Java::Javap::Generator:: namespace.
110              
111             =head1 AUTHOR
112              
113             Phil Crow, Ecrow.phil@gmail.comE
114              
115             =head1 COPYRIGHT AND LICENSE
116              
117             Copyright (C) 2007, Phil Crow
118              
119             This library is free software; you can redistribute it and/or modify
120             it under the same terms as Perl itself, either Perl version 5.8.6 or,
121             at your option, any later version of Perl 5 you may have available.
122              
123             =cut
124