1 package MooseX::MethodAttributes::Role::Meta::Class;
4 # ABSTRACT: metaclass role for storing code attributes
7 use Moose::Util qw/find_meta does_role/;
9 use namespace::clean -except => 'meta';
12 MooseX::MethodAttributes::Role::Meta::Map
16 sub get_method_with_attributes_list {
18 my @methods = map { $self->get_method($_) } $self->get_method_list;
23 $order{$_} = $i++ for @{ $self->_method_attribute_list };
29 $order{ $a->[0] } <=> $order{ $b->[0] }
31 my $addr = 0 + $_->_get_attributed_coderef;
32 exists $self->_method_attribute_map->{$addr}
36 $_->can('_get_attributed_coderef')
41 sub get_all_methods_with_attributes {
49 my $meta = find_meta($_);
50 ($meta && ($meth = $meta->can('get_method_with_attributes_list')))
53 } reverse $self->linearized_isa;
57 sub get_nearest_methods_with_attributes {
60 my $m = $self->find_method_by_name($_->name);
61 my $meth = $m->can('attributes');
62 my $attrs = $meth ? $m->$meth() : [];
63 scalar @{ $attrs } ? ( $m ) : ( );
64 } $self->get_all_methods_with_attributes;
68 foreach my $type (qw/after before around/) {
69 around "add_${type}_method_modifier" => sub {
72 my ($method_name) = @_;
74 # Ensure the correct metaclass
75 $meta = MooseX::MethodAttributes->init_meta( for_class => $meta->name );
77 my $code = $meta->$orig(@_);
78 my $method = $meta->get_method($method_name);
80 does_role($method->get_original_method, 'MooseX::MethodAttributes::Role::Meta::Method')
81 || does_role($method->get_original_method, 'MooseX::MethodAttributes::Role::Meta::Method::Wrapped')
83 MooseX::MethodAttributes::Role::Meta::Method::Wrapped->meta->apply($method);
98 MooseX::MethodAttributes::Role::Meta::Class - metaclass role for storing code attributes
106 =head2 get_method_with_attributes_list
108 Gets the list of meta methods for local methods of this class that have
109 attributes in the order they have been registered.
113 =head2 get_all_methods_with_attributes
115 Gets the list of meta methods of local and inherited methods of this class,
116 that have attributes. Baseclass methods come before subclass methods. Methods
117 of one class have the order they have been declared in.
121 =head2 get_nearest_methods_with_attributes
123 The same as get_all_methods_with_attributes, except that methods from parent classes
124 are not included if there is an attributeless method in a child class.
135 use base qw/BaseClass/;
141 C<< SubClass->meta->get_all_methods_with_attributes >> will return
142 C<< BaseClass->meta->get_method('foo') >> for the above example, but
143 this method will not, and will return the wrapped bar method, wheras
144 C<< get_all_methods_with_attributes >> will return the original method.
150 Florian Ragwitz <rafl@debian.org>
151 Tomas Doran <bobtfish@bobtfish.net>
153 =head1 COPYRIGHT AND LICENSE
155 This software is copyright (c) 2009 by Florian Ragwitz.
157 This is free software; you can redistribute it and/or modify it under
158 the same terms as perl itself.