使用 DBIx::Class 我试图在更新或检索列的数据时对其进行操作。例如,在它进入数据库之前我想对其进行加密,并且每当它被访问时我想对其进行解密。我正在遵循这个例子DBIx::类::手册::食谱 https://metacpan.org/module/DBIx::Class::Manual::Cookbook#Wrapping-overloading-a-column-accessor,但是我似乎无法让它工作。我已将以下内容放入我的用户架构中。为了进行测试,我只是使用名称列,我知道它没有意义:
__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;
}
我看不出我所做的与食谱上所说的有什么不同。没有人能帮助我理解我做错了什么吗?谢谢!
DBIx::Class 有一个组件,称为过滤列 https://metacpan.org/module/DBIx%3a%3aClass%3a%3aFilterColumn.
CPAN 上有各种使用该组件的模块,例如DBIx::类::编码列 https://metacpan.org/module/DBIx%3a%3aClass%3a%3aEncodedColumn and 密码列 https://metacpan.org/module/DBIx%3a%3aClass%3a%3aPassphraseColumn.
如果您告诉我们您的用例是什么,我们可能会给您更多/更好的建议。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)