Cheater
view release on metacpan or search on metacpan
lib/Cheater/AST.pm view on Meta::CPAN
package Cheater::AST;
use 5.010000;
use Moose;
use Clone qw(clone);
sub process_table ($$$$$$$);
has 'goals' => (is => 'ro', isa => 'HashRef');
has 'cols' => (is => 'ro', isa => 'HashRef');
has 'deps' => (is => 'ro', isa => 'HashRef');
has 'types' => (is => 'ro', isa => 'HashRef');
has 'tables' => (is => 'ro', isa => 'HashRef');
has 'col_clones' => (is => 'ro', isa => 'HashRef');
around BUILDARGS => sub {
my $orig = shift;
my $class = shift;
my $parse_tree = shift;
#warn "BUILDARGS";
my (%tables, %cols, %deps, %goals, %types, %col_clones);
my %cols_visited;
%types = (
integer => 1,
text => 1,
serial => 1,
real => 1,
date => 1,
time => 1,
datetime => 1,
);
my $n;
do {{
$n = @$parse_tree;
@$parse_tree = map {
$_->[0] eq 'include' ? @{ $_->[1] } : $_
} @$parse_tree;
}} while (@$parse_tree > $n);
for my $stmt (@$parse_tree) {
#say $stmt->[0];
my $typ = $stmt->[0];
given ($typ) {
when ('type') {
my $typname = $stmt->[1];
my $def = $stmt->[2];
$types{$typname} = $def;
}
when ('rows') {
my $table = $stmt->[2];
my $rows = $goals{$table};
if ($rows) {
die "table $table was configured to generate $rows rows.\n";
}
$rows = $stmt->[1];
$goals{$table} = $rows;
}
when ('table') {
my $table_name = $stmt->[1];
my $table = $stmt->[2];
process_table($table_name, $table, \%tables, \%deps, \%cols, \%types, \%col_clones);
}
when ('table_assign') {
my $lhs = $stmt->[1];
my $rhs = $stmt->[2];
my $table = $tables{$rhs};
( run in 2.179 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )