line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Generator::FromDDL; |
2
|
6
|
|
|
6
|
|
117270
|
use 5.008005; |
|
6
|
|
|
|
|
23
|
|
|
6
|
|
|
|
|
287
|
|
3
|
6
|
|
|
6
|
|
35
|
use strict; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
199
|
|
4
|
6
|
|
|
6
|
|
32
|
use warnings; |
|
6
|
|
|
|
|
24
|
|
|
6
|
|
|
|
|
200
|
|
5
|
6
|
|
|
6
|
|
35
|
use Carp qw(croak); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
575
|
|
6
|
6
|
|
|
6
|
|
8362
|
use SQL::Translator; |
|
6
|
|
|
|
|
2838360
|
|
|
6
|
|
|
|
|
340
|
|
7
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
8
|
6
|
|
|
|
|
57
|
new => 1, |
9
|
|
|
|
|
|
|
rw => [qw(builder_class parser ddl include exclude)], |
10
|
6
|
|
|
6
|
|
5234
|
); |
|
6
|
|
|
|
|
6112
|
|
11
|
|
|
|
|
|
|
|
12
|
6
|
|
|
6
|
|
4747
|
use Data::Generator::FromDDL::Director; |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
223
|
|
13
|
6
|
|
|
6
|
|
4046
|
use Data::Generator::FromDDL::Util qw(normalize_parser_str); |
|
6
|
|
|
|
|
152
|
|
|
6
|
|
|
|
|
3037
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = "0.06"; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub generate { |
18
|
20
|
|
|
20
|
1
|
41600
|
my ($self, $num, $out_fh, $format, $pretty, $bytes_per_sql) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# set default values if not specified |
21
|
20
|
|
|
|
|
109
|
my $builder_class = _load_builder_class($self->builder_class); |
22
|
20
|
|
100
|
|
|
134
|
my $parser = $self->parser || 'mysql'; |
23
|
20
|
|
100
|
|
|
268
|
my $include = $self->include || []; |
24
|
20
|
|
100
|
|
|
276
|
my $exclude = $self->exclude || []; |
25
|
20
|
|
50
|
|
|
207
|
my $ddl = $self->ddl || ''; |
26
|
20
|
|
33
|
|
|
183
|
$out_fh ||= *STDOUT; |
27
|
20
|
|
100
|
|
|
87
|
$format ||= 'sql'; |
28
|
20
|
|
100
|
|
|
83
|
$bytes_per_sql ||= 1024 * 1024; # 1MB; |
29
|
|
|
|
|
|
|
|
30
|
20
|
|
|
|
|
79
|
my $schema = _parse_ddl($parser, $ddl); |
31
|
|
|
|
|
|
|
|
32
|
20
|
|
|
|
|
1901
|
my $director = Data::Generator::FromDDL::Director->new( |
33
|
|
|
|
|
|
|
builder_class => $builder_class, |
34
|
|
|
|
|
|
|
schema => $schema, |
35
|
|
|
|
|
|
|
include => $include, |
36
|
|
|
|
|
|
|
exclude => $exclude, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
20
|
|
|
|
|
397
|
my @recordsets = $director->generate($num); |
40
|
20
|
|
|
|
|
128
|
$director->flush( |
41
|
|
|
|
|
|
|
\@recordsets, $out_fh, $format, $pretty, $bytes_per_sql |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _parse_ddl { |
46
|
20
|
|
|
20
|
|
42
|
my ($parser, $ddl) = @_; |
47
|
20
|
|
|
|
|
815
|
my $tr = SQL::Translator->new; |
48
|
20
|
|
|
|
|
23875
|
$tr->parser(normalize_parser_str($parser))->($tr, $ddl); |
49
|
20
|
50
|
|
|
|
16476890
|
croak "Parsing DDL failed. Please check a DDL syntax.\n" |
50
|
|
|
|
|
|
|
unless $tr->schema->is_valid; |
51
|
|
|
|
|
|
|
|
52
|
20
|
|
|
|
|
54726
|
return $tr->schema; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _load_builder_class { |
56
|
20
|
|
|
20
|
|
171
|
my ($builder_class) = @_; |
57
|
20
|
|
50
|
|
|
155
|
$builder_class ||= 'Data::Generator::FromDDL::Builder::SerialOrder'; |
58
|
|
|
|
|
|
|
|
59
|
20
|
|
|
|
|
45
|
my $builder_file = $builder_class; |
60
|
20
|
|
|
|
|
162
|
$builder_file =~ s!::!/!g; |
61
|
20
|
|
|
|
|
60
|
eval { |
62
|
20
|
|
|
|
|
3826
|
require "$builder_file.pm"; |
63
|
|
|
|
|
|
|
}; |
64
|
20
|
50
|
|
|
|
118
|
if ($@) { |
65
|
0
|
|
|
|
|
0
|
croak("Can't require $builder_class \n"); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
20
|
|
|
|
|
62
|
return $builder_class; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
__END__ |