Code::Generator::Perl - Perl module for generating perl modules
use Code::Generator::Perl; my $generator = new Code::Generator::Perl( generated_by => 'somescript.pl', ); my @fib_sequence = ( 1, 1, 2, 3, 5, 8 ); $generator->new_package('Fibonacci'); $generator->add_comment('Single digit fibonacci numbers'); $generator->add(fib_sequence => \@fib_sequence); $generator->create_or_die(); # This will generate the file Fibonacci.pm: # # package Fibonacci; # # use strict; # use warnings; # # # You should never edit this file. Everything in here is automatically # # generated by somescript.pl. # # # Single digit fibonacci numbers # our $sequence = [ # 1, # 1, # 2, # 3, # 5, # 8 # ]; # # 1; my @single_digit_numbers = ( 1..9 ); $generator->new_package('Number::Single::Digit'); $generator->add(single_digits => \@single_digit_numbers); # Generates Number/Single/Digit.pm $generator->create_or_die();
Code::Generator::Perl generates perl modules for you.
The idea is that you specify the module name and what variables it has and it will spit out the .pm files for you, using Data::Dumper to do the actual nitty-gritty work.
It was born out of the need to generate perl modules for representing static data relationship from relational database tables. The static data doesn't change all that often so having them pre-calculated in some perl module somewhere saves precious cpu time that would have been spent on doing table joins to come up with the same data.
Creates the generator object. Available options are
Specifies the directory where the generated files will be saved to.
The base package to be prepended to the package name.
Set this to true if you would like all the variables in all the packages to be generated to be readonly. This requires the Readonly module. You can overide this in per-package or per-variable readonly option.
Set this to the name of your script so that people that view the generated file know which script generates your generated files.
Prepare the generator for creating a new package. Previous contents are cleared. Valid options are:
The output directory for this package.
An array ref to a list of other modules to use. By default 'strict' and 'warnings' are included. Specify the 'nowarnings' and 'nostrict' if you don't want them (see below).
Exclude 'use warnings' if set to true.
Exclude 'use strict' if set to true.
Similar to 'generated_by' option to new but for this package only.
The base package name to be prepended to this package.
Set to 1 if you would like all variables in this package to be readonly.
Add comments. They will be joined with newlines.
Add a variable with the given name, pointing to $ref. Options are:
Nazri Ramliy, <email@example.com>
Copyright (C) 2011 by Nazri Ramliy
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.