adds the ability to filter generated code
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / Base.pm
index a576c71..2a67684 100644 (file)
@@ -77,6 +77,8 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/
                                 class_to_table
                                 uniq_to_primary
                                 quiet
+
+                                filter_generated_text
 /);
 
 
@@ -264,7 +266,7 @@ L</really_erase_my_files>.)
 By default POD will be generated for columns and relationships, using database
 metadata for the text if available and supported.
 
-Metadata can be stored in two ways.
+Comment metadata can be stored in two ways.
 
 The first is that you can create two tables named C<table_comments> and
 C<column_comments> respectively.  They both need to have columns named
@@ -275,12 +277,13 @@ source of metadata about tables and comments.
 (If you wish you can change the name of these tables with the parameters
 L</table_comments_table> and L</column_comments_table>.)
 
-As a fallback you can use built-in commenting mechanisms.  Currently this
-is only supported for PostgreSQL and MySQL.  To create comments in
-PostgreSQL you add statements of the form C<COMMENT ON TABLE some_table ...>.
-To create comments in MySQL you add C<COMMENT '...'> to the end of the
-column or table definition.  Note that MySQL restricts the length of comments,
-and also does not handle complex Unicode characters properly.
+As a fallback you can use built-in commenting mechanisms.  Currently this is
+only supported for PostgreSQL, Oracle and MySQL.  To create comments in
+PostgreSQL you add statements of the form C<COMMENT ON TABLE some_table IS
+'...'>, the same syntax is used in Oracle. To create comments in MySQL you add
+C<COMMENT '...'> to the end of the column or table definition.  Note that MySQL
+restricts the length of comments, and also does not handle complex Unicode
+characters properly.
 
 Set this to C<0> to turn off all POD generation.
 
@@ -681,6 +684,21 @@ Automatically promotes the largest unique constraints with non-nullable columns
 on tables to primary keys, assuming there is only one largest unique
 constraint.
 
+=head2 filter_generated_text
+
+An optional hook that lets you filter the generated text for various classes through
+a function that change it in any way that you want.  The function will receive the class
+and text, and returns the new text to use instead.  For instance you could add
+custom comment, run C<perltidy>, or do anything else that you want.
+
+If this exists but fails to return text matching C</package/>, no file will be generated.
+
+    filter_generated_base => sub {
+        my ($class, $text) = @_;
+       ...
+       return $new_text;
+    }
+
 =head1 METHODS
 
 None of these methods are intended for direct invocation by regular
@@ -1654,7 +1672,15 @@ sub _write_classfile {
     $text .= qq|$_\n|
         for @{$self->{_dump_storage}->{$class} || []};
 
-    # Check and see if the dump is infact differnt
+    if ($self->{filter_generated_text}) {
+        $text = $self->{filter_generated_text}->($class, $text);
+       if (not $text or not $text =~ /package/) {
+           warn("$class skipped due to filter") if $self->debug;
+           return;
+       }
+    }
+
+    # Check and see if the dump is in fact different
 
     my $compare_to;
     if ($old_md5) {