From: gfx Date: Mon, 8 Feb 2010 04:16:31 +0000 (+0900) Subject: Add Mouse::Util::quoted_english_list() X-Git-Tag: 0.50~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5af36247683101e3c457450489486d41f0bd7101;p=gitmo%2FMouse.git Add Mouse::Util::quoted_english_list() --- diff --git a/lib/Mouse/Meta/Role.pm b/lib/Mouse/Meta/Role.pm index a52c12e..d680a54 100644 --- a/lib/Mouse/Meta/Role.pm +++ b/lib/Mouse/Meta/Role.pm @@ -1,5 +1,5 @@ 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); @@ -85,7 +85,7 @@ sub _check_required_methods{ $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); } } diff --git a/lib/Mouse/Meta/Role/Composite.pm b/lib/Mouse/Meta/Role/Composite.pm index 58496c3..771520b 100644 --- a/lib/Mouse/Meta/Role/Composite.pm +++ b/lib/Mouse/Meta/Role/Composite.pm @@ -1,5 +1,5 @@ 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); @@ -91,16 +91,17 @@ sub _apply_methods{ 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( diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index 19876a1..3ffa375 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -310,6 +310,18 @@ sub english_list { 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{