我按照http://wiki.class-dbi.com/wiki/Overriding_autogenerated_accessors中的示例进行操作
我想在将 URL 插入数据库之前对其进行修改:
package Hosting::Company;
use base 'Class::DBI';
my $class = __PACKAGE__;
$class->table('Companies');
$class->columns(Primary => 'CompanyId');
$class->columns(Others => qw/Name Url Comment/);
sub Url {
my $self = shift;
# modify URL.
if (@_) {
$_[0] = 'aaaaaaaaaaaa';
# return $self->_Url_accessor('aaaaaaaaaaaa'); - doesn't work either
}
# Back to normal Class::DBI
return $self->_Url_accessor(@_);
}
但它不起作用:
my $company = Hosting::Company->insert({ Name => 'Test', Url => 'http://http://url' });
print $company->Url, "\n";
显示:
http://http://url
我希望 Class:DBI 邮件列表还活着!