How can I clean DBIx :: Class :: Schema :: Loader output?

We currently represent DBIx::Class on our team, and we would like to start with DBIx::Class::Schema::Loader . However, we have strict requirements for the style of the code, i.e. We got Perl::Tidy as part of our pre-commit script since we didn’t have any generated code before. Now we need to make sure that the code generated by Schema::Loader is clean and tidy. We cannot run perltidy by code before committing, since it twists the DBIC MD5 hash. Therefore, the postprocessor integrated into Schema::Loader would be my preferred and probably the only possible solution. But still: how would you deal with this problem?

EDIT I could also install the DBIx::Class::Schema::Loader::Base patch to use the perltidy preprocess parameter if it receives it.

+7
perl dbix-class
source share
3 answers

0.05000 was released (earlier version for development), the rbels parameter was added in it, the overwrite_modifications parameter was added.

I will try to add the post_process parameter as well soon.

+3
source share

The DBICSL development version now has an overwrite_modifications option that you can use to ignore changes in parts of the md5summed code. This should allow you to run perltidy on exit before committing it, and still be able to reload later.

+3
source share

This question was asked some time ago, but I had to deal with it today, so I decided to share my solution based on the changes made to this module at the moment. If you scan PerlTidy documents for -format-skipping, you will see that you can give PerlTidy instructions about which code should not be used. Start and end markers indicate # <<<and # →>, respectively. Thus, the default settings 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'; 

It is easy enough. Now you just need Loader to wrap the generated code with these markers. It might 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 generate the generated code. Now you can generate your schema files and still use PerlTidy. This will allow you to arrange the custom code that you add at the bottom of the generated files without triggering errors that occur when the generated code is changed by something other than make_schema_at ().

In my case, I decided to disable generate_pod because PerlTidy still (for some reason) inserted some newlines into the created Pod. I do not quite understand why this is so, but disabling Pod fixes it, and I can live without it.

+1
source share

All Articles