package Mouse::Meta::Role;
-use Mouse::Util qw(:meta not_supported english_list); # enables strict and warnings
+use Mouse::Util qw(:meta not_supported); # enables strict and warnings
use Mouse::Meta::Module;
our @ISA = qw(Mouse::Meta::Module);
$role->throw_error(sprintf "'%s' requires the method%s %s to be implemented by '%s'",
$role->name,
(@missing == 1 ? '' : 's'), # method or methods
- english_list(map{ sprintf q{'%s'}, $_ } @missing),
+ Mouse::Util::quoted_english_list(@missing),
$consumer_class_name);
}
}
package Mouse::Meta::Role::Composite;
-use Mouse::Util qw(english_list); # enables strict and warnings
+use Mouse::Util; # enables strict and warnings
use Mouse::Meta::Role;
our @ISA = qw(Mouse::Meta::Role);
my @roles = sort @{ $self->{composed_roles_by_method}{$method_name} };
$self->throw_error(
sprintf q{Due to a method name conflict in roles %s, the method '%s' must be implemented or excluded by '%s'},
- english_list(map{ sprintf q{'%s'}, $_->name } @roles), $method_name, $consumer->name
+ Mouse::Util::quoted_english_list(map{ $_->name } @roles), $method_name, $consumer->name
);
}
elsif(@conflicting > 1){
- my $methods = english_list(map{ sprintf q{'%s'}, $_ } @conflicting);
+ my $methods = Mouse::Util::quoted_english_list(@conflicting);
my %seen;
- my $roles = english_list(
- sort map{ my $name = $_->name; $seen{$name}++ ? () : sprintf q{'%s'}, $name }
- map{ @{$_} } @{ $self->{composed_roles_by_method} }{@conflicting}
+ my $roles = Mouse::Util::quoted_english_list(sort
+ grep{ !$seen{$_}++ } # uniq
+ map { $_->name }
+ map { @{$_} } @{ $self->{composed_roles_by_method} }{@conflicting}
);
$self->throw_error(
return join q{, }, @items, "and $tail";
}
+sub quoted_english_list {
+ return qq{'$_[0]'} if @_ == 1;
+
+ my @items = sort @_;
+
+ return qq{'$items[0]' and '$items[1]'} if @items == 2;
+
+ my $tail = pop @items;
+
+ return join q{, }, (map{ qq{'$_'} } @items), qq{and '$tail'};
+}
+
# common utilities
sub not_supported{