Cheater
view release on metacpan or search on metacpan
lib/Cheater/Eval.pm view on Meta::CPAN
package Cheater::Eval;
use 5.010000;
use Moose;
#use Smart::Comments;
use Date::Calc qw( Localtime );
use Data::Random qw(
rand_chars
rand_date rand_time rand_datetime
);
use Parse::RandGen::Regexp ();
use Scalar::Util qw( looks_like_number );
use Cheater::Util qw( quote_sql_str );
sub get_today ();
our $NowDate = 'now';
our $NowDatetime = 'now';
has 'ast' => (is => 'ro', isa => 'Cheater::AST');
has '_samples' => (is => 'ro', isa => 'HashRef');
has '_cols_visited' => (is => 'ro', isa => 'HashRef');
sub pick_elems ($$$);
sub gen_txt_col ($$$$$$$);
sub gen_num_col ($$$$$$);
sub gen_domain_val ($);
sub gen_int ($);
sub gen_real ($);
sub BUILD {
my $self = shift;
$self->{_samples} = {};
$self->{_cols_visited} = {};
}
sub go {
my $self = shift;
my $ast = $self->ast;
my $goals = $ast->goals;
### $goals
my %computed;
for my $goal (sort keys %$goals) {
$computed{$goal} = $self->gen_goal($goal);
}
return \%computed;
}
sub rand_regex ($) {
my $regex = shift;
Parse::RandGen::Regexp->new(qr/$regex/)->pick();
}
sub gen_goal {
my ($self, $table) = @_;
my $ast = $self->ast;
my $goals = $ast->goals;
my $tables = $ast->tables;
my $rows = $goals->{$table};
my @cols_data;
my $tb_spec = $tables->{$table} or
die "Table $table not defined.\n";
for my $col (@$tb_spec) {
#say "col: ", $col->[0];
my $name = $col->[0];
push @cols_data, $self->gen_column($table, $name);
}
return \@cols_data;
}
sub gen_column {
my ($self, $table, $col_name) = @_;
( run in 2.148 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )