line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Generator::FromDDL::Builder; |
2
|
6
|
|
|
6
|
|
1125
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
237
|
|
3
|
6
|
|
|
6
|
|
34
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
229
|
|
4
|
6
|
|
|
6
|
|
35
|
use Carp qw(croak); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
362
|
|
5
|
6
|
|
|
6
|
|
10106
|
use Class::Data::Inheritable; |
|
6
|
|
|
|
|
2290
|
|
|
6
|
|
|
|
|
191
|
|
6
|
6
|
|
|
6
|
|
4395
|
use Data::Generator::FromDDL::RecordSet; |
|
6
|
|
|
|
|
28
|
|
|
6
|
|
|
|
|
252
|
|
7
|
6
|
|
|
6
|
|
42
|
use Data::Generator::FromDDL::Util qw(need_quote_data_type); |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
754
|
|
8
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
9
|
6
|
|
|
|
|
41
|
new => 1, |
10
|
|
|
|
|
|
|
rw => [qw(table recordsets)], |
11
|
6
|
|
|
6
|
|
38
|
); |
|
6
|
|
|
|
|
13
|
|
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
|
576
|
use base qw(Exporter Class::Data::Inheritable); |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
3941
|
|
14
|
|
|
|
|
|
|
our @EXPORT = qw(datatype); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata('dispatch_table', {}); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub generate { |
20
|
21
|
|
|
21
|
0
|
51
|
my ($self, $n) = @_; |
21
|
21
|
|
|
|
|
148
|
my $table = $self->table; |
22
|
21
|
|
|
|
|
365
|
my $recordset = Data::Generator::FromDDL::RecordSet->new($table, $n); |
23
|
21
|
|
|
|
|
86
|
for my $field ($table->get_fields) { |
24
|
22
|
|
|
|
|
13421
|
my @values = $self->generate_field_values($field, $n); |
25
|
22
|
|
|
|
|
151
|
$recordset->set_column_values($field, \@values); |
26
|
|
|
|
|
|
|
} |
27
|
21
|
|
|
|
|
535
|
return $recordset; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub generate_field_values { |
31
|
22
|
|
|
22
|
0
|
53
|
my ($self, $field, $n) = @_; |
32
|
22
|
|
|
|
|
98
|
my $data_type = lc($field->data_type); |
33
|
|
|
|
|
|
|
|
34
|
22
|
|
|
|
|
138
|
my @values = $self->dispatch($data_type, $field, $n); |
35
|
|
|
|
|
|
|
|
36
|
22
|
100
|
|
|
|
139
|
if (need_quote_data_type($data_type)) { |
37
|
3
|
|
|
|
|
8
|
@values = map { q{'} . $_ . q{'} } @values; |
|
3
|
|
|
|
|
17
|
|
38
|
|
|
|
|
|
|
} |
39
|
22
|
|
|
|
|
88
|
return @values; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub dispatch { |
43
|
39
|
|
|
39
|
0
|
97
|
my ($self, $data_type, $field, $n) = @_; |
44
|
39
|
|
|
|
|
81
|
my $class = ref $self; |
45
|
39
|
|
|
|
|
182
|
my $code = $class->dispatch_table->{$data_type}; |
46
|
39
|
50
|
|
|
|
405
|
croak "Unsupported data type: $data_type \n" |
47
|
|
|
|
|
|
|
unless $code; |
48
|
|
|
|
|
|
|
|
49
|
39
|
|
|
|
|
205
|
return $code->($self, $field, $n, $self->recordsets); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub redispatch { |
53
|
17
|
|
|
17
|
0
|
51
|
my ($self, $new_data_type, $field, $n) = @_; |
54
|
17
|
|
|
|
|
79
|
return $self->dispatch($new_data_type, $field, $n); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
## DSL |
58
|
|
|
|
|
|
|
sub datatype($&) { |
59
|
66
|
|
|
66
|
0
|
126
|
my ($data_types, $code) = @_; |
60
|
66
|
|
|
|
|
163
|
my ($class) = caller; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# update dispatch table |
63
|
66
|
|
|
|
|
269
|
my $dispatch_table = $class->dispatch_table; |
64
|
66
|
|
|
|
|
575
|
for my $data_type (split /,\s*/, $data_types) { |
65
|
102
|
|
|
|
|
321
|
$dispatch_table->{$data_type} = $code; |
66
|
|
|
|
|
|
|
} |
67
|
66
|
|
|
|
|
226
|
$class->dispatch_table($dispatch_table); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |