Commit | Line | Data |
ad91060a |
1 | package Catalyst::Helper::Model::DBIC::Schema; |
2 | |
73f72d28 |
3 | use namespace::autoclean; |
f090a149 |
4 | use Moose; |
ffbf1967 |
5 | no warnings 'uninitialized'; |
018eb0e2 |
6 | |
fdbe669e |
7 | our $VERSION = '0.43'; |
4e251d1a |
8 | $VERSION = eval $VERSION; |
2201c2e4 |
9 | |
0f2fd2c0 |
10 | use Carp; |
2201c2e4 |
11 | use Tie::IxHash (); |
12 | use Data::Dumper (); |
c4fee9b8 |
13 | use List::Util 'first'; |
4cbe63e7 |
14 | use MooseX::Types::Moose qw/Str HashRef Bool ArrayRef/; |
15 | use Catalyst::Model::DBIC::Schema::Types 'CreateOption'; |
4cbe63e7 |
16 | use List::MoreUtils 'firstidx'; |
5f9a34d7 |
17 | use Scalar::Util 'looks_like_number'; |
2201c2e4 |
18 | |
ad91060a |
19 | =head1 NAME |
20 | |
21 | Catalyst::Helper::Model::DBIC::Schema - Helper for DBIC Schema Models |
22 | |
23 | =head1 SYNOPSIS |
24 | |
2201c2e4 |
25 | script/create.pl model CatalystModelName DBIC::Schema MyApp::SchemaClass \ |
c34bcab6 |
26 | [ create=dynamic | create=static ] [ traits=trait1,trait2... ] \ |
2ff00e2b |
27 | [ Schema::Loader opts ] [ dsn user pass ] \ |
28 | [ other connect_info args ] |
0f2fd2c0 |
29 | |
d89e6c8a |
30 | =head1 DESCRIPTION |
31 | |
32 | Helper for the DBIC Schema Models. |
33 | |
34 | =head2 Arguments: |
35 | |
018eb0e2 |
36 | C<CatalystModelName> is the short name for the Catalyst Model class |
37 | being generated (i.e. callable with C<$c-E<gt>model('CatalystModelName')>). |
6116daed |
38 | |
018eb0e2 |
39 | C<MyApp::SchemaClass> is the fully qualified classname of your Schema, |
6116daed |
40 | which might or might not yet exist. Note that you should have a good |
41 | reason to create this under a new global namespace, otherwise use an |
42 | existing top level namespace for your schema class. |
43 | |
018eb0e2 |
44 | C<create=dynamic> instructs this Helper to generate the named Schema |
6116daed |
45 | class for you, basing it on L<DBIx::Class::Schema::Loader> (which |
46 | means the table information will always be dynamically loaded at |
47 | runtime from the database). |
48 | |
018eb0e2 |
49 | C<create=static> instructs this Helper to generate the named Schema |
6116daed |
50 | class for you, using L<DBIx::Class::Schema::Loader> in "one shot" |
51 | mode to create a standard, manually-defined L<DBIx::Class::Schema> |
52 | setup, based on what the Loader sees in your database at this moment. |
53 | A Schema/Model pair generated this way will not require |
54 | L<DBIx::Class::Schema::Loader> at runtime, and will not automatically |
55 | adapt itself to changes in your database structure. You can edit |
56 | the generated classes by hand to refine them. |
57 | |
c34bcab6 |
58 | C<traits> is the list of traits to apply to the model, see |
2ff00e2b |
59 | L<Catalyst::Model::DBIC::Schema> for details. |
60 | |
61 | C<Schema::Loader opts> are described in L</TYPICAL EXAMPLES> below. |
62 | |
018eb0e2 |
63 | C<connect_info> arguments are the same as what |
6116daed |
64 | DBIx::Class::Schema::connect expects, and are storage_type-specific. |
65 | For DBI-based storage, these arguments are the dsn, username, |
66 | password, and connect options, respectively. These are optional for |
67 | existing Schemas, but required if you use either of the C<create=> |
68 | options. |
d89e6c8a |
69 | |
a75b6e58 |
70 | username and password can be omitted for C<SQLite> dsns. |
71 | |
d89e6c8a |
72 | Use of either of the C<create=> options requires L<DBIx::Class::Schema::Loader>. |
0b2a7108 |
73 | |
74 | =head1 TYPICAL EXAMPLES |
75 | |
a75b6e58 |
76 | Use DBIx::Class::Schema::Loader to create a static DBIx::Class::Schema, |
77 | and a Model which references it: |
78 | |
2201c2e4 |
79 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ |
80 | MyApp::SchemaClass create=static dbi:mysql:foodb myuname mypass |
81 | |
a75b6e58 |
82 | Same, with extra connect_info args |
83 | user and pass can be omitted for sqlite, since they are always empty |
84 | |
2201c2e4 |
85 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ |
a75b6e58 |
86 | MyApp::SchemaClass create=static dbi:SQLite:foo.db \ |
2201c2e4 |
87 | AutoCommit=1 cursor_class=DBIx::Class::Cursor::Cached \ |
a75b6e58 |
88 | on_connect_do='["select 1", "select 2"]' quote_char='"' |
89 | |
c34bcab6 |
90 | If using a 2 character quote_char: |
91 | |
92 | script/myapp_create.pl ... quote_char='[]' |
93 | |
a75b6e58 |
94 | B<ON WINDOWS COMMAND LINES QUOTING RULES ARE DIFFERENT> |
95 | |
96 | In C<cmd.exe> the above example would be: |
97 | |
98 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ |
99 | MyApp::SchemaClass create=static dbi:SQLite:foo.db \ |
100 | AutoCommit=1 cursor_class=DBIx::Class::Cursor::Cached \ |
101 | on_connect_do="[\"select 1\", \"select 2\"]" quote_char="\"" |
102 | |
103 | Same, but with extra Schema::Loader args (separate multiple values by commas): |
0b2a7108 |
104 | |
2201c2e4 |
105 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ |
106 | MyApp::SchemaClass create=static db_schema=foodb components=Foo,Bar \ |
4cbe63e7 |
107 | exclude='^(wibble|wobble)$' moniker_map='{ foo => "FOO" }' \ |
2201c2e4 |
108 | dbi:Pg:dbname=foodb myuname mypass |
34f036a0 |
109 | |
ce9e19dc |
110 | Coderefs are also supported: |
111 | |
112 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ |
113 | MyApp::SchemaClass create=static \ |
114 | inflect_singular='sub { $_[0] =~ /\A(.+?)(_id)?\z/; $1 }' \ |
115 | moniker_map='sub { join(q{}, map ucfirst, split(/[\W_]+/, lc $_[0])); }' \ |
116 | dbi:mysql:foodb myuname mypass |
117 | |
a75b6e58 |
118 | See L<DBIx::Class::Schema::Loader::Base> for a list of options |
119 | |
120 | Create a dynamic DBIx::Class::Schema::Loader-based Schema, |
121 | and a Model which references it (B<DEPRECATED>): |
34f036a0 |
122 | |
2201c2e4 |
123 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ |
124 | MyApp::SchemaClass create=dynamic dbi:mysql:foodb myuname mypass |
ad91060a |
125 | |
a75b6e58 |
126 | Reference an existing Schema of any kind, and provide some connection information for ->config: |
127 | |
2201c2e4 |
128 | script/myapp_create.pl model CatalystModelName DBIC::Schema \ |
129 | MyApp::SchemaClass dbi:mysql:foodb myuname mypass |
ad91060a |
130 | |
a75b6e58 |
131 | Same, but don't supply connect information yet (you'll need to do this |
132 | in your app config, or [not recommended] in the schema itself). |
133 | |
d89e6c8a |
134 | script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass |
ad91060a |
135 | |
f090a149 |
136 | =cut |
137 | |
138 | has helper => (is => 'ro', isa => 'Catalyst::Helper', required => 1); |
4cbe63e7 |
139 | has create => (is => 'rw', isa => CreateOption); |
140 | has args => (is => 'ro', isa => ArrayRef); |
c34bcab6 |
141 | has traits => (is => 'rw', isa => ArrayRef); |
61ed82a5 |
142 | has schema_class => (is => 'ro', isa => Str, required => 1); |
61ed82a5 |
143 | has loader_args => (is => 'rw', isa => HashRef); |
144 | has connect_info => (is => 'rw', isa => HashRef); |
61ed82a5 |
145 | has old_schema => (is => 'rw', isa => Bool, lazy_build => 1); |
4cbe63e7 |
146 | has components => (is => 'rw', isa => ArrayRef); |
f090a149 |
147 | |
018eb0e2 |
148 | =head1 METHODS |
ad91060a |
149 | |
018eb0e2 |
150 | =head2 mk_compclass |
ad91060a |
151 | |
0fbbc8d5 |
152 | This is called by L<Catalyst::Helper> with the commandline args to generate the |
153 | files. |
154 | |
ad91060a |
155 | =cut |
156 | |
157 | sub mk_compclass { |
2201c2e4 |
158 | my ($package, $helper, $schema_class, @args) = @_; |
159 | |
4cbe63e7 |
160 | my $self = $package->new( |
161 | helper => $helper, |
162 | schema_class => $schema_class, |
163 | args => \@args |
164 | ); |
0f2fd2c0 |
165 | |
4cbe63e7 |
166 | $self->run; |
167 | } |
168 | |
169 | sub BUILD { |
170 | my $self = shift; |
171 | my $helper = $self->helper; |
7dfd616a |
172 | my @args = @{ $self->args || [] }; |
4cbe63e7 |
173 | |
174 | $helper->{schema_class} = $self->schema_class; |
c4fee9b8 |
175 | |
176 | @args = $self->_cleanup_args(\@args); |
d89e6c8a |
177 | |
c34bcab6 |
178 | my ($traits_idx, $traits); |
179 | if (($traits_idx = firstidx { ($traits) = /^traits=(\S*)\z/ } @args) != -1) { |
180 | my @traits = split /,/ => $traits; |
2201c2e4 |
181 | |
c34bcab6 |
182 | $self->traits(\@traits); |
4cbe63e7 |
183 | |
c34bcab6 |
184 | $helper->{traits} = '[' |
7dfd616a |
185 | .(join ',' => map { qq{'$_'} } @traits) |
4cbe63e7 |
186 | .']'; |
187 | |
c34bcab6 |
188 | splice @args, $traits_idx, 1, (); |
4cbe63e7 |
189 | } |
190 | |
191 | if ($args[0] && $args[0] =~ /^create=(\S*)\z/) { |
192 | $self->create($1); |
193 | shift @args; |
2ff00e2b |
194 | |
2201c2e4 |
195 | if (@args) { |
196 | $self->_parse_loader_args(\@args); |
197 | |
4cbe63e7 |
198 | $helper->{loader_args} = $self->_build_helper_loader_args; |
ca7cf6f0 |
199 | } |
200 | } |
4cbe63e7 |
201 | |
ca7cf6f0 |
202 | my $dbi_dsn_part; |
203 | if (first { ($dbi_dsn_part) = /^(dbi):/i } @args) { |
204 | die |
a4803ca6 |
205 | qq{DSN must start with 'dbi:' not '$dbi_dsn_part' (case matters!)} |
ca7cf6f0 |
206 | if $dbi_dsn_part ne 'dbi'; |
a4803ca6 |
207 | |
ca7cf6f0 |
208 | $helper->{setup_connect_info} = 1; |
2201c2e4 |
209 | |
ca7cf6f0 |
210 | $helper->{connect_info} = |
211 | $self->_build_helper_connect_info(\@args); |
2201c2e4 |
212 | |
ca7cf6f0 |
213 | $self->_parse_connect_info(\@args); |
d89e6c8a |
214 | } |
0f2fd2c0 |
215 | |
2201c2e4 |
216 | $helper->{generator} = ref $self; |
217 | $helper->{generator_version} = $VERSION; |
4cbe63e7 |
218 | } |
219 | |
9f7cc709 |
220 | =head2 run |
221 | |
222 | Can be called on an instance to generate the files. |
223 | |
224 | =cut |
225 | |
4cbe63e7 |
226 | sub run { |
227 | my $self = shift; |
2201c2e4 |
228 | |
4cbe63e7 |
229 | if ($self->create eq 'dynamic') { |
c4fee9b8 |
230 | $self->_print_dynamic_deprecation_warning; |
2201c2e4 |
231 | $self->_gen_dynamic_schema; |
4cbe63e7 |
232 | } elsif ($self->create eq 'static') { |
2201c2e4 |
233 | $self->_gen_static_schema; |
234 | } |
235 | |
236 | $self->_gen_model; |
237 | } |
238 | |
239 | sub _parse_loader_args { |
240 | my ($self, $args) = @_; |
241 | |
242 | my %loader_args = $self->_read_loader_args($args); |
243 | |
244 | while (my ($key, $val) = each %loader_args) { |
245 | next if $key =~ /^(?:components|constraint|exclude)\z/; |
246 | |
5f9a34d7 |
247 | $loader_args{$key} = $self->_eval($val); |
c4fee9b8 |
248 | die "syntax error for loader args key '$key' with value '$val': $@" |
2201c2e4 |
249 | if $@; |
250 | } |
251 | |
7e6a622c |
252 | my @components = $self->_build_loader_components( |
253 | delete $loader_args{components}, |
254 | $loader_args{use_namespaces}, |
255 | ); |
2201c2e4 |
256 | |
4cbe63e7 |
257 | $self->components(\@components); |
258 | |
2201c2e4 |
259 | for my $re_opt (qw/constraint exclude/) { |
260 | $loader_args{$re_opt} = qr/$loader_args{$re_opt}/ |
261 | if exists $loader_args{$re_opt}; |
262 | } |
263 | |
264 | tie my %result, 'Tie::IxHash'; |
265 | |
266 | %result = ( |
267 | relationships => 1, |
4f907946 |
268 | use_moose => 1, |
f0279514 |
269 | col_collision_map => 'column_%s', |
f090a149 |
270 | (!$self->old_schema ? ( |
2201c2e4 |
271 | use_namespaces => 1 |
272 | ) : ()), |
273 | (@components ? ( |
274 | components => \@components |
7e6a622c |
275 | ) : ()), |
276 | (%loader_args ? %loader_args : ()), |
2201c2e4 |
277 | ); |
278 | |
279 | $self->loader_args(\%result); |
280 | |
281 | wantarray ? %result : \%result; |
282 | } |
283 | |
284 | sub _read_loader_args { |
285 | my ($self, $args) = @_; |
286 | |
287 | my %loader_args; |
288 | |
a4803ca6 |
289 | while (@$args && $args->[0] !~ /^dbi:/i) { |
2201c2e4 |
290 | my ($key, $val) = split /=/, shift(@$args), 2; |
ca14239e |
291 | |
4cbe63e7 |
292 | if ($self->_is_struct($val)) { |
293 | $loader_args{$key} = $val; |
294 | } elsif ((my @vals = split /,/ => $val) > 1) { |
2201c2e4 |
295 | $loader_args{$key} = \@vals; |
ca14239e |
296 | } else { |
2201c2e4 |
297 | $loader_args{$key} = $val; |
ca14239e |
298 | } |
299 | } |
300 | |
2201c2e4 |
301 | wantarray ? %loader_args : \%loader_args; |
302 | } |
303 | |
304 | sub _build_helper_loader_args { |
305 | my $self = shift; |
306 | |
307 | my $args = $self->loader_args; |
308 | |
309 | tie my %loader_args, 'Tie::IxHash'; |
310 | |
311 | while (my ($arg, $val) = each %$args) { |
312 | if (ref $val) { |
313 | $loader_args{$arg} = $self->_data_struct_to_string($val); |
314 | } else { |
315 | $loader_args{$arg} = qq{'$val'}; |
0b2a7108 |
316 | } |
0f2fd2c0 |
317 | } |
318 | |
2201c2e4 |
319 | \%loader_args |
320 | } |
321 | |
322 | sub _build_loader_components { |
7e6a622c |
323 | my ($self, $components, $use_namespaces) = @_; |
d89e6c8a |
324 | |
7e6a622c |
325 | my @components = $self->old_schema && (not $use_namespaces) ? () |
326 | : ('InflateColumn::DateTime'); |
d89e6c8a |
327 | |
2201c2e4 |
328 | if ($components) { |
329 | $components = [ $components ] if !ref $components; |
330 | push @components, @$components; |
d89e6c8a |
331 | } |
2201c2e4 |
332 | |
333 | wantarray ? @components : \@components; |
334 | } |
335 | |
336 | sub _build_helper_connect_info { |
337 | my ($self, $connect_info) = @_; |
338 | |
339 | my @connect_info = @$connect_info; |
340 | |
a75b6e58 |
341 | my ($dsn, $user, $password) = $self->_get_dsn_user_pass(\@connect_info); |
2201c2e4 |
342 | |
343 | tie my %helper_connect_info, 'Tie::IxHash'; |
344 | |
345 | %helper_connect_info = ( |
346 | dsn => qq{'$dsn'}, |
347 | user => qq{'$user'}, |
348 | password => qq{'$password'} |
349 | ); |
350 | |
351 | for (@connect_info) { |
352 | if (/^\s*{.*}\s*\z/) { |
5f9a34d7 |
353 | my $hash = $self->_eval($_); |
c4fee9b8 |
354 | die "Syntax errorr in connect_info hash: $_: $@" if $@; |
2201c2e4 |
355 | my %hash = %$hash; |
356 | |
357 | for my $key (keys %hash) { |
358 | my $val = $hash{$key}; |
359 | |
360 | if (ref $val) { |
361 | $val = $self->_data_struct_to_string($val); |
362 | } else { |
c34bcab6 |
363 | $val = $self->_quote($val); |
2201c2e4 |
364 | } |
365 | |
366 | $helper_connect_info{$key} = $val; |
592cd3ae |
367 | } |
2201c2e4 |
368 | |
369 | next; |
592cd3ae |
370 | } |
371 | |
2201c2e4 |
372 | my ($key, $val) = split /=/, $_, 2; |
1d155058 |
373 | |
c34bcab6 |
374 | if ($key eq 'quote_char') { |
375 | $helper_connect_info{$key} = length($val) == 1 ? |
376 | $self->_quote($val) : |
377 | $self->_data_struct_to_string([split //, $val]); |
378 | } else { |
379 | $helper_connect_info{$key} = $self->_quote_unless_struct($val); |
380 | } |
2201c2e4 |
381 | } |
1d155058 |
382 | |
2201c2e4 |
383 | \%helper_connect_info |
384 | } |
1d155058 |
385 | |
61ed82a5 |
386 | sub _build_old_schema { |
387 | my $self = shift; |
388 | |
389 | my @schema_pm = split '::', $self->schema_class; |
390 | $schema_pm[-1] .= '.pm'; |
391 | my $schema_file = |
392 | File::Spec->catfile($self->helper->{base}, 'lib', @schema_pm); |
393 | |
394 | if (-f $schema_file) { |
395 | my $schema_code = do { local (@ARGV, $/) = $schema_file; <> }; |
396 | return 1 if $schema_code =~ /->load_classes/; |
397 | } |
398 | |
399 | 0; |
400 | } |
401 | |
2201c2e4 |
402 | sub _data_struct_to_string { |
403 | my ($self, $data) = @_; |
34f036a0 |
404 | |
2201c2e4 |
405 | local $Data::Dumper::Terse = 1; |
406 | local $Data::Dumper::Quotekeys = 0; |
407 | local $Data::Dumper::Indent = 0; |
408 | local $Data::Dumper::Useqq = 1; |
34f036a0 |
409 | |
2201c2e4 |
410 | return Data::Dumper->Dump([$data]); |
411 | } |
34f036a0 |
412 | |
a75b6e58 |
413 | sub _get_dsn_user_pass { |
414 | my ($self, $connect_info) = @_; |
415 | |
416 | my $dsn = shift @$connect_info; |
417 | my ($user, $password); |
418 | |
419 | if ($dsn =~ /sqlite/i) { |
420 | ($user, $password) = ('', ''); |
108a45d1 |
421 | shift @$connect_info while @$connect_info and $connect_info->[0] eq ''; |
a75b6e58 |
422 | } else { |
423 | ($user, $password) = splice @$connect_info, 0, 2; |
424 | } |
425 | |
426 | ($dsn, $user, $password) |
427 | } |
428 | |
2201c2e4 |
429 | sub _parse_connect_info { |
430 | my ($self, $connect_info) = @_; |
431 | |
432 | my @connect_info = @$connect_info; |
433 | |
a75b6e58 |
434 | my ($dsn, $user, $password) = $self->_get_dsn_user_pass(\@connect_info); |
2201c2e4 |
435 | |
436 | tie my %connect_info, 'Tie::IxHash'; |
437 | @connect_info{qw/dsn user password/} = ($dsn, $user, $password); |
438 | |
439 | for (@connect_info) { |
440 | if (/^\s*{.*}\s*\z/) { |
5f9a34d7 |
441 | my $hash = $self->_eval($_); |
c4fee9b8 |
442 | die "Syntax errorr in connect_info hash: $_: $@" if $@; |
2201c2e4 |
443 | |
444 | %connect_info = (%connect_info, %$hash); |
ca14239e |
445 | |
2201c2e4 |
446 | next; |
ca14239e |
447 | } |
448 | |
2201c2e4 |
449 | my ($key, $val) = split /=/, $_, 2; |
450 | |
c34bcab6 |
451 | if ($key eq 'quote_char') { |
452 | $connect_info{$key} = length($val) == 1 ? $val : [split //, $val]; |
453 | } elsif ($key =~ /^(?:name_sep|limit_dialect)\z/) { |
3f139b02 |
454 | $connect_info{$key} = $val; |
455 | } else { |
5f9a34d7 |
456 | $connect_info{$key} = $self->_eval($val); |
3f139b02 |
457 | } |
458 | |
c4fee9b8 |
459 | die "syntax error for connect_info key '$key' with value '$val': $@" |
2201c2e4 |
460 | if $@; |
d89e6c8a |
461 | } |
202d09c8 |
462 | |
2201c2e4 |
463 | $self->connect_info(\%connect_info); |
464 | |
465 | \%connect_info |
466 | } |
467 | |
4cbe63e7 |
468 | sub _is_struct { |
469 | my ($self, $val) = @_; |
470 | |
ce9e19dc |
471 | return $val =~ /^\s*(?:sub|[[{])/; |
4cbe63e7 |
472 | } |
473 | |
c34bcab6 |
474 | sub _quote { |
475 | my ($self, $val) = @_; |
476 | |
477 | return 'q{'.$val.'}'; |
478 | } |
479 | |
2201c2e4 |
480 | sub _quote_unless_struct { |
481 | my ($self, $val) = @_; |
482 | |
c34bcab6 |
483 | $val = $self->_quote($val) if not $self->_is_struct($val); |
2201c2e4 |
484 | |
c34bcab6 |
485 | return $val; |
2201c2e4 |
486 | } |
487 | |
5f9a34d7 |
488 | sub _eval { |
489 | my ($self, $code) = @_; |
490 | |
491 | return $code if looks_like_number $code; |
492 | |
97631b44 |
493 | return $code if not $self->_is_struct($code); |
5f9a34d7 |
494 | |
495 | return eval "{no strict; $code}"; |
496 | } |
497 | |
2201c2e4 |
498 | sub _gen_dynamic_schema { |
499 | my $self = shift; |
500 | |
501 | my $helper = $self->helper; |
502 | |
503 | my @schema_parts = split(/\:\:/, $self->schema_class); |
504 | my $schema_file_part = pop @schema_parts; |
505 | |
506 | my $schema_dir = File::Spec->catfile( |
507 | $helper->{base}, 'lib', @schema_parts |
508 | ); |
509 | my $schema_file = File::Spec->catfile( |
510 | $schema_dir, $schema_file_part . '.pm' |
511 | ); |
512 | |
513 | $helper->mk_dir($schema_dir); |
514 | $helper->render_file('schemaclass', $schema_file); |
515 | } |
516 | |
517 | sub _gen_static_schema { |
518 | my $self = shift; |
519 | |
c4fee9b8 |
520 | die "cannot load schema without connect info" unless $self->connect_info; |
2201c2e4 |
521 | |
522 | my $helper = $self->helper; |
523 | |
524 | my $schema_dir = File::Spec->catfile($helper->{base}, 'lib'); |
525 | |
f090a149 |
526 | eval { Class::MOP::load_class('DBIx::Class::Schema::Loader') }; |
c4fee9b8 |
527 | die "Cannot load DBIx::Class::Schema::Loader: $@" if $@; |
f090a149 |
528 | |
529 | DBIx::Class::Schema::Loader->import( |
2201c2e4 |
530 | "dump_to_dir:$schema_dir", 'make_schema_at' |
f090a149 |
531 | ); |
2201c2e4 |
532 | |
533 | make_schema_at( |
534 | $self->schema_class, |
535 | $self->loader_args, |
536 | [$self->connect_info] |
537 | ); |
538 | } |
539 | |
2201c2e4 |
540 | sub _gen_model { |
541 | my $self = shift; |
542 | my $helper = $self->helper; |
543 | |
544 | $helper->render_file('compclass', $helper->{file} ); |
ad91060a |
545 | } |
546 | |
c4fee9b8 |
547 | sub _print_dynamic_deprecation_warning { |
548 | warn <<EOF; |
549 | ************************************ WARNING ********************************** |
550 | * create=dynamic is DEPRECATED, please use create=static instead. * |
551 | ******************************************************************************* |
552 | EOF |
553 | print "Continue? [y/n]: "; |
554 | chomp(my $response = <STDIN>); |
555 | exit 0 if $response =~ /^n(o)?\z/; |
556 | } |
557 | |
558 | sub _cleanup_args { |
559 | my ($self, $args) = @_; |
560 | |
561 | # remove blanks, ie. someoned doing foo \ bar |
61ed82a5 |
562 | my @res = grep !/^\s+\z/, @$args; |
c4fee9b8 |
563 | |
564 | # remove leading whitespace, ie. foo \ bar |
565 | s/^\s*// for @res; |
566 | |
567 | @res |
568 | } |
569 | |
ad91060a |
570 | =head1 SEE ALSO |
571 | |
7b39f3f0 |
572 | General Catalyst Stuff: |
573 | |
ad91060a |
574 | L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>, |
7b39f3f0 |
575 | L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>, |
576 | |
577 | Stuff related to DBIC and this Model style: |
578 | |
579 | L<DBIx::Class>, L<DBIx::Class::Schema>, |
ef91bcf9 |
580 | L<DBIx::Class::Schema::Loader>, L<Catalyst::Model::DBIC::Schema> |
ad91060a |
581 | |
582 | =head1 AUTHOR |
583 | |
4e251d1a |
584 | See L<Catalyst::Model::DBIC::Schema/AUTHOR> and |
585 | L<Catalyst::Model::DBIC::Schema/CONTRIBUTORS>. |
ad91060a |
586 | |
4e251d1a |
587 | =head1 COPYRIGHT |
2ff00e2b |
588 | |
4e251d1a |
589 | See L<Catalyst::Model::DBIC::Schema/COPYRIGHT>. |
2ff00e2b |
590 | |
ad91060a |
591 | =head1 LICENSE |
592 | |
593 | This library is free software, you can redistribute it and/or modify |
594 | it under the same terms as Perl itself. |
595 | |
596 | =cut |
597 | |
dce0dfe8 |
598 | 1; |
599 | |
ad91060a |
600 | __DATA__ |
601 | |
5d11d759 |
602 | =begin pod_to_ignore |
603 | |
d89e6c8a |
604 | __schemaclass__ |
605 | package [% schema_class %]; |
606 | |
607 | use strict; |
608 | use base qw/DBIx::Class::Schema::Loader/; |
609 | |
610 | __PACKAGE__->loader_options( |
2201c2e4 |
611 | [%- FOREACH key = loader_args.keys %] |
612 | [% key %] => [% loader_args.${key} %], |
613 | [%- END -%] |
614 | |
d89e6c8a |
615 | ); |
616 | |
617 | =head1 NAME |
618 | |
2201c2e4 |
619 | [% schema_class %] - L<DBIx::Class::Schema::Loader> class |
d89e6c8a |
620 | |
621 | =head1 SYNOPSIS |
622 | |
623 | See L<[% app %]> |
624 | |
625 | =head1 DESCRIPTION |
626 | |
2201c2e4 |
627 | Dynamic L<DBIx::Class::Schema::Loader> schema for use in L<[% class %]> |
628 | |
629 | =head1 GENERATED BY |
630 | |
631 | [% generator %] - [% generator_version %] |
d89e6c8a |
632 | |
633 | =head1 AUTHOR |
634 | |
2201c2e4 |
635 | [% author.replace(',+$', '') %] |
d89e6c8a |
636 | |
637 | =head1 LICENSE |
638 | |
639 | This library is free software, you can redistribute it and/or modify |
640 | it under the same terms as Perl itself. |
641 | |
642 | =cut |
643 | |
644 | 1; |
645 | |
ad91060a |
646 | __compclass__ |
647 | package [% class %]; |
648 | |
649 | use strict; |
650 | use base 'Catalyst::Model::DBIC::Schema'; |
651 | |
652 | __PACKAGE__->config( |
0f2fd2c0 |
653 | schema_class => '[% schema_class %]', |
c34bcab6 |
654 | [% IF traits %]traits => [% traits %],[% END %] |
2201c2e4 |
655 | [% IF setup_connect_info %]connect_info => { |
656 | [%- FOREACH key = connect_info.keys %] |
657 | [% key %] => [% connect_info.${key} %], |
658 | [%- END -%] |
659 | |
660 | }[% END %] |
ad91060a |
661 | ); |
662 | |
663 | =head1 NAME |
664 | |
1aeb6e1e |
665 | [% class %] - Catalyst DBIC Schema Model |
2201c2e4 |
666 | |
ad91060a |
667 | =head1 SYNOPSIS |
668 | |
669 | See L<[% app %]> |
670 | |
671 | =head1 DESCRIPTION |
672 | |
d89e6c8a |
673 | L<Catalyst::Model::DBIC::Schema> Model using schema L<[% schema_class %]> |
ad91060a |
674 | |
2201c2e4 |
675 | =head1 GENERATED BY |
676 | |
677 | [% generator %] - [% generator_version %] |
678 | |
ad91060a |
679 | =head1 AUTHOR |
680 | |
2201c2e4 |
681 | [% author.replace(',+$', '') %] |
ad91060a |
682 | |
683 | =head1 LICENSE |
684 | |
685 | This library is free software, you can redistribute it and/or modify |
686 | it under the same terms as Perl itself. |
687 | |
688 | =cut |
689 | |
690 | 1; |
a75b6e58 |
691 | __END__ |
692 | # vim:sts=4 sw=4: |