(This is unrelated to your actual question / problem.)
Why do you use wantarray?
sub my_uniq { my $self = shift; my @result = uniq @{ $self->list }; wantarray ? @result : scalar @result; }
Why don't you simply write
sub my_uniq { my $self = shift; return uniq @{ $self->list }; }
My guess is it's a performance optimization since it reimplements already existing behaviour. Have you benchmarked it?
My personal opinion - feel free to ignore it.
As far as I can see the method my_uniq is simply a convenience function to make it easier to work with the array reference stored in the field 'list'. I would design the class differently and not provide any direct access to the field 'list' at all. Instead provide an accessor which returns the list as an array and drop the convenience function 'my_uniq'.
# class method sub get_list { my $self = shift; return @{ $self->list() }; }
# client code - variant a # (client wants values and count) my @uniq_list = uniq $obj->get_list(); my $uniq_count = scalar @uniq_list; # client code - variant b # (client just wants the count) my $uniq_count = scalar uniq $obj->get_list();
Main reason: If the user wants to do something else with the list (e.g. reverse) then I don't need to reimplement these functions too.
In reply to Re: Moo From Hell #1: How to proxy a sub from a non OO module [SOLVED]
by Monk::Thomas
in thread Moo From Hell #1: How to proxy a sub from a non OO module [SOLVED]
by karlgoethebier
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |