1 package MooseX::MethodAttributes::Role::Meta::Role;
4 # ABSTRACT: metarole role for storing code attributes
6 use Moose::Util::MetaRole;
7 use Moose::Util qw/find_meta does_role ensure_all_roles/;
12 use MooseX::MethodAttributes ();
13 use MooseX::MethodAttributes::Role ();
15 use namespace::clean -except => 'meta';
19 MooseX::MethodAttributes::Role::Meta::Map
20 MooseX::MethodAttributes::Role::Meta::Role::Application
23 has '+composition_class_roles' => (
24 default => [ 'MooseX::MethodAttributes::Role::Meta::Role::Application::Summation' ],
28 after 'initialize' => sub {
29 my ($self, $class, %args) = @_;
30 ensure_all_roles($class, 'MooseX::MethodAttributes::Role::AttrContainer');
34 # FIXME - Skip this logic if the method metaclass already does the right role?
35 around method_metaclass => sub {
38 return $self->$orig(@_) if scalar @_;
39 Moose::Meta::Class->create_anon_class(
40 superclasses => [ $self->$orig ],
42 MooseX::MethodAttributes::Role::Meta::Method
49 sub _copy_attributes {
50 my ($self, $thing) = @_;
52 push @{ $thing->_method_attribute_list }, @{ $self->_method_attribute_list };
53 @{ $thing->_method_attribute_map }{ (keys(%{ $self->_method_attribute_map }), keys(%{ $thing->_method_attribute_map })) }
54 = (values(%{ $self->_method_attribute_map }), values(%{ $thing->_method_attribute_map }));
57 # This allows you to say use Moose::Role -traits => 'MethodAttributes'
58 # This is replaced by MooseX::MethodAttributes::Role, and this trait registration
59 # is now only present for backwards compatibility reasons.
60 package # Hide from PAUSE
61 Moose::Meta::Role::Custom::Trait::MethodAttributes;
63 sub register_implementation { 'MooseX::MethodAttributes::Role::Meta::Role' }
74 MooseX::MethodAttributes::Role::Meta::Role - metarole role for storing code attributes
83 use MooseX::MethodAttributes::Role;
85 sub foo : Bar Baz('corge') { ... }
92 my $attrs = MyClass->meta->get_method('foo')->attributes; # ["Bar", "Baz('corge')"]
96 This module is a metaclass role which is applied by L<MooseX::MethodAttributes::Role>, allowing
97 you to add code attributes to methods in Moose roles.
99 These attributes can then be found by introspecting the role metaclass, and are automatically copied
100 into any classes or roles that the role is composed onto.
108 Currently roles with attributes cannot have methods excluded
109 or aliased, and will in turn confer this property onto any roles they
120 Ensures that the package containing the role methods does the
121 L<MooseX::MethodAttributes::Role::AttrContainer> role during initialisation,
122 which in turn is responsible for capturing the method attributes on the class
123 and registering them with the metaclass.
127 =head2 method_metaclass
129 Wraps the normal method and ensures that the method metaclass performs the
130 L<MooseX::MethodAttributes::Role::Meta::Method> role, which allows you to
131 introspect the attributes from the method objects returned by the MOP when
132 querying the metaclass.
138 Florian Ragwitz <rafl@debian.org>
139 Tomas Doran <bobtfish@bobtfish.net>
141 =head1 COPYRIGHT AND LICENSE
143 This software is copyright (c) 2009 by Florian Ragwitz.
145 This is free software; you can redistribute it and/or modify it under
146 the same terms as perl itself.