line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MySQL::Workbench::DBIC; |
2
|
|
|
|
|
|
|
|
3
|
38
|
|
|
38
|
|
4367164
|
use warnings; |
|
38
|
|
|
|
|
454
|
|
|
38
|
|
|
|
|
1430
|
|
4
|
38
|
|
|
38
|
|
228
|
use strict; |
|
38
|
|
|
|
|
84
|
|
|
38
|
|
|
|
|
791
|
|
5
|
|
|
|
|
|
|
|
6
|
38
|
|
|
38
|
|
185
|
use Carp; |
|
38
|
|
|
|
|
70
|
|
|
38
|
|
|
|
|
2147
|
|
7
|
38
|
|
|
38
|
|
26040
|
use Data::Dumper; |
|
38
|
|
|
|
|
275407
|
|
|
38
|
|
|
|
|
2912
|
|
8
|
38
|
|
|
38
|
|
327
|
use File::Path qw(make_path); |
|
38
|
|
|
|
|
89
|
|
|
38
|
|
|
|
|
2691
|
|
9
|
38
|
|
|
38
|
|
282
|
use File::Spec; |
|
38
|
|
|
|
|
87
|
|
|
38
|
|
|
|
|
780
|
|
10
|
38
|
|
|
38
|
|
25594
|
use JSON; |
|
38
|
|
|
|
|
478696
|
|
|
38
|
|
|
|
|
257
|
|
11
|
38
|
|
|
38
|
|
6435
|
use List::Util qw(first); |
|
38
|
|
|
|
|
94
|
|
|
38
|
|
|
|
|
2838
|
|
12
|
38
|
|
|
38
|
|
21962
|
use Moo; |
|
38
|
|
|
|
|
447000
|
|
|
38
|
|
|
|
|
224
|
|
13
|
38
|
|
|
38
|
|
79781
|
use MySQL::Workbench::Parser; |
|
38
|
|
|
|
|
20470461
|
|
|
38
|
|
|
|
|
202322
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# ABSTRACT: create DBIC scheme for MySQL workbench .mwb files |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.21'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has output_path => ( is => 'ro', required => 1, default => sub { '.' } ); |
20
|
|
|
|
|
|
|
has file => ( is => 'ro', required => 1 ); |
21
|
|
|
|
|
|
|
has uppercase => ( is => 'ro' ); |
22
|
|
|
|
|
|
|
has inherit_from_core => ( is => 'ro' ); |
23
|
|
|
|
|
|
|
has namespace => ( is => 'ro', isa => sub{ _check_namespace( @_, 1) }, required => 1, default => sub { '' } ); |
24
|
|
|
|
|
|
|
has result_namespace => ( is => 'ro', isa => \&_check_namespace, required => 1, default => sub { '' } ); |
25
|
|
|
|
|
|
|
has resultset_namespace => ( is => 'ro', isa => \&_check_namespace, required => 1, default => sub { '' } ); |
26
|
|
|
|
|
|
|
has load_result_namespace => ( is => 'ro', isa => \&_check_namespace_array, default => sub { '' } ); |
27
|
|
|
|
|
|
|
has load_resultset_namespace => ( is => 'ro', isa => \&_check_namespace_array, default => sub { '' } ); |
28
|
|
|
|
|
|
|
has schema_name => ( is => 'rwp', isa => sub { defined $_[0] && $_[0] =~ m{ \A [A-Za-z0-9_]+ \z }xms } ); |
29
|
|
|
|
|
|
|
has parser => ( is => 'rwp' ); |
30
|
|
|
|
|
|
|
has version_add => ( is => 'ro', required => 1, default => sub { 0.01 } ); |
31
|
|
|
|
|
|
|
has column_details => ( is => 'ro', required => 1, default => sub { 0 } ); |
32
|
|
|
|
|
|
|
has use_fake_dbic => ( is => 'ro', required => 1, default => sub { 0 } ); |
33
|
|
|
|
|
|
|
has skip_indexes => ( is => 'ro', required => 1, default => sub { 0 } ); |
34
|
|
|
|
|
|
|
has belongs_to_prefix => ( is => 'ro', required => 1, default => sub { '' } ); |
35
|
|
|
|
|
|
|
has has_many_prefix => ( is => 'ro', required => 1, default => sub { '' } ); |
36
|
|
|
|
|
|
|
has has_one_prefix => ( is => 'ro', required => 1, default => sub { '' } ); |
37
|
|
|
|
|
|
|
has many_to_many_prefix => ( is => 'ro', required => 1, default => sub { '' } ); |
38
|
|
|
|
|
|
|
has utf8 => ( is => 'ro', required => 1, default => sub { 0 } ); |
39
|
|
|
|
|
|
|
has schema_base_class => ( is => 'ro', required => 1, default => sub { 'DBIx::Class::Schema' } ); |
40
|
|
|
|
|
|
|
has remove_table_prefix => ( is => 'ro' ); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has version => ( is => 'rwp' ); |
43
|
|
|
|
|
|
|
has classes => ( is => 'rwp', isa => sub { ref $_[0] && ref $_[0] eq 'ARRAY' }, default => sub { [] } ); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _check_namespace { |
46
|
223
|
|
|
223
|
|
5445
|
my ($namespace, $allow_empty_string) = @_; |
47
|
|
|
|
|
|
|
|
48
|
223
|
100
|
|
|
|
518
|
return if !defined $namespace; |
49
|
221
|
100
|
|
|
|
483
|
return if ref $namespace; |
50
|
|
|
|
|
|
|
|
51
|
218
|
100
|
100
|
|
|
1068
|
return 1 if $namespace eq '' && $allow_empty_string; |
52
|
|
|
|
|
|
|
|
53
|
205
|
|
|
|
|
3226
|
return $namespace =~ m{ \A [A-Z]\w*(::\w+)* \z }xms; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _check_namespace_array { |
57
|
89
|
|
|
89
|
|
5211
|
my ($namespaces) = @_; |
58
|
|
|
|
|
|
|
|
59
|
89
|
100
|
|
|
|
298
|
if ( !ref $namespaces ) { |
60
|
76
|
|
|
|
|
223
|
return _check_namespace( $namespaces ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
13
|
100
|
|
|
|
38
|
return if 'ARRAY' ne ref $namespaces; |
64
|
|
|
|
|
|
|
|
65
|
11
|
|
|
|
|
20
|
for my $namespace ( @{ $namespaces } ) { |
|
11
|
|
|
|
|
25
|
|
66
|
20
|
100
|
|
|
|
42
|
return if !_check_namespace( $namespace ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
7
|
|
|
|
|
81
|
return 1; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
around new => sub { |
73
|
|
|
|
|
|
|
my ($next, $class, %args) = @_; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
if ( $args{use_fake_dbic} || !eval{ require DBIx::Class } ) { |
76
|
|
|
|
|
|
|
require MySQL::Workbench::DBIC::FakeDBIC; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $self = $class->$next( %args ); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $parser = MySQL::Workbench::Parser->new( file => $self->file ); |
82
|
|
|
|
|
|
|
$self->_set_parser( $parser ); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
return $self; |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub create_schema{ |
88
|
31
|
|
|
31
|
1
|
26094
|
my $self = shift; |
89
|
|
|
|
|
|
|
|
90
|
31
|
|
|
|
|
172
|
my $parser = $self->parser; |
91
|
31
|
|
|
|
|
79
|
my @tables = @{ $parser->tables }; |
|
31
|
|
|
|
|
962
|
|
92
|
|
|
|
|
|
|
|
93
|
31
|
|
|
|
|
2334596
|
my @classes; |
94
|
|
|
|
|
|
|
my %relations; |
95
|
31
|
|
|
|
|
137
|
for my $table ( @tables ){ |
96
|
87
|
|
|
|
|
278
|
my $name = $table->name; |
97
|
|
|
|
|
|
|
|
98
|
87
|
|
|
|
|
186
|
push @classes, $name; |
99
|
|
|
|
|
|
|
|
100
|
87
|
|
|
|
|
267
|
my $rels = $table->foreign_keys; |
101
|
87
|
|
|
|
|
297
|
for my $to_table ( keys %$rels ){ |
102
|
51
|
|
|
|
|
239
|
$relations{$to_table}->{to}->{$name} = $rels->{$to_table}; |
103
|
51
|
|
|
|
|
200
|
$relations{$name}->{from}->{$to_table} = $rels->{$to_table}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
31
|
|
|
|
|
716
|
$self->_set_classes( \@classes ); |
108
|
|
|
|
|
|
|
|
109
|
31
|
|
|
|
|
395
|
my @scheme = $self->_main_template; |
110
|
|
|
|
|
|
|
|
111
|
31
|
|
|
|
|
71
|
my @files; |
112
|
31
|
|
|
|
|
87
|
for my $table ( @tables ){ |
113
|
87
|
|
|
|
|
286
|
my $custom_code = $self->_custom_code_table( $table ); |
114
|
87
|
|
|
|
|
638
|
push @files, $self->_class_template( $table, $relations{$table->name}, $custom_code ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
31
|
50
|
|
|
|
91
|
for my $view ( @{ $parser->views || [] } ) { |
|
31
|
|
|
|
|
825
|
|
118
|
2
|
|
|
|
|
28
|
my $custom_code = $self->_custom_code_table( $view ); |
119
|
2
|
|
|
|
|
24
|
push @files, $self->_view_template( $view, $custom_code ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
31
|
|
|
|
|
418
|
push @files, @scheme; |
123
|
|
|
|
|
|
|
|
124
|
31
|
|
|
|
|
160
|
$self->_write_files( @files ); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub _custom_code_table { |
128
|
89
|
|
|
89
|
|
217
|
my ($self, $table) = @_; |
129
|
|
|
|
|
|
|
|
130
|
89
|
|
|
|
|
303
|
my $name = $table->name; |
131
|
89
|
100
|
|
|
|
308
|
if ( $self->uppercase ) { |
132
|
27
|
|
|
|
|
184
|
$name = join '', map{ ucfirst } split /[_-]/, $table->name; |
|
37
|
|
|
|
|
161
|
|
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
89
|
|
|
|
|
172
|
my @base_path; |
136
|
89
|
100
|
|
|
|
357
|
push @base_path, $self->output_path if $self->output_path; |
137
|
|
|
|
|
|
|
|
138
|
89
|
|
|
|
|
1902
|
my $path = File::Spec->catfile( |
139
|
|
|
|
|
|
|
@base_path, |
140
|
|
|
|
|
|
|
(split /::/, $self->namespace), |
141
|
|
|
|
|
|
|
$self->schema_name, |
142
|
|
|
|
|
|
|
$self->result_namespace, |
143
|
|
|
|
|
|
|
'Result', |
144
|
|
|
|
|
|
|
$name . '.pm' |
145
|
|
|
|
|
|
|
); |
146
|
|
|
|
|
|
|
|
147
|
89
|
100
|
|
|
|
2037
|
return '' if !-f $path; |
148
|
|
|
|
|
|
|
|
149
|
26
|
|
|
|
|
131
|
return $self->_custom_code( $path ); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub _custom_code { |
153
|
35
|
|
|
35
|
|
116
|
my ($self, $path) = @_; |
154
|
|
|
|
|
|
|
|
155
|
35
|
|
|
|
|
57
|
my $content = do { local (@ARGV, $/) = $path; <> }; |
|
35
|
|
|
|
|
234
|
|
|
35
|
|
|
|
|
2892
|
|
156
|
|
|
|
|
|
|
|
157
|
35
|
|
|
|
|
486
|
my ($code) = $content =~ m{ |
158
|
|
|
|
|
|
|
^[#] \s+ --- \s* |
159
|
|
|
|
|
|
|
^[#] \s+ Put \s+ your \s+ own \s+ code \s+ below \s+ this \s+ comment \s* |
160
|
|
|
|
|
|
|
^[#] \s+ --- \s* |
161
|
|
|
|
|
|
|
(.*?) \s+ |
162
|
|
|
|
|
|
|
^[#] \s+ --- \s* |
163
|
|
|
|
|
|
|
}xms; |
164
|
|
|
|
|
|
|
|
165
|
35
|
|
|
|
|
133
|
return $code; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub _write_files{ |
169
|
33
|
|
|
33
|
|
1542
|
my ($self, %files) = @_; |
170
|
|
|
|
|
|
|
|
171
|
33
|
|
|
|
|
176
|
for my $package ( keys %files ){ |
172
|
122
|
|
|
|
|
361
|
my @path; |
173
|
122
|
100
|
|
|
|
718
|
push @path, $self->output_path if $self->output_path; |
174
|
122
|
|
|
|
|
776
|
push @path, split /::/, $package; |
175
|
122
|
|
|
|
|
312
|
my $file = pop @path; |
176
|
122
|
|
|
|
|
1307
|
my $dir = File::Spec->catdir( @path ); |
177
|
|
|
|
|
|
|
|
178
|
122
|
100
|
|
|
|
2609
|
if( !-e $dir ){ |
179
|
34
|
100
|
|
|
|
16228
|
make_path( $dir ) or croak "Cannot create directory $dir"; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
121
|
100
|
|
|
|
9398
|
if( open my $fh, '>', $dir . '/' . $file . '.pm' ){ |
183
|
120
|
100
|
|
|
|
762
|
if ( $self->utf8 ) { |
184
|
4
|
|
|
1
|
|
78
|
binmode $fh, ':encoding(utf-8)'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
120
|
|
|
|
|
3016
|
print $fh $files{$package}; |
188
|
120
|
|
|
|
|
6315
|
close $fh; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
else{ |
191
|
1
|
|
|
|
|
106
|
croak "Couldn't create $file.pm: $!"; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub _has_many_template{ |
197
|
54
|
|
|
54
|
|
1099
|
my ($self, $to, $rels) = @_; |
198
|
|
|
|
|
|
|
|
199
|
54
|
|
|
|
|
110
|
my $name = $to; |
200
|
54
|
|
|
|
|
146
|
my ($to_class, $package) = $self->_create_class_and_package_name( $to ); |
201
|
|
|
|
|
|
|
|
202
|
54
|
50
|
|
|
|
203
|
if ( defined $self->remove_table_prefix ) { |
203
|
0
|
|
|
|
|
0
|
my $prefix = $self->remove_table_prefix; |
204
|
0
|
|
|
|
|
0
|
$name =~ s{\A\Q$prefix\E}{}; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
54
|
|
|
|
|
102
|
my %has_many_rels; |
208
|
54
|
|
|
|
|
95
|
my $counter = 1; |
209
|
|
|
|
|
|
|
|
210
|
54
|
|
|
|
|
102
|
my $string = ''; |
211
|
54
|
100
|
|
|
|
92
|
for my $field ( @{ $rels || [] } ) { |
|
54
|
|
|
|
|
209
|
|
212
|
54
|
|
|
|
|
132
|
my $me_field = $field->{foreign}; |
213
|
54
|
|
|
|
|
110
|
my $foreign_field = $field->{me}; |
214
|
|
|
|
|
|
|
|
215
|
54
|
|
|
|
|
197
|
my $temp_field = $self->has_many_prefix . $name; |
216
|
54
|
|
|
|
|
203
|
while ( $has_many_rels{$temp_field} ) { |
217
|
1
|
|
|
|
|
7
|
$temp_field = $self->has_many_prefix . $name . $counter++; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
54
|
|
|
|
|
163
|
$has_many_rels{$temp_field}++; |
221
|
|
|
|
|
|
|
|
222
|
54
|
|
|
|
|
361
|
$string .= qq~ |
223
|
|
|
|
|
|
|
__PACKAGE__->has_many($temp_field => '$package', |
224
|
|
|
|
|
|
|
{ 'foreign.$foreign_field' => 'self.$me_field' }); |
225
|
|
|
|
|
|
|
~; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
54
|
|
|
|
|
244
|
return $string; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub _belongs_to_template{ |
232
|
54
|
|
|
54
|
|
1754
|
my ($self, $from, $rels) = @_; |
233
|
|
|
|
|
|
|
|
234
|
54
|
|
|
|
|
111
|
my $name = $from; |
235
|
54
|
|
|
|
|
138
|
my ($from_class, $package) = $self->_create_class_and_package_name( $from ); |
236
|
|
|
|
|
|
|
|
237
|
54
|
50
|
|
|
|
229
|
if ( defined $self->remove_table_prefix ) { |
238
|
0
|
|
|
|
|
0
|
my $prefix = $self->remove_table_prefix; |
239
|
0
|
|
|
|
|
0
|
$name =~ s{\A\Q$prefix\E}{}; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
54
|
|
|
|
|
113
|
my %belongs_to_rels; |
243
|
54
|
|
|
|
|
103
|
my $counter = 1; |
244
|
|
|
|
|
|
|
|
245
|
54
|
|
|
|
|
103
|
my $string = ''; |
246
|
54
|
100
|
|
|
|
90
|
for my $field ( @{ $rels || [] } ) { |
|
54
|
|
|
|
|
213
|
|
247
|
54
|
|
|
|
|
137
|
my $me_field = $field->{me}; |
248
|
54
|
|
|
|
|
114
|
my $foreign_field = $field->{foreign}; |
249
|
|
|
|
|
|
|
|
250
|
54
|
|
|
|
|
197
|
my $temp_field = $self->belongs_to_prefix . $name; |
251
|
54
|
|
|
|
|
216
|
while ( $belongs_to_rels{$temp_field} ) { |
252
|
1
|
|
|
|
|
5
|
$temp_field = $self->belongs_to_prefix . $name . $counter++; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
54
|
|
|
|
|
197
|
$belongs_to_rels{$temp_field}++; |
256
|
|
|
|
|
|
|
|
257
|
54
|
|
|
|
|
361
|
$string .= qq~ |
258
|
|
|
|
|
|
|
__PACKAGE__->belongs_to($temp_field => '$package', |
259
|
|
|
|
|
|
|
{ 'foreign.$foreign_field' => 'self.$me_field' }); |
260
|
|
|
|
|
|
|
~; |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
54
|
|
|
|
|
208
|
return $string; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub _create_class_and_package_name { |
267
|
204
|
|
|
204
|
|
416
|
my ($self, $name) = @_; |
268
|
|
|
|
|
|
|
|
269
|
204
|
|
|
|
|
341
|
my $class = $name; |
270
|
|
|
|
|
|
|
|
271
|
204
|
100
|
|
|
|
664
|
if ( defined $self->remove_table_prefix ) { |
272
|
1
|
|
|
|
|
5
|
my $prefix = $self->remove_table_prefix; |
273
|
1
|
|
|
|
|
17
|
$class =~ s{\A\Q$prefix\E}{}; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
204
|
100
|
|
|
|
513
|
if ( $self->uppercase ) { |
277
|
63
|
|
|
|
|
273
|
$class = join '', map{ ucfirst $_ }split /[_-]/, $name; |
|
92
|
|
|
|
|
293
|
|
278
|
|
|
|
|
|
|
} |
279
|
|
|
|
|
|
|
|
280
|
204
|
100
|
|
|
|
1217
|
my $package = join '::', ( |
|
|
100
|
|
|
|
|
|
281
|
|
|
|
|
|
|
( $self->namespace ? $self->namespace : () ), |
282
|
|
|
|
|
|
|
$self->schema_name, |
283
|
|
|
|
|
|
|
( length $self->result_namespace ? $self->result_namespace : () ), |
284
|
|
|
|
|
|
|
'Result', |
285
|
|
|
|
|
|
|
$class, |
286
|
|
|
|
|
|
|
); |
287
|
|
|
|
|
|
|
|
288
|
204
|
|
|
|
|
586
|
return ($class, $package); |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
sub _class_template{ |
292
|
91
|
|
|
91
|
|
6430
|
my ($self, $table, $relations, $custom_code) = @_; |
293
|
|
|
|
|
|
|
|
294
|
91
|
|
|
|
|
219
|
my $name = $table->name; |
295
|
91
|
|
|
|
|
271
|
my ($class, $package) = $self->_create_class_and_package_name( $name ); |
296
|
|
|
|
|
|
|
|
297
|
91
|
|
|
|
|
236
|
my ($has_many, $belongs_to) = ('',''); |
298
|
|
|
|
|
|
|
|
299
|
91
|
|
100
|
|
|
514
|
my $comment = $table->comment // '{}'; |
300
|
91
|
|
|
|
|
300
|
utf8::upgrade( $comment ); |
301
|
|
|
|
|
|
|
|
302
|
91
|
|
|
|
|
129
|
my $data; |
303
|
91
|
|
|
|
|
156
|
my $table_comment_perl = ''; |
304
|
91
|
|
|
|
|
218
|
eval { |
305
|
91
|
|
|
|
|
1437
|
$data = JSON->new->decode( $comment ); |
306
|
|
|
|
|
|
|
}; |
307
|
|
|
|
|
|
|
|
308
|
91
|
100
|
100
|
|
|
925
|
if ( !ref $data || 'HASH' ne ref $data ) { |
|
|
100
|
|
|
|
|
|
309
|
7
|
|
|
|
|
21
|
$data = {}; |
310
|
7
|
100
|
|
|
|
27
|
$table_comment_perl = $comment if $comment; |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
elsif ( $data->{comment} ) { |
313
|
3
|
|
|
|
|
11
|
$table_comment_perl = $data->{comment}; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
|
316
|
91
|
100
|
|
|
|
272
|
if ( $table_comment_perl ) { |
317
|
7
|
|
|
|
|
40
|
$table_comment_perl = sprintf "\n\n=head1 DESCRIPTION\n\n%s\n\n=cut", $table_comment_perl; |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
|
320
|
91
|
100
|
|
|
|
402
|
my @core_components = $self->inherit_from_core ? () : qw(PK::Auto Core); |
321
|
91
|
100
|
|
|
|
182
|
my $components = join( ' ', @core_components, @{ $data->{components} || [] } ); |
|
91
|
|
|
|
|
483
|
|
322
|
91
|
100
|
|
|
|
359
|
my $load_components = $components ? "__PACKAGE__->load_components( qw/$components/ );" : ''; |
323
|
|
|
|
|
|
|
|
324
|
91
|
|
|
|
|
169
|
my %foreign_keys; |
325
|
|
|
|
|
|
|
|
326
|
91
|
|
|
|
|
145
|
for my $to_table ( sort keys %{ $relations->{to} } ){ |
|
91
|
|
|
|
|
459
|
|
327
|
51
|
|
|
|
|
239
|
$has_many .= $self->_has_many_template( $to_table, $relations->{to}->{$to_table} ); |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
|
330
|
91
|
|
|
|
|
201
|
for my $from_table ( sort keys %{ $relations->{from} } ){ |
|
91
|
|
|
|
|
414
|
|
331
|
51
|
|
|
|
|
216
|
$belongs_to .= $self->_belongs_to_template( $from_table, $relations->{from}->{$from_table} ); |
332
|
|
|
|
|
|
|
|
333
|
51
|
|
|
|
|
169
|
my @foreign_key_names = map{ $_->{me} }@{ $relations->{from}->{$from_table} }; |
|
51
|
|
|
|
|
159
|
|
|
51
|
|
|
|
|
157
|
|
334
|
51
|
|
|
|
|
221
|
@foreign_keys{ @foreign_key_names } = (1) x @foreign_key_names; |
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
|
337
|
91
|
|
|
|
|
193
|
my @columns = map{ $_->name }@{ $table->columns }; |
|
184
|
|
|
|
|
1303
|
|
|
91
|
|
|
|
|
2336
|
|
338
|
91
|
|
|
|
|
242
|
my $column_string = ''; |
339
|
|
|
|
|
|
|
|
340
|
91
|
100
|
|
|
|
372
|
if ( !$self->column_details ) { |
341
|
54
|
|
|
|
|
115
|
$column_string = "qw/\n" . join "\n", map{ " " . $_ }@columns, " /"; |
|
161
|
|
|
|
|
416
|
|
342
|
|
|
|
|
|
|
} |
343
|
|
|
|
|
|
|
else { |
344
|
37
|
|
|
|
|
58
|
my @columns = @{ $table->columns }; |
|
37
|
|
|
|
|
602
|
|
345
|
|
|
|
|
|
|
|
346
|
37
|
|
|
|
|
307
|
for my $column ( @columns ) { |
347
|
77
|
|
|
|
|
312
|
$column_string .= $self->_column_details( $table, $column, \%foreign_keys, $data ); |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
} |
350
|
|
|
|
|
|
|
|
351
|
91
|
|
|
|
|
296
|
my @indexes = @{ $table->indexes }; |
|
91
|
|
|
|
|
1910
|
|
352
|
91
|
|
|
|
|
943
|
my $indexes_hook = $self->_indexes_template( @indexes ); |
353
|
|
|
|
|
|
|
|
354
|
91
|
|
|
|
|
250
|
my $primary_key = join " ", @{ $table->primary_key }; |
|
91
|
|
|
|
|
383
|
|
355
|
91
|
|
|
|
|
295
|
my $version = $self->version; |
356
|
91
|
100
|
|
|
|
314
|
my $inherit_from = $self->inherit_from_core ? '::Core' : ''; |
357
|
91
|
100
|
|
|
|
283
|
my $use_utf8 = $self->utf8 ? "\nuse utf8;" : ''; |
358
|
|
|
|
|
|
|
|
359
|
91
|
|
|
|
|
1565
|
my $template = qq~package $package; |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
# ABSTRACT: Result class for $name$table_comment_perl |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
use strict; |
364
|
|
|
|
|
|
|
use warnings;$use_utf8 |
365
|
|
|
|
|
|
|
use base qw(DBIx::Class$inherit_from); |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
our \$VERSION = $version; |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
$load_components |
370
|
|
|
|
|
|
|
__PACKAGE__->table( '$name' ); |
371
|
|
|
|
|
|
|
__PACKAGE__->add_columns( |
372
|
|
|
|
|
|
|
$column_string |
373
|
|
|
|
|
|
|
); |
374
|
|
|
|
|
|
|
__PACKAGE__->set_primary_key( qw/ $primary_key / ); |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
$has_many |
377
|
|
|
|
|
|
|
$belongs_to |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
$indexes_hook |
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
# --- |
382
|
|
|
|
|
|
|
# Put your own code below this comment |
383
|
|
|
|
|
|
|
# --- |
384
|
|
|
|
|
|
|
$custom_code |
385
|
|
|
|
|
|
|
# --- |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
1;~; |
388
|
|
|
|
|
|
|
|
389
|
91
|
|
|
|
|
715
|
return $package, $template; |
390
|
|
|
|
|
|
|
} |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
sub _view_template{ |
393
|
2
|
|
|
2
|
|
6
|
my ($self, $view, $custom_code) = @_; |
394
|
|
|
|
|
|
|
|
395
|
2
|
|
|
|
|
8
|
my $name = $view->name; |
396
|
2
|
|
|
|
|
6
|
my ($class, $package) = $self->_create_class_and_package_name( $name ); |
397
|
|
|
|
|
|
|
|
398
|
2
|
|
50
|
|
|
14
|
my $comment = $view->comment // '{}'; |
399
|
2
|
|
|
|
|
8
|
utf8::upgrade( $comment ); |
400
|
|
|
|
|
|
|
|
401
|
2
|
|
|
|
|
3
|
my $data; |
402
|
2
|
|
|
|
|
4
|
my $view_comment_perl = ''; |
403
|
2
|
|
|
|
|
5
|
eval { |
404
|
2
|
|
|
|
|
21
|
$data = JSON->new->decode( $comment ); |
405
|
|
|
|
|
|
|
}; |
406
|
|
|
|
|
|
|
|
407
|
2
|
50
|
33
|
|
|
22
|
if ( !ref $data || 'HASH' ne ref $data ) { |
|
|
50
|
|
|
|
|
|
408
|
0
|
|
|
|
|
0
|
$data = {}; |
409
|
0
|
0
|
|
|
|
0
|
$view_comment_perl = $comment if $comment; |
410
|
|
|
|
|
|
|
} |
411
|
|
|
|
|
|
|
elsif ( $data->{comment} ) { |
412
|
0
|
|
|
|
|
0
|
$view_comment_perl = $data->{comment}; |
413
|
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
|
|
415
|
2
|
50
|
|
|
|
7
|
if ( $view_comment_perl ) { |
416
|
0
|
|
|
|
|
0
|
$view_comment_perl = sprintf "\n\n=head1 DESCRIPTION\n\n%s\n\n=cut", $view_comment_perl; |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
|
419
|
2
|
50
|
|
|
|
9
|
my @core_components = $self->inherit_from_core ? () : qw(PK::Auto Core); |
420
|
2
|
50
|
|
|
|
5
|
my $components = join( ' ', @core_components, @{ $data->{components} || [] } ); |
|
2
|
|
|
|
|
13
|
|
421
|
2
|
50
|
|
|
|
9
|
my $load_components = $components ? "__PACKAGE__->load_components( qw/$components/ );" : ''; |
422
|
|
|
|
|
|
|
|
423
|
2
|
|
|
|
|
5
|
my @columns = map{ $_->name }@{ $view->columns }; |
|
5
|
|
|
|
|
33
|
|
|
2
|
|
|
|
|
51
|
|
424
|
2
|
|
|
|
|
4
|
my $column_string = ''; |
425
|
|
|
|
|
|
|
|
426
|
2
|
50
|
|
|
|
8
|
if ( !$self->column_details ) { |
427
|
2
|
|
|
|
|
4
|
$column_string = "qw/\n" . join "\n", map{ " " . $_ }@columns, " /"; |
|
7
|
|
|
|
|
19
|
|
428
|
|
|
|
|
|
|
} |
429
|
|
|
|
|
|
|
else { |
430
|
0
|
|
|
|
|
0
|
my @columns = @{ $view->columns }; |
|
0
|
|
|
|
|
0
|
|
431
|
|
|
|
|
|
|
|
432
|
0
|
|
|
|
|
0
|
for my $column ( @columns ) { |
433
|
0
|
|
|
|
|
0
|
$column_string .= $self->_column_details( $view, $column, {}, $data ); |
434
|
|
|
|
|
|
|
} |
435
|
|
|
|
|
|
|
} |
436
|
|
|
|
|
|
|
|
437
|
2
|
|
|
|
|
8
|
my $version = $self->version; |
438
|
2
|
50
|
|
|
|
7
|
my $inherit_from = $self->inherit_from_core ? '::Core' : ''; |
439
|
2
|
50
|
|
|
|
11
|
my $use_utf8 = $self->utf8 ? "\nuse utf8;" : ''; |
440
|
2
|
|
|
|
|
6
|
my $definition = $view->definition; |
441
|
|
|
|
|
|
|
my $classes = join ', ', map { |
442
|
3
|
|
|
|
|
34
|
my ($class, $package) = $self->_create_class_and_package_name( $_ ); |
443
|
3
|
|
|
|
|
12
|
qq~"$package"~ |
444
|
2
|
50
|
|
|
|
4
|
} @{ $view->tables || [] }; |
|
2
|
|
|
|
|
40
|
|
445
|
|
|
|
|
|
|
|
446
|
2
|
|
|
|
|
35
|
my $template = qq~package $package; |
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
# ABSTRACT: Result class for $name$view_comment_perl |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
use strict; |
451
|
|
|
|
|
|
|
use warnings;$use_utf8 |
452
|
|
|
|
|
|
|
use base qw(DBIx::Class$inherit_from); |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
our \$VERSION = $version; |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
$load_components |
457
|
|
|
|
|
|
|
__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); |
458
|
|
|
|
|
|
|
__PACKAGE__->table( '$name' ); |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
__PACKAGE__->result_source_instance->view_definition( |
461
|
|
|
|
|
|
|
"$definition" |
462
|
|
|
|
|
|
|
); |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
__PACKAGE__->add_columns( |
465
|
|
|
|
|
|
|
$column_string |
466
|
|
|
|
|
|
|
); |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
# --- |
469
|
|
|
|
|
|
|
# Put your own code below this comment |
470
|
|
|
|
|
|
|
# --- |
471
|
|
|
|
|
|
|
$custom_code |
472
|
|
|
|
|
|
|
# --- |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
1;~; |
475
|
|
|
|
|
|
|
|
476
|
2
|
|
|
|
|
22
|
return $package, $template; |
477
|
|
|
|
|
|
|
} |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
sub _column_details { |
480
|
88
|
|
|
88
|
|
9218
|
my ($self, $table, $column, $foreign_keys, $data) = @_; |
481
|
|
|
|
|
|
|
|
482
|
88
|
|
100
|
|
|
403
|
my $default_value = $column->default_value // ''; |
483
|
88
|
|
|
|
|
173
|
$default_value =~ s/'/\\'/g; |
484
|
|
|
|
|
|
|
|
485
|
88
|
|
|
|
|
240
|
my $size = $column->length; |
486
|
|
|
|
|
|
|
|
487
|
88
|
100
|
100
|
|
|
571
|
if ( $column->datatype =~ /char/i && $column->length <= 0 ) { |
488
|
5
|
|
|
|
|
11
|
$size = 255; |
489
|
|
|
|
|
|
|
} |
490
|
|
|
|
|
|
|
|
491
|
88
|
|
|
|
|
150
|
my @options; |
492
|
|
|
|
|
|
|
|
493
|
88
|
|
|
|
|
181
|
my $name = $column->name; |
494
|
88
|
|
|
|
|
194
|
my $col_comment = $column->comment; |
495
|
|
|
|
|
|
|
|
496
|
88
|
|
|
|
|
350
|
push @options, "data_type => '" . $column->datatype . "',"; |
497
|
88
|
100
|
|
|
|
291
|
push @options, "is_auto_increment => 1," if $column->autoincrement; |
498
|
88
|
100
|
|
|
|
245
|
push @options, "is_nullable => 1," if !$column->not_null; |
499
|
88
|
100
|
|
|
|
303
|
push @options, "size => " . $size . "," if $size > 0; |
500
|
88
|
100
|
|
|
|
239
|
push @options, "default_value => '" . $default_value . "'," if length $default_value; |
501
|
|
|
|
|
|
|
|
502
|
88
|
100
|
|
381
|
|
501
|
if ( first { $column->datatype eq $_ }qw/SMALLINT INT INTEGER BIGINT MEDIUMINT NUMERIC DECIMAL/ ) { |
|
381
|
|
|
|
|
729
|
|
503
|
47
|
|
|
|
|
91
|
push @options, "is_numeric => 1,"; |
504
|
|
|
|
|
|
|
} |
505
|
|
|
|
|
|
|
|
506
|
88
|
100
|
|
|
|
502
|
if ( $table->isa('MySQL::Workbench::Parser::Table') ) { |
507
|
77
|
100
|
|
87
|
|
220
|
push @options, "retrieve_on_insert => 1," if first{ $name eq $_ }@{ $table->primary_key }; |
|
87
|
|
|
|
|
235
|
|
|
77
|
|
|
|
|
386
|
|
508
|
77
|
100
|
|
|
|
283
|
push @options, "is_foreign_key => 1," if $foreign_keys->{$name}; |
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
|
511
|
88
|
|
|
|
|
136
|
my %flags = %{ $column->flags }; |
|
88
|
|
|
|
|
290
|
|
512
|
88
|
100
|
|
|
|
231
|
if ( %flags ) { |
513
|
2
|
|
|
|
|
9
|
my $extras = join ', ', map { "$_ => 1" }sort keys %flags; |
|
3
|
|
|
|
|
22
|
|
514
|
2
|
|
|
|
|
13
|
push @options, sprintf "extra => {%s},", $extras; |
515
|
|
|
|
|
|
|
} |
516
|
|
|
|
|
|
|
|
517
|
88
|
|
|
|
|
164
|
my $column_comment_perl_raw = ''; |
518
|
|
|
|
|
|
|
|
519
|
88
|
100
|
100
|
|
|
527
|
if ( ( $data && $data->{column_info}->{$name} ) || $col_comment ) { |
|
|
|
100
|
|
|
|
|
520
|
18
|
|
|
|
|
37
|
local $Data::Dumper::Sortkeys = 1; |
521
|
18
|
|
|
|
|
34
|
local $Data::Dumper::Indent = 1; |
522
|
18
|
|
|
|
|
30
|
local $Data::Dumper::Pad = ' '; |
523
|
|
|
|
|
|
|
|
524
|
18
|
|
|
|
|
55
|
utf8::upgrade( $col_comment ); |
525
|
|
|
|
|
|
|
|
526
|
18
|
|
|
|
|
24
|
my $comment_data; |
527
|
|
|
|
|
|
|
eval { |
528
|
18
|
|
|
|
|
219
|
$comment_data = JSON->new->decode( $col_comment ); |
529
|
7
|
|
|
|
|
35
|
1; |
530
|
18
|
100
|
|
|
|
31
|
} or do { |
531
|
11
|
100
|
|
|
|
44
|
if ( $col_comment =~ /\{/ ) { |
532
|
1
|
|
|
|
|
64
|
print STDERR $col_comment, ": ", $@; |
533
|
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
}; |
535
|
|
|
|
|
|
|
|
536
|
18
|
100
|
100
|
|
|
137
|
if ( !$comment_data || 'HASH' ne ref $comment_data ) { |
537
|
12
|
|
|
|
|
26
|
$column_comment_perl_raw = $col_comment; |
538
|
12
|
|
|
|
|
51
|
$comment_data = {}; |
539
|
|
|
|
|
|
|
} |
540
|
|
|
|
|
|
|
else { |
541
|
6
|
|
100
|
|
|
44
|
$column_comment_perl_raw = delete $comment_data->{comment} // ''; |
542
|
|
|
|
|
|
|
} |
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
my %hash = ( |
545
|
18
|
100
|
|
|
|
102
|
%{ $data->{column_info}->{$name} || {} }, |
546
|
18
|
|
|
|
|
34
|
%{ $comment_data }, |
|
18
|
|
|
|
|
50
|
|
547
|
|
|
|
|
|
|
); |
548
|
|
|
|
|
|
|
|
549
|
18
|
100
|
|
|
|
104
|
if ( %hash ) { |
550
|
5
|
|
|
|
|
31
|
my $dump = Dumper( \%hash ); |
551
|
5
|
|
|
|
|
643
|
$dump =~ s{\$VAR1 \s+ = \s* \{ \s*? $}{}xms; |
552
|
5
|
|
|
|
|
37
|
$dump =~ s{\A\s+\n\s{8}}{}xms; |
553
|
5
|
|
|
|
|
44
|
$dump =~ s{\n[ ]+\};\s*\z}{}xms; |
554
|
|
|
|
|
|
|
|
555
|
5
|
|
|
|
|
28
|
push @options, $dump; |
556
|
|
|
|
|
|
|
} |
557
|
|
|
|
|
|
|
} |
558
|
|
|
|
|
|
|
|
559
|
88
|
|
|
|
|
310
|
my $option_string = join "\n ", @options; |
560
|
|
|
|
|
|
|
|
561
|
88
|
|
|
|
|
251
|
my @column_comment_lines = split /\r?\n/, $column_comment_perl_raw; |
562
|
88
|
|
|
|
|
162
|
my $column_comment_perl = ''; |
563
|
|
|
|
|
|
|
|
564
|
88
|
100
|
|
|
|
225
|
if ( @column_comment_lines ) { |
565
|
12
|
|
|
|
|
55
|
my $sep = sprintf "\n%s%s%s# ", ' ' x 4, ' ' x length $name, ' ' x 6; |
566
|
12
|
|
|
|
|
40
|
$column_comment_perl = ' # ' . join ( $sep, @column_comment_lines ); |
567
|
|
|
|
|
|
|
} |
568
|
|
|
|
|
|
|
|
569
|
88
|
|
|
|
|
415
|
my $details = sprintf " %s => {%s\n %s\n },\n", |
570
|
|
|
|
|
|
|
$name, |
571
|
|
|
|
|
|
|
$column_comment_perl, |
572
|
|
|
|
|
|
|
$option_string; |
573
|
|
|
|
|
|
|
|
574
|
88
|
|
|
|
|
460
|
return $details; |
575
|
|
|
|
|
|
|
} |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
sub _indexes_template { |
578
|
94
|
|
|
94
|
|
7158
|
my ($self, @indexes) = @_; |
579
|
|
|
|
|
|
|
|
580
|
94
|
100
|
|
|
|
304
|
return '' if !@indexes; |
581
|
90
|
100
|
|
|
|
444
|
return '' if $self->skip_indexes; |
582
|
|
|
|
|
|
|
|
583
|
87
|
|
|
|
|
165
|
my $hooks = ''; |
584
|
87
|
|
|
|
|
213
|
my $indexlist = ''; |
585
|
|
|
|
|
|
|
|
586
|
87
|
|
|
|
|
148
|
my $unique_indexes = ''; |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
INDEX: |
589
|
87
|
|
|
|
|
192
|
for my $index ( @indexes ) { |
590
|
156
|
|
|
|
|
470
|
my $type = $index->type; |
591
|
156
|
100
|
|
|
|
422
|
$type = 'normal' if !$type; |
592
|
156
|
|
|
|
|
351
|
$type = lc $type; |
593
|
|
|
|
|
|
|
|
594
|
156
|
100
|
|
|
|
481
|
next INDEX if $type eq 'primary'; |
595
|
|
|
|
|
|
|
|
596
|
72
|
100
|
|
|
|
224
|
if ( $type eq 'unique' ) { |
597
|
|
|
|
|
|
|
$unique_indexes .= sprintf q~__PACKAGE__->add_unique_constraint( |
598
|
|
|
|
|
|
|
%s => [qw/%s/], |
599
|
21
|
|
|
|
|
98
|
);~, $index->name, ( join ' ', @{ $index->columns } ); |
|
21
|
|
|
|
|
451
|
|
600
|
21
|
|
|
|
|
283
|
next INDEX; |
601
|
|
|
|
|
|
|
} |
602
|
|
|
|
|
|
|
|
603
|
51
|
100
|
|
|
|
184
|
$type = 'normal' if $type eq 'index'; |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
$hooks .= sprintf ' $table->add_index( |
606
|
|
|
|
|
|
|
type => "%s", |
607
|
|
|
|
|
|
|
name => "%s", |
608
|
|
|
|
|
|
|
fields => [%s], |
609
|
|
|
|
|
|
|
); |
610
|
|
|
|
|
|
|
|
611
|
51
|
|
|
|
|
151
|
', $type, $index->name, join ', ', map{ "'$_'" }@{ $index->columns }; |
|
51
|
|
|
|
|
702
|
|
|
51
|
|
|
|
|
895
|
|
612
|
|
|
|
|
|
|
|
613
|
51
|
|
|
|
|
267
|
$indexlist.= sprintf "=item * %s\n\n", $index->name; |
614
|
|
|
|
|
|
|
} |
615
|
|
|
|
|
|
|
|
616
|
87
|
|
|
|
|
167
|
my $sub_string = ''; |
617
|
87
|
100
|
|
|
|
223
|
$sub_string .= $unique_indexes if $unique_indexes; |
618
|
|
|
|
|
|
|
|
619
|
87
|
100
|
|
|
|
301
|
return $sub_string if !$hooks; |
620
|
|
|
|
|
|
|
|
621
|
27
|
|
|
|
|
604
|
$sub_string .= qq~ |
622
|
|
|
|
|
|
|
=head1 DEPLOYMENT |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
=head2 sqlt_deploy_hook |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
These indexes are added to the table during deployment |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
=over 4 |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
$indexlist |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
=back |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
=cut |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
sub sqlt_deploy_hook { |
637
|
|
|
|
|
|
|
my (\$self, \$table) = \@_; |
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
$hooks |
640
|
|
|
|
|
|
|
return 1; |
641
|
|
|
|
|
|
|
} |
642
|
|
|
|
|
|
|
~; |
643
|
|
|
|
|
|
|
|
644
|
27
|
|
|
|
|
118
|
return $sub_string; |
645
|
|
|
|
|
|
|
} |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
sub _main_template{ |
648
|
40
|
|
|
40
|
|
5923
|
my ($self) = @_; |
649
|
|
|
|
|
|
|
|
650
|
40
|
|
|
|
|
96
|
my @class_names = @{ $self->classes }; |
|
40
|
|
|
|
|
205
|
|
651
|
40
|
|
|
|
|
135
|
my $classes = join "\n", map{ " " . $_ }@class_names; |
|
95
|
|
|
|
|
350
|
|
652
|
|
|
|
|
|
|
|
653
|
40
|
|
|
|
|
174
|
my $schema_name = $self->schema_name; |
654
|
40
|
100
|
|
|
|
223
|
$schema_name = '' if !defined $schema_name; |
655
|
|
|
|
|
|
|
|
656
|
40
|
100
|
|
|
|
143
|
if (!$schema_name) { |
657
|
27
|
|
|
|
|
121
|
my @schema_names = qw(DBIC_Schema Database DBIC MySchema MyDatabase DBIxClass_Schema); |
658
|
|
|
|
|
|
|
|
659
|
27
|
|
|
|
|
76
|
for my $schema ( @schema_names ){ |
660
|
32
|
100
|
|
|
|
72
|
if( !grep{ $_ eq $schema }@class_names ){ |
|
98
|
|
|
|
|
250
|
|
661
|
26
|
|
|
|
|
64
|
$schema_name = $schema; |
662
|
26
|
|
|
|
|
81
|
last; |
663
|
|
|
|
|
|
|
} |
664
|
|
|
|
|
|
|
} |
665
|
|
|
|
|
|
|
} |
666
|
|
|
|
|
|
|
|
667
|
40
|
100
|
|
|
|
311
|
croak "couldn't determine a package name for the schema" unless $schema_name; |
668
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
|
670
|
39
|
|
|
|
|
813
|
$self->_set_schema_name( $schema_name ); |
671
|
|
|
|
|
|
|
|
672
|
39
|
|
|
|
|
469
|
my $namespace = $self->namespace . '::' . $schema_name; |
673
|
39
|
|
|
|
|
140
|
$namespace =~ s/^:://; |
674
|
|
|
|
|
|
|
|
675
|
39
|
|
|
|
|
82
|
my $version; |
676
|
39
|
|
|
|
|
78
|
do { |
677
|
39
|
|
|
|
|
153
|
my $lib_path = $self->output_path; |
678
|
39
|
|
|
|
|
279
|
my @paths = @INC; |
679
|
39
|
|
|
|
|
148
|
unshift @INC, $lib_path; |
680
|
|
|
|
|
|
|
|
681
|
39
|
|
|
|
|
3008
|
eval "require $namespace"; |
682
|
39
|
|
|
|
|
653
|
$version = $namespace->VERSION(); |
683
|
|
|
|
|
|
|
}; |
684
|
|
|
|
|
|
|
|
685
|
39
|
|
|
|
|
213
|
my $custom_code; |
686
|
39
|
100
|
|
|
|
306
|
if ( $version ) { |
687
|
9
|
|
|
|
|
59
|
(my $path = $namespace) =~ s{::}{/}g; |
688
|
9
|
|
|
|
|
58
|
my $schema_file = $self->output_path . '/' . $path . '.pm'; |
689
|
9
|
|
|
|
|
43
|
$custom_code = $self->_custom_code( $schema_file ); |
690
|
|
|
|
|
|
|
} |
691
|
|
|
|
|
|
|
|
692
|
39
|
|
100
|
|
|
404
|
$custom_code //= ''; |
693
|
|
|
|
|
|
|
|
694
|
39
|
|
|
|
|
77
|
my %all_namespaces_to_load; |
695
|
39
|
100
|
|
|
|
339
|
if ( $self->resultset_namespace ) { |
696
|
8
|
|
|
|
|
14
|
push @{ $all_namespaces_to_load{resultset_namespace} }, sprintf "'%s'", $self->resultset_namespace; |
|
8
|
|
|
|
|
48
|
|
697
|
|
|
|
|
|
|
} |
698
|
|
|
|
|
|
|
|
699
|
39
|
100
|
|
|
|
269
|
if ( $self->load_resultset_namespace ) { |
700
|
3
|
|
|
|
|
23
|
push @{ $all_namespaces_to_load{resultset_namespace} }, map { "'$_'" } |
|
6
|
|
|
|
|
32
|
|
701
|
|
|
|
|
|
|
ref $self->load_resultset_namespace ? |
702
|
3
|
100
|
|
|
|
6
|
@{ $self->load_resultset_namespace } : |
|
2
|
|
|
|
|
8
|
|
703
|
|
|
|
|
|
|
$self->load_resultset_namespace; |
704
|
|
|
|
|
|
|
} |
705
|
|
|
|
|
|
|
|
706
|
39
|
100
|
|
|
|
246
|
if ( $self->load_result_namespace ) { |
707
|
3
|
|
|
|
|
20
|
push @{ $all_namespaces_to_load{result_namespace} }, map { "'$_'" } |
|
6
|
|
|
|
|
18
|
|
708
|
|
|
|
|
|
|
ref $self->load_result_namespace ? |
709
|
3
|
100
|
|
|
|
6
|
@{ $self->load_result_namespace } : |
|
2
|
|
|
|
|
8
|
|
710
|
|
|
|
|
|
|
$self->load_result_namespace; |
711
|
|
|
|
|
|
|
} |
712
|
|
|
|
|
|
|
|
713
|
39
|
100
|
|
|
|
260
|
if ( $self->result_namespace ) { |
714
|
12
|
|
|
|
|
47
|
my $namespace = sprintf "'%s::Result'", $self->result_namespace; |
715
|
12
|
|
|
|
|
27
|
my $found = grep { $namespace eq $_ }@{ $all_namespaces_to_load{result_namespace} }; |
|
6
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
32
|
|
716
|
12
|
100
|
|
|
|
37
|
unshift @{ $all_namespaces_to_load{result_namespace} }, $namespace if !$found; |
|
11
|
|
|
|
|
35
|
|
717
|
|
|
|
|
|
|
} |
718
|
|
|
|
|
|
|
|
719
|
39
|
|
|
|
|
187
|
my $version_add = $self->version_add; |
720
|
39
|
100
|
|
|
|
194
|
$version_add = 0.01 if !$version_add; |
721
|
|
|
|
|
|
|
|
722
|
39
|
100
|
|
|
|
120
|
if ( $version ) { |
723
|
9
|
|
|
|
|
35
|
$version += $version_add; |
724
|
|
|
|
|
|
|
} |
725
|
|
|
|
|
|
|
|
726
|
39
|
100
|
|
|
|
140
|
$version = $version_add if !$version; |
727
|
|
|
|
|
|
|
|
728
|
39
|
|
|
|
|
173
|
$self->_set_version( $version ); |
729
|
|
|
|
|
|
|
|
730
|
39
|
|
|
|
|
91
|
my @namespace_types; |
731
|
39
|
|
|
|
|
198
|
for my $namespace_type ( sort keys %all_namespaces_to_load ) { |
732
|
23
|
|
|
|
|
40
|
my @namespaces = @{ $all_namespaces_to_load{$namespace_type} }; |
|
23
|
|
|
|
|
60
|
|
733
|
|
|
|
|
|
|
|
734
|
23
|
100
|
|
|
|
164
|
push @namespace_types, sprintf "\n %s => %s,", |
735
|
|
|
|
|
|
|
$namespace_type, |
736
|
|
|
|
|
|
|
( @namespaces == 1 ? $namespaces[0] : '[' . (join ', ', @namespaces ) . ']' ); |
737
|
|
|
|
|
|
|
} |
738
|
|
|
|
|
|
|
|
739
|
39
|
|
|
|
|
132
|
my $namespaces_to_load = ''; |
740
|
39
|
100
|
|
|
|
225
|
$namespaces_to_load = "(" . (join '', @namespace_types) . "\n)" if @namespace_types; |
741
|
|
|
|
|
|
|
|
742
|
39
|
100
|
|
|
|
245
|
my $use_utf8 = $self->utf8 ? "\nuse utf8;" : ''; |
743
|
39
|
100
|
|
|
|
226
|
my $base_class = $self->schema_base_class ? $self->schema_base_class : 'DBIx::Class::Schema'; |
744
|
|
|
|
|
|
|
|
745
|
39
|
|
|
|
|
507
|
my $template = qq~package $namespace; |
746
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
# ABSTRACT: Schema class |
748
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
use strict; |
750
|
|
|
|
|
|
|
use warnings;$use_utf8 |
751
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
use base qw/$base_class/; |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
our \$VERSION = $version; |
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
__PACKAGE__->load_namespaces$namespaces_to_load; |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
# --- |
759
|
|
|
|
|
|
|
# Put your own code below this comment |
760
|
|
|
|
|
|
|
# --- |
761
|
|
|
|
|
|
|
$custom_code |
762
|
|
|
|
|
|
|
# --- |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
1;~; |
765
|
|
|
|
|
|
|
|
766
|
39
|
|
|
|
|
278
|
return $namespace, $template; |
767
|
|
|
|
|
|
|
} |
768
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
1; |
771
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
__END__ |