【发布时间】:2012-07-16 15:21:43
【问题描述】:
使用 DBIx::Class 我试图在更新或检索列的数据时对其进行操作。例如,在它进入数据库之前,我想对其进行加密,而每当它被访问时,我想对其进行解密。我在DBIx::Class::Manual::Cookbook 中关注这个例子,但是我似乎无法让它工作。我在我的用户模式中放置了以下内容。对于测试我只是使用名称列,我知道这没有意义:
__PACKAGE__->add_columns("name" => { accessor => '_name' });
sub name {
my $self = shift;
# If there is an update to the column, we'll let the original accessor
# deal with it.
if(@_) {
return $self->_name('test 1');
}
# Fetch the column value.
my $name = $self->_name;
$name = 'test 2';
return $name;
}
我看不出我在做什么与食谱上说的有什么不同。谁能帮助我理解我做错了什么?谢谢!
【问题讨论】:
-
它的功能就像我的名字功能不存在一样。
-
您能否向我们展示一下无法正常工作的代码的 sn-p、您期望它返回什么以及它实际返回什么?
-
我已经在我的环境中测试了该代码并且它按预期工作,所以我认为问题可能出在其他地方。如果您发布您用来测试的代码,或许还有定义
name()的整个包,我们应该能够提供帮助。
标签: perl accessor catalyst dbix-class