From: Shawn M Moore Date: Thu, 5 Feb 2009 21:11:13 +0000 (+0000) Subject: Add get_all_method_names X-Git-Tag: 0.77~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8b6a1e85e17efed123998b69c0efc341f29a5df8;p=gitmo%2FClass-MOP.git Add get_all_method_names --- diff --git a/Changes b/Changes index 3d25dd3..247b2d0 100644 --- a/Changes +++ b/Changes @@ -18,6 +18,8 @@ Revision history for Perl extension Class-MOP. * Tests - Add test showing how the xs Class::MOP::is_class_loaded can be made to operate differently to the pure perl version (t0m) + * Class::MOP::Class + - Add get_all_method_names (Sartak) 0.75 Wed, December 31, 2008 * Class::MOP::Class diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index fdd91aa..bdf895d 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -800,6 +800,12 @@ sub compute_all_applicable_methods { } shift->get_all_methods(@_); } +sub get_all_method_names { + my $self = shift; + my %uniq; + grep { $uniq{$_}++ == 0 } map { $_->name } $self->get_all_methods; +} + sub find_all_methods_by_name { my ($self, $method_name) = @_; (defined $method_name && $method_name) @@ -1100,6 +1106,7 @@ sub create_immutable_transformer { class_precedence_list => 'ARRAY', linearized_isa => 'ARRAY', # FIXME perl 5.10 memoizes this on its own, no need? get_all_methods => 'ARRAY', + get_all_method_names => 'ARRAY', #get_all_attributes => 'ARRAY', # it's an alias, no need, but maybe in the future compute_all_applicable_attributes => 'ARRAY', get_meta_instance => 'SCALAR', @@ -1555,6 +1562,12 @@ class. Use L, which is easier/better/faster. This method predates L. +=item B + +This will traverse the inheritance heirachy and return a list of all the +applicable method names for this class. Duplicate names are removed, but the +order the methods come out is not defined. + =item B This will traverse the inheritence hierarchy and locate all methods diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index f2dcff2..fecd632 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 234; +use Test::More tests => 236; use Test::Exception; use Class::MOP; @@ -71,7 +71,7 @@ my @class_mop_class_methods = qw( superclasses subclasses class_precedence_list linearized_isa has_method get_method add_method remove_method alias_method wrap_method_body - get_method_list get_method_map get_all_methods compute_all_applicable_methods + get_method_list get_method_map get_all_method_names get_all_methods compute_all_applicable_methods find_method_by_name find_all_methods_by_name find_next_method_by_name add_before_method_modifier add_after_method_modifier add_around_method_modifier