In addition, sub classes inherited the accessors that generated in their parent classes. In the following example, an instance of class Foo can use the accessors of 'name' only. But that of class Foo::Var can use the accessors of 'name' and 'birthday'.
package Foo;
use base qw( Class::Accessor::Fast );
__PACKAGE__->mk_accessors( qw( name ) );
package Foo::Var;
use base qw/ Foo /;
__PACKAGE__->mk_accessors( qw( birthday ) );
If this is the case, you can use following accessors.
* getter
$self->get('KEY'), $self->KEY
* setter
$self->set('KEY', 'something new')
But you must use only get_KEY or set_KEY (like recommended in 'Perl Best Practices') if you added the following constraint.
__PACKAGE__->follow_best_practice;
This constraint is continued in the sub classes if you added in the parent classes.
You need to write this above 'mk_accessors' to get it to work properly.

0 件のコメント:
コメントを投稿