perl – 更改DBIx类结果类的继承树?
天儿真好,
我正在使用DBIx :: Class 0.07003和DBIx :: Class :: Schema :: Loader 0.03009,我正在尝试更改Loader生成的类的基类 – 来自: package S2S::DBIxperiment::Productions; # Created by DBIx::Class::Schema::Loader v0.03009 @ 2011-06-24 14:29:13 use base 'DBIx::Class'; __PACKAGE__->load_components("PK::Auto","Core"); 类似于: package S2S::DBIxperiment::Productions; # Created by DBIx::Class::Schema::Loader v0.03009 @ 2011-06-24 14:29:13 use base 'BaseMooseDBI'; __PACKAGE__->load_components("PK::Auto","Core"); BaseMooseDBI的位置如下: package BaseMooseDBI; use Moose; use base qw(DBIx::Class); 但是,这似乎根本不起作用,它似乎没有从BaseMooseDBI包继承东西(属性等)我尝试覆盖BaseMooseDBI中的load_components,但它永远不会被调用 – 而是它错误,它不能找到load_components? 什么似乎是问题? 注意:生成结果类时,我不能使用较新的use_moose和result_base_class. 编辑:找到解决方案.看看DBIx :: Class :: Schema :: Loader现在如何做,具有Mutable和Immutable结果类. 解决方法
如果您只想向父类添加一些方法等,那么您的代码应该可以正常工作.您可能需要使用MooseX :: NonMoose,并且在过去我使用了父子类DBIx :: Class :: Core而不是DBIx :: Class.这是我成功使用的:
# Parent package App::Schema::Result; use Moose; use MooseX::NonMoose; use namespace::autoclean; extends 'DBIx::Class::Core'; sub parent_method { ... } # Child package App::Schema::Result::Product; use Moose; use MooseX::NonMoose; use namespace::autoclean; extends 'Keystone::Schema::Site::Result'; __PACKAGE__->table('products'); sub child_method { my ($self) = @_; $self->parent_method(); } 如果您希望父类定义DBIx :: Class特定信息(即调用__PACKAGE-> table,__PACKAGE __-> add_columns等),请查看DBIx :: Class :: Helper :: Row :: SubClass.使用它,您可以像普通的DBIx :: Class :: Result :: *一样定义父类,并在子类中使用SubClass组件并调用子类: # Parent package App::Schema::Result::Parent; use Moose; use MooseX::NonMoose; extends 'DBIx::Class'; __PACKAGE__->load_components(qw{InflateColumn::DateTime Core}); __PACKAGE__->table('products'); ... # Child package App::Schema::Result::Child; use Moose; use MooseX::NonMoose; extends 'App::Schema::Result::Parent'; __PACKAGE__->load_components(qw{Helper::Row::SubClass Core}); __PACKAGE__->subclass; # Now add the child specific stuff / override parent stuff 我不确定你是否可以让Loader自动生成一些代码. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |