如何整理 DBIx::Class::Schema::Loader 的输出?
目前,我们正在团队中引入 DBIx::Class
,我们希望从 DBIx::Class::Schema::Loader
开始。但是,我们对代码风格有严格的要求,即我们将 Perl::Tidy
作为我们 pre-commit
脚本的一部分,因为我们还没有生成任何代码之前的代码。现在,我们必须确保 Schema::Loader
生成的代码干净整洁。我们无法在提交之前对代码运行 perltidy
,因为它会破坏 DBIC 的 MD5 哈希。因此,将后处理器集成到 Schema::Loader 中将是我的首选,也可能是唯一可行的解决方案。但仍然:你会如何处理这个问题?
编辑我不妨修补DBIx::Class::Schema::Loader::Base
以使用perltidy
preprocess
参数(如果有)。
We are currently introducing DBIx::Class
in our team and we would like to start out with DBIx::Class::Schema::Loader
. However, we have hard requirements on code style, i.e. we've got Perl::Tidy
as part of our pre-commit
script, since we haven't had any generated code before. Now, we'd have to make sure that the code that Schema::Loader
generates is clean and tidy. We can't run perltidy
over the code before commit, since it screws up DBIC's MD5 hashing. So a post-processor integrated into Schema::Loader
would be my preferred and probably the only feasible solution. But still: how would you handle this problem?
EDIT I might as well patch DBIx::Class::Schema::Loader::Base
to use a perltidy
preprocess
parameter if it gets one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个问题是不久前提出的,但我今天必须处理这个问题,所以我想我会根据暂时对该模块所做的更改来分享我的解决方案。如果您扫描 PerlTidy 文档中的 --format-skipping,您会发现您可以向 PerlTidy 提供有关不应整理哪些代码的说明。开始和结束标记是 #<<<和#>>分别。所以,默认设置看起来像这样:
这很简单。现在您只需要让加载器用这些标记包装生成的代码即可。这可能看起来像这样:
重要的部分是
filter_ generated_code
,它允许您包装生成的代码。现在您可以生成模式文件并仍然 PerlTidy 它们。这将允许您整理在生成的文件底部添加的自定义代码,而不会遇到当生成的代码被 make_schema_at() 以外的其他内容更改时发生的错误。就我而言,我决定关闭
generate_pod
,因为 PerlTidy 仍然(出于某种原因)在生成的 Pod 中插入一些换行符。我还不太明白为什么会这样,但是关闭 Pod 就可以解决这个问题,没有它我也能生活。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:
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:
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.0.05000 已经发布(之前是开发版本),它添加了 overwrite_modifications 选项 rbuels。
我很快也会尝试添加 post_process 选项。
0.05000 has been released (previously the development version) it has the overwrite_modifications option rbuels added.
I will try to add a post_process option as well soon.
DBICSL 的开发版本现在有一个 overwrite_modifications 选项,您可以使用它来忽略代码的 md5summed 部分中的更改。这应该让您在提交之前对输出运行 perltidy,并且仍然能够稍后重新转储。
The development version of DBICSL now has an overwrite_modifications option you can use to ignore changes in the md5summed parts of the code. This should let you run perltidy on the output before committing it, and still be able to re-dump later.