lib/Java/Javap/Generator.pm

filter: Statementstmt 58.8% 10 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 63.6% 14 / 22 CC 1 SCAR 2.2
CC
1
Cov
59%
get_generator
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« blib/lib/Java/Javap/TypeCast.pm ↑ Summary
1 package Java::Javap::Generator;
2 4 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 4 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 0 ▶sub get_generator {
Subroutine get_generator: not called CC=1 SCAR=6.9
Pod documented
7 0 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 4 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<new> and C<generate> 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<get_generator> with the name of the generator you want to use.
53 Pass any additional arguments expected by the C<new> 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<get_generator> in this module. Your constructor
66 will receive all of the parameters passed to C<get_generator>, except
67 the name of the subclass (but C<new> is invoked through the fully
68 qualified subclass name, so you get that too).
69  
70 C<java2perl6api> 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<t/02_interface.t> and
80 C<t/03_class.t> for examples of the syntax tree data structure.
81  
82 Parameters are supplied to your C<generate> in a single hash reference.
83 These are the ones supplied by the C<java2perl6api> 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<Java::Javap::Grammar>.
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<get_generator> 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, E<lt>crow.phil@gmail.comE<gt>
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  
« blib/lib/Java/Javap/TypeCast.pm ↑ Summary