0

The improvement of using roles (Moo::Role or Role::Tiny or whatever)

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

over just explicitly importing the function from the mixin class

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

are numerous, and include added flexibility, less bookkeeping (especially if there are a lot of methods being imported), and not overwriting existing methods.

But a big drawback is if you're reading the code and come across mentions of some_roles_method() and you want to read the function, it's not immediately apparent where to go. All you can tell is that it's not defined in this file.

Are there any good strategies for handling that? Am I the only one that bothers?

Kevin G.
  • 1,424
  • 1
  • 13
  • 22
  • 2
    That is not the only role of roles (no pun intended.) For example, [`requires`](https://www.nu42.com/2010/07/beauty-of-moose-enforcing-interface.html) can come in handy. If you don't buy in to the sugar these modules provide, SO is not the place to have a debate about it. – Sinan Ünür Jul 12 '17 at 16:57
  • 1
    Given how it's called the only place to go to is the package (class). Then you look for `with` there and see the role's package name. It shouldn't be much of a problem? – zdim Jul 12 '17 at 17:12
  • 2
    Given your snippet, let me say this just in case -- roles are used with a class and are absorbed by it (see [this post](https://stackoverflow.com/a/42465412/4653379) for example). Then locating the method shouldn't be a problem. – zdim Jul 12 '17 at 17:22

1 Answers1

0

The only thing I can think of, and that I do once in a while, is to document everything thoroughly with POD. But of course that requires a lot of discipline.

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; 
simbabque
  • 53,749
  • 8
  • 73
  • 136