Allow specifying a custom loader_class in loader_options
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / Base.pm
1 package DBIx::Class::Schema::Loader::Base;
2
3 use strict;
4 use warnings;
5 use base qw/Class::Accessor::Fast/;
6 use Class::C3;
7 use Carp::Clan qw/^DBIx::Class/;
8 use UNIVERSAL::require;
9 use DBIx::Class::Schema::Loader::RelBuilder;
10 use Data::Dump qw/ dump /;
11 use POSIX qw//;
12 use File::Spec qw//;
13 use Cwd qw//;
14 use Digest::MD5 qw//;
15 require DBIx::Class;
16
17 our $VERSION = '0.04999_04';
18
19 __PACKAGE__->mk_ro_accessors(qw/
20                                 schema
21                                 schema_class
22
23                                 exclude
24                                 constraint
25                                 additional_classes
26                                 additional_base_classes
27                                 left_base_classes
28                                 components
29                                 resultset_components
30                                 skip_relationships
31                                 moniker_map
32                                 inflect_singular
33                                 inflect_plural
34                                 debug
35                                 dump_directory
36                                 dump_overwrite
37                                 really_erase_my_files
38                                 use_namespaces
39                                 result_namespace
40                                 resultset_namespace
41                                 default_resultset_class
42
43                                 db_schema
44                                 _tables
45                                 classes
46                                 monikers
47                              /);
48
49 =head1 NAME
50
51 DBIx::Class::Schema::Loader::Base - Base DBIx::Class::Schema::Loader Implementation.
52
53 =head1 SYNOPSIS
54
55 See L<DBIx::Class::Schema::Loader>
56
57 =head1 DESCRIPTION
58
59 This is the base class for the storage-specific C<DBIx::Class::Schema::*>
60 classes, and implements the common functionality between them.
61
62 =head1 CONSTRUCTOR OPTIONS
63
64 These constructor options are the base options for
65 L<DBIx::Class::Schema::Loader/loader_opts>.  Available constructor options are:
66
67 =head2 loader_class
68
69 Use the specified class as the loader instead of
70 C<DBIx::Class::Schema::Loader${storage_type}>. This is mostly useful for
71 subclassing existing loaders or in conjunction with
72 L<DBIx::Class::Schema::Loader/dump_to_dir>.
73
74 =head2 skip_relationships
75
76 Skip setting up relationships.  The default is to attempt the loading
77 of relationships.
78
79 =head2 debug
80
81 If set to true, each constructive L<DBIx::Class> statement the loader
82 decides to execute will be C<warn>-ed before execution.
83
84 =head2 db_schema
85
86 Set the name of the schema to load (schema in the sense that your database
87 vendor means it).  Does not currently support loading more than one schema
88 name.
89
90 =head2 constraint
91
92 Only load tables matching regex.  Best specified as a qr// regex.
93
94 =head2 exclude
95
96 Exclude tables matching regex.  Best specified as a qr// regex.
97
98 =head2 moniker_map
99
100 Overrides the default table name to moniker translation.  Can be either
101 a hashref of table keys and moniker values, or a coderef for a translator
102 function taking a single scalar table name argument and returning
103 a scalar moniker.  If the hash entry does not exist, or the function
104 returns a false value, the code falls back to default behavior
105 for that table name.
106
107 The default behavior is: C<join '', map ucfirst, split /[\W_]+/, lc $table>,
108 which is to say: lowercase everything, split up the table name into chunks
109 anywhere a non-alpha-numeric character occurs, change the case of first letter
110 of each chunk to upper case, and put the chunks back together.  Examples:
111
112     Table Name  | Moniker Name
113     ---------------------------
114     luser       | Luser
115     luser_group | LuserGroup
116     luser-opts  | LuserOpts
117
118 =head2 inflect_plural
119
120 Just like L</moniker_map> above (can be hash/code-ref, falls back to default
121 if hash key does not exist or coderef returns false), but acts as a map
122 for pluralizing relationship names.  The default behavior is to utilize
123 L<Lingua::EN::Inflect::Number/to_PL>.
124
125 =head2 inflect_singular
126
127 As L</inflect_plural> above, but for singularizing relationship names.
128 Default behavior is to utilize L<Lingua::EN::Inflect::Number/to_S>.
129
130 =head2 additional_base_classes
131
132 List of additional base classes all of your table classes will use.
133
134 =head2 left_base_classes
135
136 List of additional base classes all of your table classes will use
137 that need to be leftmost.
138
139 =head2 additional_classes
140
141 List of additional classes which all of your table classes will use.
142
143 =head2 components
144
145 List of additional components to be loaded into all of your table
146 classes.  A good example would be C<ResultSetManager>.
147
148 =head2 resultset_components
149
150 List of additional ResultSet components to be loaded into your table
151 classes.  A good example would be C<AlwaysRS>.  Component
152 C<ResultSetManager> will be automatically added to the above
153 C<components> list if this option is set.
154
155 =head2 use_namespaces
156
157 Generate result class names suitable for
158 L<DBIx::Class::Schema/load_namespaces> and call that instead of
159 L<DBIx::Class::Schema/load_classes>. When using this option you can also
160 specify any of the options for C<load_namespaces> (i.e. C<result_namespace>,
161 C<resultset_namespace>, C<default_resultset_class>), and they will be added
162 to the call (and the generated result class names adjusted appropriately).
163
164 =head2 dump_directory
165
166 This option is designed to be a tool to help you transition from this
167 loader to a manually-defined schema when you decide it's time to do so.
168
169 The value of this option is a perl libdir pathname.  Within
170 that directory this module will create a baseline manual
171 L<DBIx::Class::Schema> module set, based on what it creates at runtime
172 in memory.
173
174 The created schema class will have the same classname as the one on
175 which you are setting this option (and the ResultSource classes will be
176 based on this name as well).
177
178 Normally you wouldn't hard-code this setting in your schema class, as it
179 is meant for one-time manual usage.
180
181 See L<DBIx::Class::Schema::Loader/dump_to_dir> for examples of the
182 recommended way to access this functionality.
183
184 =head2 dump_overwrite
185
186 Deprecated.  See L</really_erase_my_files> below, which does *not* mean
187 the same thing as the old C<dump_overwrite> setting from previous releases.
188
189 =head2 really_erase_my_files
190
191 Default false.  If true, Loader will unconditionally delete any existing
192 files before creating the new ones from scratch when dumping a schema to disk.
193
194 The default behavior is instead to only replace the top portion of the
195 file, up to and including the final stanza which contains
196 C<# DO NOT MODIFY THIS OR ANYTHING ABOVE!>
197 leaving any customizations you placed after that as they were.
198
199 When C<really_erase_my_files> is not set, if the output file already exists,
200 but the aforementioned final stanza is not found, or the checksum
201 contained there does not match the generated contents, Loader will
202 croak and not touch the file.
203
204 You should really be using version control on your schema classes (and all
205 of the rest of your code for that matter).  Don't blame me if a bug in this
206 code wipes something out when it shouldn't have, you've been warned.
207
208 =head1 METHODS
209
210 None of these methods are intended for direct invocation by regular
211 users of L<DBIx::Class::Schema::Loader>.  Anything you can find here
212 can also be found via standard L<DBIx::Class::Schema> methods somehow.
213
214 =cut
215
216 # ensure that a peice of object data is a valid arrayref, creating
217 # an empty one or encapsulating whatever's there.
218 sub _ensure_arrayref {
219     my $self = shift;
220
221     foreach (@_) {
222         $self->{$_} ||= [];
223         $self->{$_} = [ $self->{$_} ]
224             unless ref $self->{$_} eq 'ARRAY';
225     }
226 }
227
228 =head2 new
229
230 Constructor for L<DBIx::Class::Schema::Loader::Base>, used internally
231 by L<DBIx::Class::Schema::Loader>.
232
233 =cut
234
235 sub new {
236     my ( $class, %args ) = @_;
237
238     my $self = { %args };
239
240     bless $self => $class;
241
242     $self->_ensure_arrayref(qw/additional_classes
243                                additional_base_classes
244                                left_base_classes
245                                components
246                                resultset_components
247                               /);
248
249     push(@{$self->{components}}, 'ResultSetManager')
250         if @{$self->{resultset_components}};
251
252     $self->{monikers} = {};
253     $self->{classes} = {};
254
255     $self->{schema_class} ||= ( ref $self->{schema} || $self->{schema} );
256     $self->{schema} ||= $self->{schema_class};
257
258     croak "dump_overwrite is deprecated.  Please read the"
259         . " DBIx::Class::Schema::Loader::Base documentation"
260             if $self->{dump_overwrite};
261
262     $self->{relbuilder} = DBIx::Class::Schema::Loader::RelBuilder->new(
263         $self->schema_class, $self->inflect_plural, $self->inflect_singular
264     ) if !$self->{skip_relationships};
265
266     $self;
267 }
268
269 sub _find_file_in_inc {
270     my ($self, $file) = @_;
271
272     foreach my $prefix (@INC) {
273         my $fullpath = $prefix . '/' . $file;
274         return $fullpath if -f $fullpath;
275     }
276
277     return;
278 }
279
280 sub _load_external {
281     my ($self, $class) = @_;
282
283     my $class_path = $class;
284     $class_path =~ s{::}{/}g;
285     $class_path .= '.pm';
286
287     my $inc_path = $self->_find_file_in_inc($class_path);
288
289     return if !$inc_path;
290
291     my $real_dump_path = $self->dump_directory
292         ? Cwd::abs_path(
293               File::Spec->catfile($self->dump_directory, $class_path)
294           )
295         : '';
296     my $real_inc_path = Cwd::abs_path($inc_path);
297     return if $real_inc_path eq $real_dump_path;
298
299     $class->require;
300     croak "Failed to load external class definition"
301         . " for '$class': $@"
302             if $@;
303
304     # If we make it to here, we loaded an external definition
305     warn qq/# Loaded external class definition for '$class'\n/
306         if $self->debug;
307
308     # The rest is only relevant when dumping
309     return if !$self->dump_directory;
310
311     croak 'Failed to locate actual external module file for '
312           . "'$class'"
313               if !$real_inc_path;
314     open(my $fh, '<', $real_inc_path)
315         or croak "Failed to open '$real_inc_path' for reading: $!";
316     $self->_ext_stmt($class,
317         qq|# These lines were loaded from '$real_inc_path' found in \@INC.|
318         .q|# They are now part of the custom portion of this file|
319         .q|# for you to hand-edit.  If you do not either delete|
320         .q|# this section or remove that file from @INC, this section|
321         .q|# will be repeated redundantly when you re-create this|
322         .q|# file again via Loader!|
323     );
324     while(<$fh>) {
325         chomp;
326         $self->_ext_stmt($class, $_);
327     }
328     $self->_ext_stmt($class,
329         qq|# End of lines loaded from '$real_inc_path' |
330     );
331     close($fh)
332         or croak "Failed to close $real_inc_path: $!";
333 }
334
335 =head2 load
336
337 Does the actual schema-construction work.
338
339 =cut
340
341 sub load {
342     my $self = shift;
343
344     $self->_load_tables($self->_tables_list);
345 }
346
347 =head2 rescan
348
349 Arguments: schema
350
351 Rescan the database for newly added tables.  Does
352 not process drops or changes.  Returns a list of
353 the newly added table monikers.
354
355 The schema argument should be the schema class
356 or object to be affected.  It should probably
357 be derived from the original schema_class used
358 during L</load>.
359
360 =cut
361
362 sub rescan {
363     my ($self, $schema) = @_;
364
365     $self->{schema} = $schema;
366
367     my @created;
368     my @current = $self->_tables_list;
369     foreach my $table ($self->_tables_list) {
370         if(!exists $self->{_tables}->{$table}) {
371             push(@created, $table);
372         }
373     }
374
375     my $loaded = $self->_load_tables(@created);
376
377     return map { $self->monikers->{$_} } @$loaded;
378 }
379
380 sub _load_tables {
381     my ($self, @tables) = @_;
382
383     # First, use _tables_list with constraint and exclude
384     #  to get a list of tables to operate on
385
386     my $constraint   = $self->constraint;
387     my $exclude      = $self->exclude;
388
389     @tables = grep { /$constraint/ } @tables if $constraint;
390     @tables = grep { ! /$exclude/ } @tables if $exclude;
391
392     # Save the new tables to the tables list
393     foreach (@tables) {
394         $self->{_tables}->{$_} = 1;
395     }
396
397     # Set up classes/monikers
398     {
399         no warnings 'redefine';
400         local *Class::C3::reinitialize = sub { };
401         use warnings;
402
403         $self->_make_src_class($_) for @tables;
404     }
405
406     Class::C3::reinitialize;
407
408     $self->_setup_src_meta($_) for @tables;
409
410     if(!$self->skip_relationships) {
411         $self->_load_relationships($_) for @tables;
412     }
413
414     $self->_load_external($_)
415         for map { $self->classes->{$_} } @tables;
416
417     $self->_dump_to_dir if $self->dump_directory;
418
419     # Drop temporary cache
420     delete $self->{_cache};
421
422     return \@tables;
423 }
424
425 sub _get_dump_filename {
426     my ($self, $class) = (@_);
427
428     $class =~ s{::}{/}g;
429     return $self->dump_directory . q{/} . $class . q{.pm};
430 }
431
432 sub _ensure_dump_subdirs {
433     my ($self, $class) = (@_);
434
435     my @name_parts = split(/::/, $class);
436     pop @name_parts; # we don't care about the very last element,
437                      # which is a filename
438
439     my $dir = $self->dump_directory;
440     while (1) {
441         if(!-d $dir) {
442             mkdir($dir) or croak "mkdir('$dir') failed: $!";
443         }
444         last if !@name_parts;
445         $dir = File::Spec->catdir($dir, shift @name_parts);
446     }
447 }
448
449 sub _dump_to_dir {
450     my ($self) = @_;
451
452     my $target_dir = $self->dump_directory;
453
454     my $schema_class = $self->schema_class;
455
456     croak "Must specify target directory for dumping!" if ! $target_dir;
457
458     warn "Dumping manual schema for $schema_class to directory $target_dir ...\n";
459
460     my $schema_text =
461           qq|package $schema_class;\n\n|
462         . qq|use strict;\nuse warnings;\n\n|
463         . qq|use base 'DBIx::Class::Schema';\n\n|;
464
465     
466     if ($self->use_namespaces) {
467         $schema_text .= qq|__PACKAGE__->load_namespaces|;
468         my $namespace_options;
469         for my $attr (qw(result_namespace
470                          resultset_namespace
471                          default_resultset_class)) {
472             if ($self->$attr) {
473                 $namespace_options .= qq|    $attr => '| . $self->$attr . qq|',\n|
474             }
475         }
476         $schema_text .= qq|(\n$namespace_options)| if $namespace_options;
477         $schema_text .= qq|;\n|;
478     }
479     else {
480         $schema_text .= qq|__PACKAGE__->load_classes;\n|;
481
482     }
483
484     $self->_write_classfile($schema_class, $schema_text);
485
486     foreach my $src_class (sort keys %{$self->{_dump_storage}}) {
487         my $src_text = 
488               qq|package $src_class;\n\n|
489             . qq|use strict;\nuse warnings;\n\n|
490             . qq|use base 'DBIx::Class';\n\n|;
491
492         $self->_write_classfile($src_class, $src_text);
493     }
494
495     warn "Schema dump completed.\n";
496 }
497
498 sub _write_classfile {
499     my ($self, $class, $text) = @_;
500
501     my $filename = $self->_get_dump_filename($class);
502     $self->_ensure_dump_subdirs($class);
503
504     if (-f $filename && $self->really_erase_my_files) {
505         warn "Deleting existing file '$filename' due to "
506             . "'really_erase_my_files' setting\n";
507         unlink($filename);
508     }    
509
510     my $custom_content = $self->_get_custom_content($class, $filename);
511
512     $custom_content ||= qq|\n\n# You can replace this text with custom|
513         . qq| content, and it will be preserved on regeneration|
514         . qq|\n1;\n|;
515
516     $text .= qq|$_\n|
517         for @{$self->{_dump_storage}->{$class} || []};
518
519     $text .= qq|\n\n# Created by DBIx::Class::Schema::Loader|
520         . qq| v| . $DBIx::Class::Schema::Loader::VERSION
521         . q| @ | . POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime)
522         . qq|\n# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:|;
523
524     open(my $fh, '>', $filename)
525         or croak "Cannot open '$filename' for writing: $!";
526
527     # Write the top half and its MD5 sum
528     print $fh $text . Digest::MD5::md5_base64($text) . "\n";
529
530     # Write out anything loaded via external partial class file in @INC
531     print $fh qq|$_\n|
532         for @{$self->{_ext_storage}->{$class} || []};
533
534     print $fh $custom_content;
535
536     close($fh)
537         or croak "Cannot close '$filename': $!";
538 }
539
540 sub _get_custom_content {
541     my ($self, $class, $filename) = @_;
542
543     return if ! -f $filename;
544     open(my $fh, '<', $filename)
545         or croak "Cannot open '$filename' for reading: $!";
546
547     my $mark_re = 
548         qr{^(# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:)([A-Za-z0-9/+]{22})\n};
549
550     my $found = 0;
551     my $buffer = '';
552     while(<$fh>) {
553         if(!$found && /$mark_re/) {
554             $found = 1;
555             $buffer .= $1;
556             croak "Checksum mismatch in '$filename'"
557                 if Digest::MD5::md5_base64($buffer) ne $2;
558
559             $buffer = '';
560         }
561         else {
562             $buffer .= $_;
563         }
564     }
565
566     croak "Cannot not overwrite '$filename' without 'really_erase_my_files',"
567         . " it does not appear to have been generated by Loader"
568             if !$found;
569
570     return $buffer;
571 }
572
573 sub _use {
574     my $self = shift;
575     my $target = shift;
576     my $evalstr;
577
578     foreach (@_) {
579         warn "$target: use $_;" if $self->debug;
580         $self->_raw_stmt($target, "use $_;");
581         $_->require or croak ($_ . "->require: $@");
582         $evalstr .= "package $target; use $_;";
583     }
584     eval $evalstr if $evalstr;
585     croak $@ if $@;
586 }
587
588 sub _inject {
589     my $self = shift;
590     my $target = shift;
591     my $schema_class = $self->schema_class;
592
593     my $blist = join(q{ }, @_);
594     warn "$target: use base qw/ $blist /;" if $self->debug && @_;
595     $self->_raw_stmt($target, "use base qw/ $blist /;") if @_;
596     foreach (@_) {
597         $_->require or croak ($_ . "->require: $@");
598         $schema_class->inject_base($target, $_);
599     }
600 }
601
602 # Create class with applicable bases, setup monikers, etc
603 sub _make_src_class {
604     my ($self, $table) = @_;
605
606     my $schema       = $self->schema;
607     my $schema_class = $self->schema_class;
608
609     my $table_moniker = $self->_table2moniker($table);
610     my @result_namespace = ($schema_class);
611     if ($self->use_namespaces) {
612         my $result_namespace = $self->result_namespace || 'Result';
613         if ($result_namespace =~ /^\+(.*)/) {
614             # Fully qualified namespace
615             @result_namespace =  ($1)
616         }
617         else {
618             # Relative namespace
619             push @result_namespace, $result_namespace;
620         }
621     }
622     my $table_class = join(q{::}, @result_namespace, $table_moniker);
623
624     my $table_normalized = lc $table;
625     $self->classes->{$table} = $table_class;
626     $self->classes->{$table_normalized} = $table_class;
627     $self->monikers->{$table} = $table_moniker;
628     $self->monikers->{$table_normalized} = $table_moniker;
629
630     { no strict 'refs'; @{"${table_class}::ISA"} = qw/DBIx::Class/ }
631
632     $self->_use   ($table_class, @{$self->additional_classes});
633     $self->_inject($table_class, @{$self->additional_base_classes});
634
635     $self->_dbic_stmt($table_class, 'load_components', @{$self->components}, 'Core');
636
637     $self->_dbic_stmt($table_class, 'load_resultset_components', @{$self->resultset_components})
638         if @{$self->resultset_components};
639     $self->_inject($table_class, @{$self->left_base_classes});
640 }
641
642 # Set up metadata (cols, pks, etc) and register the class with the schema
643 sub _setup_src_meta {
644     my ($self, $table) = @_;
645
646     my $schema       = $self->schema;
647     my $schema_class = $self->schema_class;
648
649     my $table_class = $self->classes->{$table};
650     my $table_moniker = $self->monikers->{$table};
651
652     $self->_dbic_stmt($table_class,'table',$table);
653
654     my $cols = $self->_table_columns($table);
655     my $col_info;
656     eval { $col_info = $self->_columns_info_for($table) };
657     if($@) {
658         $self->_dbic_stmt($table_class,'add_columns',@$cols);
659     }
660     else {
661         my %col_info_lc = map { lc($_), $col_info->{$_} } keys %$col_info;
662         my $fks = $self->_table_fk_info($table);
663         for my $fkdef (@$fks) {
664             for my $col (@{ $fkdef->{local_columns} }) {
665                 $col_info_lc{$col}->{is_foreign_key} = 1;
666             }
667         }
668         $self->_dbic_stmt(
669             $table_class,
670             'add_columns',
671             map { $_, ($col_info_lc{$_}||{}) } @$cols
672         );
673     }
674
675     my $pks = $self->_table_pk_info($table) || [];
676     @$pks ? $self->_dbic_stmt($table_class,'set_primary_key',@$pks)
677           : carp("$table has no primary key");
678
679     my $uniqs = $self->_table_uniq_info($table) || [];
680     $self->_dbic_stmt($table_class,'add_unique_constraint',@$_) for (@$uniqs);
681
682     $schema_class->register_class($table_moniker, $table_class);
683     $schema->register_class($table_moniker, $table_class) if $schema ne $schema_class;
684 }
685
686 =head2 tables
687
688 Returns a sorted list of loaded tables, using the original database table
689 names.
690
691 =cut
692
693 sub tables {
694     my $self = shift;
695
696     return keys %{$self->_tables};
697 }
698
699 # Make a moniker from a table
700 sub _table2moniker {
701     my ( $self, $table ) = @_;
702
703     my $moniker;
704
705     if( ref $self->moniker_map eq 'HASH' ) {
706         $moniker = $self->moniker_map->{$table};
707     }
708     elsif( ref $self->moniker_map eq 'CODE' ) {
709         $moniker = $self->moniker_map->($table);
710     }
711
712     $moniker ||= join '', map ucfirst, split /[\W_]+/, lc $table;
713
714     return $moniker;
715 }
716
717 sub _load_relationships {
718     my ($self, $table) = @_;
719
720     my $tbl_fk_info = $self->_table_fk_info($table);
721     foreach my $fkdef (@$tbl_fk_info) {
722         $fkdef->{remote_source} =
723             $self->monikers->{delete $fkdef->{remote_table}};
724     }
725     my $tbl_uniq_info = $self->_table_uniq_info($table);
726
727     my $local_moniker = $self->monikers->{$table};
728     my $rel_stmts = $self->{relbuilder}->generate_code($local_moniker, $tbl_fk_info, $tbl_uniq_info);
729
730     foreach my $src_class (sort keys %$rel_stmts) {
731         my $src_stmts = $rel_stmts->{$src_class};
732         foreach my $stmt (@$src_stmts) {
733             $self->_dbic_stmt($src_class,$stmt->{method},@{$stmt->{args}});
734         }
735     }
736 }
737
738 # Overload these in driver class:
739
740 # Returns an arrayref of column names
741 sub _table_columns { croak "ABSTRACT METHOD" }
742
743 # Returns arrayref of pk col names
744 sub _table_pk_info { croak "ABSTRACT METHOD" }
745
746 # Returns an arrayref of uniqs [ [ foo => [ col1, col2 ] ], [ bar => [ ... ] ] ]
747 sub _table_uniq_info { croak "ABSTRACT METHOD" }
748
749 # Returns an arrayref of foreign key constraints, each
750 #   being a hashref with 3 keys:
751 #   local_columns (arrayref), remote_columns (arrayref), remote_table
752 sub _table_fk_info { croak "ABSTRACT METHOD" }
753
754 # Returns an array of lower case table names
755 sub _tables_list { croak "ABSTRACT METHOD" }
756
757 # Execute a constructive DBIC class method, with debug/dump_to_dir hooks.
758 sub _dbic_stmt {
759     my $self = shift;
760     my $class = shift;
761     my $method = shift;
762
763     if(!$self->debug && !$self->dump_directory) {
764         $class->$method(@_);
765         return;
766     }
767
768     my $args = dump(@_);
769     $args = '(' . $args . ')' if @_ < 2;
770     my $stmt = $method . $args . q{;};
771
772     warn qq|$class\->$stmt\n| if $self->debug;
773     $class->$method(@_);
774     $self->_raw_stmt($class, '__PACKAGE__->' . $stmt);
775 }
776
777 # Store a raw source line for a class (for dumping purposes)
778 sub _raw_stmt {
779     my ($self, $class, $stmt) = @_;
780     push(@{$self->{_dump_storage}->{$class}}, $stmt) if $self->dump_directory;
781 }
782
783 # Like above, but separately for the externally loaded stuff
784 sub _ext_stmt {
785     my ($self, $class, $stmt) = @_;
786     push(@{$self->{_ext_storage}->{$class}}, $stmt) if $self->dump_directory;
787 }
788
789 =head2 monikers
790
791 Returns a hashref of loaded table to moniker mappings.  There will
792 be two entries for each table, the original name and the "normalized"
793 name, in the case that the two are different (such as databases
794 that like uppercase table names, or preserve your original mixed-case
795 definitions, or what-have-you).
796
797 =head2 classes
798
799 Returns a hashref of table to class mappings.  In some cases it will
800 contain multiple entries per table for the original and normalized table
801 names, as above in L</monikers>.
802
803 =head1 SEE ALSO
804
805 L<DBIx::Class::Schema::Loader>
806
807 =cut
808
809 1;