Add option to allow extra columns in many_to_many link tables
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / Base.pm
index 0b22a09..3cd33f1 100644 (file)
@@ -20,12 +20,12 @@ use File::Temp ();
 use Class::Unload;
 use Class::Inspector ();
 use Scalar::Util 'looks_like_number';
-use DBIx::Class::Schema::Loader::Utils qw/split_name dumper_squashed eval_package_without_redefine_warnings class_path slurp_file sigwarn_silencer/;
+use DBIx::Class::Schema::Loader::Utils qw/split_name dumper_squashed eval_package_without_redefine_warnings class_path slurp_file sigwarn_silencer firstidx uniq/;
 use DBIx::Class::Schema::Loader::Optional::Dependencies ();
 use Try::Tiny;
 use DBIx::Class ();
 use Encode qw/encode decode/;
-use List::MoreUtils qw/all any firstidx uniq/;
+use List::Util qw/all any none/;
 use File::Temp 'tempfile';
 use namespace::clean;
 
@@ -84,6 +84,7 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/
                                 moniker_to_table
                                 uniq_to_primary
                                 quiet
+                                allow_extra_m2m_cols
 /);
 
 
@@ -993,6 +994,13 @@ Automatically promotes the largest unique constraints with non-nullable columns
 on tables to primary keys, assuming there is only one largest unique
 constraint.
 
+=head2 allow_extra_m2m_cols
+
+Generate C<many_to_many> relationship bridges even if the link table has
+extra columns other than the foreign keys.  The primary key must still
+equal the union of the foreign keys.
+
+
 =head2 filter_generated_code
 
 An optional hook that lets you filter the generated text for various classes
@@ -1009,8 +1017,19 @@ be generated.
 
     filter_generated_code => sub {
         my ($type, $class, $text) = @_;
-       ...
-       return $new_code;
+        ...
+        return $new_code;
+    }
+
+You can also use this option to set L<perltidy markers|perltidy/Skipping
+Selected Sections of Code> in your generated classes.  This will leave
+the generated code in the default format, but will allow you to tidy
+your classes at any point in future, without worrying about changing the
+portions of the file which are checksummed, since C<perltidy> will just
+ignore all text between the markers.
+
+    filter_generated_code => sub {
+        return "#<<<\n$_[2]\n#>>>";
     }
 
 =head1 METHODS
@@ -1272,7 +1291,7 @@ sub new {
         if (ref $self->moniker_parts ne 'ARRAY') {
             croak 'moniker_parts must be an arrayref';
         }
-        if ((firstidx { $_ eq 'name' } @{ $self->moniker_parts }) == -1) {
+        if (none { $_ eq 'name' } @{ $self->moniker_parts }) {
             croak "moniker_parts option *must* contain 'name'";
         }
     }
@@ -2143,10 +2162,10 @@ sub _write_classfile {
                 croak "filter '$filter' exited non-zero: $exit_code";
             }
         }
-       if (not $text or not $text =~ /\bpackage\b/) {
-           warn("$class skipped due to filter") if $self->debug;
-           return;
-       }
+        if (not $text or not $text =~ /\bpackage\b/) {
+            warn("$class skipped due to filter") if $self->debug;
+            return;
+        }
     }
 
     # Check and see if the dump is in fact different