这个问题是前段时间提出的,但我今天不得不处理这个问题,所以我想我会根据暂时对该模块所做的更改来分享我的解决方案。如果你扫描 PerlTidy 文档中的 --format-skipping,你会发现你可以给 PerlTidy 说明哪些代码不应该被整理。开始和结束标记分别是#<<< 和#>>>。因此,默认设置如下所示:
# tidy my code
my $foo = 'bar';
#<<<
# don't tidy the code below
my $baz = 'foo';
# start to tidy again
#>>>
$foo .= 'stuff';
这很容易。现在您只需要让 Loader 使用这些标记包装生成的代码。这可能看起来像这样:
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] );
重要的部分是filter_generated_code
,它允许您包装生成的代码。现在你可以生成你的模式文件并且仍然对它们进行 PerlTidy。这将允许您整理在生成文件底部添加的自定义代码,而不会遇到生成的代码被 make_schema_at() 以外的其他东西更改时发生的错误。
就我而言,我决定关闭generate_pod
,因为 PerlTidy 仍然(出于某种原因)在生成的 Pod 中插入一些换行符。我还没有完全弄清楚为什么会这样,但是关闭 Pod 可以修复它,没有它我也可以生活。