0

使用角色的改进(Moo::Role 或 Role::Tiny 或其他)

with qw(
    Some::Role
    Some::Other::Role
);
...
some_roles_method();

仅从 mixin 类显式导入函数

use Some::Role qw/some_roles_method/;
...
some_roles_method();

数量众多,包括增加的灵活性、更少的簿记(尤其是在导入大量方法的情况下)以及不覆盖现有方法。

但是一个很大的缺点是,如果您正在阅读代码并遇到提及some_roles_method()并且想要阅读该函数,则不会立即知道该去哪里。你所能知道的是它没有在这个文件中定义。

有什么好的策略来处理吗?我是唯一一个困扰的人吗?

4

1 回答 1

0

我唯一能想到并且偶尔会做的事情就是用POD彻底记录所有内容。但这当然需要大量的纪律。

use Moo;
with 'Role::Reader', 'Role::Writer';

# ...

=head1 METHODS

=head2 frobnicate

Frobnicates the foo.

=cut

sub frobnicate { ... }

=head2 write_cheque

This method is documented in L<Role::Writer>.

=head2 write_autograph

This method is documented in L<Role::Writer>.

=head2 read_mind

This method is documented in L<Role::Reader>.

=head2 read_book

This method is documented in L<Role::Reader>.

=cut

1; 
于 2017-07-12T18:55:06.040 回答