Commit | Line | Data |
3fea05b9 |
1 | package MooseX::Declare::Syntax::MethodDeclaration; |
2 | |
3 | use Moose::Role; |
4 | use MooseX::Method::Signatures::Meta::Method; |
5 | use MooseX::Method::Signatures (); |
6 | use MooseX::Method::Signatures::Types qw/PrototypeInjections/; |
7 | |
8 | use namespace::clean -except => 'meta'; |
9 | |
10 | with qw( |
11 | MooseX::Declare::Syntax::KeywordHandling |
12 | ); |
13 | |
14 | requires qw( |
15 | register_method_declaration |
16 | ); |
17 | |
18 | has prototype_injections => ( |
19 | is => 'ro', |
20 | isa => PrototypeInjections, |
21 | predicate => 'has_prototype_injections', |
22 | ); |
23 | |
24 | sub parse { |
25 | my ($self, $ctx) = @_; |
26 | |
27 | my %args = ( |
28 | context => $ctx->_dd_context, |
29 | initialized_context => 1, |
30 | custom_method_application => sub { |
31 | my ($meta, $name, $method) = @_; |
32 | $self->register_method_declaration($meta, $name, $method); |
33 | }, |
34 | ); |
35 | |
36 | $args{prototype_injections} = $self->prototype_injections |
37 | if $self->has_prototype_injections; |
38 | |
39 | my $mxms = MooseX::Method::Signatures->new(%args); |
40 | $mxms->parser; |
41 | } |
42 | |
43 | 1; |
44 | |
45 | __END__ |
46 | |
47 | =head1 NAME |
48 | |
49 | MooseX::Declare::Syntax::MethodDeclaration - Handles method declarations |
50 | |
51 | =head1 DESCRIPTION |
52 | |
53 | A role for keyword handlers that gives a framework to add or modify |
54 | methods or things that look like methods. |
55 | |
56 | =head1 CONSUMES |
57 | |
58 | =over |
59 | |
60 | =item * L<MooseX::Declare::Syntax::KeywordHandling> |
61 | |
62 | =back |
63 | |
64 | =head1 ATTRIBUTES |
65 | |
66 | =head2 prototype_injections |
67 | |
68 | An optional structure describing additional things to be added to a methods |
69 | signature. A popular example is found in the C<around> |
70 | L<method modifier handler|MooseX::Declare::Syntax::Keyword::MethodModifier>: |
71 | |
72 | |
73 | |
74 | =head1 REQUIRED METHODS |
75 | |
76 | =head2 register_method_declaration |
77 | |
78 | Object->register_method_declaration (Object $metaclass, Str $name, Object $method) |
79 | |
80 | This method will be called with the target metaclass and the final built |
81 | L<method meta object|MooseX::Method::Signatures::Meta::Method> and its name. |
82 | The value it returns will be the value returned where the method was declared. |
83 | |
84 | =head1 METHODS |
85 | |
86 | =head2 parse |
87 | |
88 | Object->parse (Object $ctx); |
89 | |
90 | Reads a name and a prototype and builds the method meta object then registers |
91 | it into the current class using MooseX::Method::Signatures and a |
92 | C<custom_method_application>, that calls L</register_method_declaration>. |
93 | |
94 | =head1 SEE ALSO |
95 | |
96 | =over |
97 | |
98 | =item * L<MooseX::Declare> |
99 | |
100 | =item * L<MooseX::Declare::Syntax::NamespaceHandling> |
101 | |
102 | =item * L<MooseX::Declare::Syntax::MooseSetup> |
103 | |
104 | =item * L<MooseX::Method::Signatures> |
105 | |
106 | =back |
107 | |
108 | =head1 AUTHOR, COPYRIGHT & LICENSE |
109 | |
110 | See L<MooseX::Declare> |
111 | |
112 | =cut |