对于任何给定的结果类MySchema :: Result :: Foo(从默认模式加载器生成的语法构建,使用Moose/MooseX :: nonmoose)
如果我添加一个BUILDARGS方法包装来清理行的构造函数数据,如下所示:
package MySchema::Result::Foo;
use Moose;
use MooseX::NonMoose;
[etc ..]
around 'BUILDARGS' => sub {
my $orig = shift;
my $class = shift;
delete $_[0]->{not_a_real_column};
return $class->$orig(@_);
};
Run Code Online (Sandbox Code Playgroud)
它直接使用架构时有效.例如,以下按预期工作:创建一个新的行对象,使用real_column =>'value'并删除not_a_real_column - > new
use MySchema;
my $s = MySchema->connect('dbi:blahblahblah');
$s->resultset('Foo')->new({ real_column=>'value', not_a_real_column=>'some other thing' }); #win
Run Code Online (Sandbox Code Playgroud)
但是,当通过Catalyst :: Model :: DBIC :: Schema使用相同的模式时,顺序是不同的.尝试创建新的Foo行对象时,以下操作失败,因为not_a_real_column无效.换句话说,在调用new之前,new的参数不会通过BUILDARGS运行.
$c->model('MySchemaModel')->resultset('Foo')->new({ real_column=>'value', not_a_real_column=>'some other thing' }); #fails
Run Code Online (Sandbox Code Playgroud)
有趣的是,如果我绕过'new'=> sub {}而不是'BUILDARGS'=> sub {},两种情况下的行为是相同的,并且工作正常,但据我所知,Moose教条声明永远不会弄乱新.
任何人都在关心帮助我理解为什么会这样,或者是否有更好的方法?
JSON-LD 内容中的字符串值是否应该转义?例如,Google 建议使用以下内容为站点搜索提供提示:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"url": "https://www.example-petstore.com/",
"potentialAction": {
"@type": "SearchAction",
"target": "https://query.example-petstore.com/search?q={search_term_string}",
"query-input": "required name=search_term_string"
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
但是,如果我网站的搜索 URL 包含多个查询参数怎么办?是否应该或可以转义目标值中的字符?例如:
"target": "https://query.example-petstore.com/search?foo=bar\u0026q={search_term_string}",
Run Code Online (Sandbox Code Playgroud)
在 JSON-LD 中进行标记时,同样的问题适用于几种常见的 schema.org 类型。Organization->sameAs 中的 Google+ 社交个人资料链接,例如:如果我的组织的个人资料是
https://plus.google.com/+BeardsAreSweet
Run Code Online (Sandbox Code Playgroud)
应该表示为:
"sameAs": ["https://plus.google.com/+BeardsAreSweet"]
Run Code Online (Sandbox Code Playgroud)
或者
"sameAs": ["https://plus.google.com/\u002bBeardsAreSweet"]
Run Code Online (Sandbox Code Playgroud)
更重要的是,这真的重要吗?