return;
}
-sub compute_all_applicable_methods {
+sub get_all_methods {
my $self = shift;
my %methods = map { %{ $self->initialize($_)->get_method_map } } reverse $self->linearized_isa;
- # return values %methods # TODO make some new API that does this
+ return values %methods;
+}
+
+# compatibility
+sub compute_all_applicable_methods {
return map {
{
name => $_->name,
class => $_->package_name,
code => $_, # sigh, overloading
},
- } values %methods;
+ } shift->get_all_methods(@_);
}
sub find_all_methods_by_name {
keys %{$self->get_attribute_map};
}
+sub get_all_attributes {
+ shift->compute_all_applicable_attributes(@_);
+}
+
sub compute_all_applicable_attributes {
my $self = shift;
my %attrs = map { %{ $self->initialize($_)->get_attribute_map } } reverse $self->linearized_isa;
including any inherited ones. If you want a list of all applicable
methods, use the C<compute_all_applicable_methods> method.
+=item B<get_all_methods>
+
+This will traverse the inheritance heirachy and return a list of all
+the applicable L<Class::MOP::Method> objects for this class.
+
=item B<compute_all_applicable_methods>
-This will return a list of all the methods names this class will
-respond to, taking into account inheritance. The list will be a list of
-HASH references, each one containing the following information; method
-name, the name of the class in which the method lives and a CODE
-reference for the actual method.
+Deprecated.
+
+This method returns a list of hashes describing the all the methods of the
+class.
+
+Use L<get_all_methods>, which is easier/better/faster. This method predates
+L<Class::MOP::Method>.
=item B<find_all_methods_by_name ($method_name)>
=item B<compute_all_applicable_attributes>
+=item B<get_all_attributes>
+
This will traverse the inheritance heirachy and return a list of all
-the applicable attributes for this class. It does not construct a
-HASH reference like C<compute_all_applicable_methods> because all
-that same information is discoverable through the attribute
-meta-object itself.
+the applicable L<Class::MOP::Attribute> objects for this class.
+
+C<get_all_attributes> is an alias for consistency with C<get_all_methods>.
=item B<find_attribute_by_name ($attr_name)>
'... got the right method list for Foo');
is_deeply(
- [ sort { $a->{name} cmp $b->{name} } $Foo->compute_all_applicable_methods() ],
+ [ sort { $a->name cmp $b->name } $Foo->get_all_methods() ],
[
- map {
- {
- name => $_,
- class => 'Foo',
- code => $Foo->get_method($_)
- }
- } qw(
+ map { $Foo->get_method($_) } qw(
FOO_CONSTANT
baaz
bang
'... got the right method list for Bar');
is_deeply(
- [ sort { $a->{name} cmp $b->{name} } $Bar->compute_all_applicable_methods() ],
+ [ sort { $a->name cmp $b->name } $Bar->get_all_methods() ],
[
- {
- name => 'FOO_CONSTANT',
- class => 'Foo',
- code => $Foo->get_method('FOO_CONSTANT')
- },
- {
- name => 'baaz',
- class => 'Foo',
- code => $Foo->get_method('baaz')
- },
- {
- name => 'bang',
- class => 'Foo',
- code => $Foo->get_method('bang')
- },
- {
- name => 'bar',
- class => 'Bar',
- code => $Bar->get_method('bar')
- },
- (map {
- {
- name => $_,
- class => 'Foo',
- code => $Foo->get_method($_)
- }
- } qw(
+ $Foo->get_method('FOO_CONSTANT'),
+ $Foo->get_method('baaz'),
+ $Foo->get_method('bang'),
+ $Bar->get_method('bar'),
+ (map { $Foo->get_method($_) } qw(
baz
blah
evaled_foo
floob
)),
- {
- name => 'foo',
- class => 'Bar',
- code => $Bar->get_method('foo')
- },
- {
- name => 'meta',
- class => 'Bar',
- code => $Bar->get_method('meta')
- }
+ $Bar->get_method('foo'),
+ $Bar->get_method('meta'),
],
'... got the right list of applicable methods for Bar');
'... Foo::Bar::Baz->BUILD does have a next method');
is_deeply(
- [ sort { $a->{name} cmp $b->{name} } Class::MOP::Class->initialize('Foo')->compute_all_applicable_methods() ],
+ [ sort { $a->{name} cmp $b->{name} } Class::MOP::Class->initialize('Foo')->get_all_methods() ],
[
- {
- name => 'BUILD',
- class => 'Foo',
- code => Class::MOP::Class->initialize('Foo')->get_method('BUILD')
- },
- {
- name => 'foo',
- class => 'Foo',
- code => Class::MOP::Class->initialize('Foo')->get_method('foo')
- },
+ Class::MOP::Class->initialize('Foo')->get_method('BUILD') ,
+ Class::MOP::Class->initialize('Foo')->get_method('foo'),
],
'... got the right list of applicable methods for Foo');
is_deeply(
- [ sort { $a->{name} cmp $b->{name} } Class::MOP::Class->initialize('Bar')->compute_all_applicable_methods() ],
+ [ sort { $a->{name} cmp $b->{name} } Class::MOP::Class->initialize('Bar')->get_all_methods() ],
[
- {
- name => 'BUILD',
- class => 'Bar',
- code => Class::MOP::Class->initialize('Bar')->get_method('BUILD')
- },
- {
- name => 'bar',
- class => 'Bar',
- code => Class::MOP::Class->initialize('Bar')->get_method('bar')
- },
- {
- name => 'foo',
- class => 'Foo',
- code => Class::MOP::Class->initialize('Foo')->get_method('foo')
- },
+ Class::MOP::Class->initialize('Bar')->get_method('BUILD'),
+ Class::MOP::Class->initialize('Bar')->get_method('bar'),
+ Class::MOP::Class->initialize('Foo')->get_method('foo'),
],
'... got the right list of applicable methods for Bar');
is_deeply(
- [ sort { $a->{name} cmp $b->{name} } Class::MOP::Class->initialize('Baz')->compute_all_applicable_methods() ],
+ [ sort { $a->{name} cmp $b->{name} } Class::MOP::Class->initialize('Baz')->get_all_methods() ],
[
- {
- name => 'BUILD',
- class => 'Bar',
- code => Class::MOP::Class->initialize('Bar')->get_method('BUILD')
- },
- {
- name => 'bar',
- class => 'Bar',
- code => Class::MOP::Class->initialize('Bar')->get_method('bar')
- },
- {
- name => 'baz',
- class => 'Baz',
- code => Class::MOP::Class->initialize('Baz')->get_method('baz')
- },
- {
- name => 'foo',
- class => 'Baz',
- code => Class::MOP::Class->initialize('Baz')->get_method('foo')
- },
+ Class::MOP::Class->initialize('Bar')->get_method('BUILD'),
+ Class::MOP::Class->initialize('Bar')->get_method('bar'),
+ Class::MOP::Class->initialize('Baz')->get_method('baz'),
+ Class::MOP::Class->initialize('Baz')->get_method('foo'),
],
'... got the right list of applicable methods for Baz');
is_deeply(
- [ sort { $a->{name} cmp $b->{name} } Class::MOP::Class->initialize('Foo::Bar')->compute_all_applicable_methods() ],
+ [ sort { $a->{name} cmp $b->{name} } Class::MOP::Class->initialize('Foo::Bar')->get_all_methods() ],
[
- {
- name => 'BUILD',
- class => 'Foo::Bar',
- code => Class::MOP::Class->initialize('Foo::Bar')->get_method('BUILD')
- },
- {
- name => 'bar',
- class => 'Bar',
- code => Class::MOP::Class->initialize('Bar')->get_method('bar')
- },
- {
- name => 'foo',
- class => 'Foo',
- code => Class::MOP::Class->initialize('Foo')->get_method('foo')
- },
- {
- name => 'foobar',
- class => 'Foo::Bar',
- code => Class::MOP::Class->initialize('Foo::Bar')->get_method('foobar')
- },
+ Class::MOP::Class->initialize('Foo::Bar')->get_method('BUILD'),
+ Class::MOP::Class->initialize('Bar')->get_method('bar'),
+ Class::MOP::Class->initialize('Foo')->get_method('foo'),
+ Class::MOP::Class->initialize('Foo::Bar')->get_method('foobar'),
],
'... got the right list of applicable methods for Foo::Bar');
+# test compute_all_applicable_methods once for compat
is_deeply(
[ sort { $a->{name} cmp $b->{name} } Class::MOP::Class->initialize('Foo::Bar::Baz')->compute_all_applicable_methods() ],
[
code => Class::MOP::Class->initialize('Bar')->get_method('BUILD')
},
],
- '... got the right list of BUILD methods for Foo::Bar::Baz');
\ No newline at end of file
+ '... got the right list of BUILD methods for Foo::Bar::Baz');
use strict;
use warnings;
-use Test::More tests => 220;
+use Test::More tests => 224;
use Test::Exception;
BEGIN {
superclasses subclasses class_precedence_list linearized_isa
has_method get_method add_method remove_method alias_method
- get_method_list get_method_map compute_all_applicable_methods
+ get_method_list get_method_map 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
has_attribute get_attribute add_attribute remove_attribute
- get_attribute_list get_attribute_map compute_all_applicable_attributes find_attribute_by_name
+ get_attribute_list get_attribute_map get_all_attributes compute_all_applicable_attributes find_attribute_by_name
is_mutable is_immutable make_mutable make_immutable create_immutable_transformer
get_immutable_options get_immutable_transformer