This question was asked a while ago, but I had to deal with this today, so I thought I'd share my solution, based on the changes made to this module in the time being. If you scan the PerlTidy docs for --format-skipping, you'll see that you can give PerlTidy instructions about which code should not be tidied. The start and end markers are #<<< and #>>> respectively. So, the default settings would look something like this:
# tidy my code
my $foo = 'bar';
#<<<
# don't tidy the code below
my $baz = 'foo';
# start to tidy again
#>>>
$foo .= 'stuff';
That's easy enough. Now you just need to have the Loader wrap the generated code with these markers. That could look something like this:
my %args = (
components => [ 'InflateColumn::DateTime', 'TimeStamp' ],
debug => 1,
dump_directory => './lib',
filter_generated_code => sub {
my ( $type, $class, $text ) = @_;
return "#<<<\n$text#>>>";
},
generate_pod => 0,
naming => 'current',
overwrite_modifications => 0,
skip_load_external => 1,
use_moose => 1,
use_namespaces => 1,
);
make_schema_at( 'My::Schema', \%args, [$dsn, $user, $pass] );
The important part is filter_generated_code
, which allows you to wrap the generated code. Now you can generate your schema files and still PerlTidy them. This will allow you to tidy the custom code you add at the bottom of the generated files without running into the errors which happen when the generated code gets altered by something other than make_schema_at().
In my case, I decided to turn off generate_pod
, because PerlTidy was still (for some reason) inserting some newlines into the generated Pod. I haven't quite figured out why that is, but turning off the Pod fixes it and I can live without it.