Commit | Line | Data |
3fea05b9 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | package MooseX::MethodAttributes::Role; |
5 | our $VERSION = '0.18'; |
6 | |
7 | # ABSTRACT: code attribute introspection |
8 | |
9 | use Moose (); |
10 | use Moose::Exporter; |
11 | use Moose::Util::MetaRole; |
12 | use Moose::Util qw/find_meta does_role ensure_all_roles/; |
13 | # Ensure trait is registered |
14 | use MooseX::MethodAttributes::Role::Meta::Role (); |
15 | |
16 | |
17 | Moose::Exporter->setup_import_methods( also => 'Moose::Role' ); |
18 | |
19 | sub init_meta { |
20 | my ($class, %options) = @_; |
21 | |
22 | my $for_class = $options{for_class}; |
23 | my $meta = find_meta($for_class); |
24 | |
25 | return $meta if $meta |
26 | && does_role($meta, 'MooseX::MethodAttributes::Role::Meta::Role'); |
27 | |
28 | $meta = Moose::Meta::Role->initialize( $for_class ) |
29 | unless $meta; |
30 | |
31 | $meta = Moose::Util::MetaRole::apply_metaclass_roles( |
32 | for_class => $meta->name, |
33 | metaclass_roles => [ 'MooseX::MethodAttributes::Role::Meta::Role' ], |
34 | ); |
35 | |
36 | ensure_all_roles($meta->name, |
37 | 'MooseX::MethodAttributes::Role::AttrContainer', |
38 | ); |
39 | |
40 | return $meta; |
41 | } |
42 | |
43 | 1; |
44 | |
45 | __END__ |
46 | |
47 | =pod |
48 | |
49 | =head1 NAME |
50 | |
51 | MooseX::MethodAttributes::Role - code attribute introspection |
52 | |
53 | =head1 VERSION |
54 | |
55 | version 0.18 |
56 | |
57 | =head1 SYNOPSIS |
58 | |
59 | package MyRole; |
60 | use MooseX::MethodAttributes::Role; |
61 | |
62 | sub foo : Bar Baz('corge') { ... } |
63 | |
64 | my $attrs = MyRole->meta->get_method('foo')->attributes; # ["Bar", "Baz('corge')"] |
65 | |
66 | =head1 DESCRIPTION |
67 | |
68 | This module allows you to write a Moose Role with code attributes of methods to |
69 | be introspected using Moose meta method objects. |
70 | |
71 | =begin Pod::Coverage |
72 | |
73 | init_meta |
74 | |
75 | =end Pod::Coverage |
76 | |
77 | |
78 | |
79 | =head1 AUTHORS |
80 | |
81 | Florian Ragwitz <rafl@debian.org> |
82 | Tomas Doran <bobtfish@bobtfish.net> |
83 | |
84 | =head1 COPYRIGHT AND LICENSE |
85 | |
86 | This software is copyright (c) 2009 by Florian Ragwitz. |
87 | |
88 | This is free software; you can redistribute it and/or modify it under |
89 | the same terms as perl itself. |
90 | |
91 | =cut |
92 | |
93 | |