1 package MooseX::Declare::Syntax::InnerSyntaxHandling;
5 use MooseX::Declare::Util qw( outer_stack_push );
7 use namespace::clean -except => 'meta';
13 sub default_inner { [] }
15 after setup_for => sub {
16 my ($self, $setup_class, %args) = @_;
18 # make sure stack is valid
19 my $stack = $args{stack} || [];
21 # setup inner keywords if we're inside ourself
22 if (grep { $_ eq $self->get_identifier } @$stack) {
23 $self->setup_inner_for($setup_class, %args);
28 my ($self, $setup_class, %args) = @_;
30 # setup each keyword in target class
31 for my $inner (@{ $self->default_inner($args{stack}) }) {
32 $inner->setup_for($setup_class, %args);
35 # push package onto stack for namespace management
36 if (exists $args{file}) {
37 outer_stack_push $args{file}, $args{outer_package};
45 MooseX::Declare::Syntax::InnerSyntaxHandling - Keywords inside blocks
49 This role allows you to setup keyword handlers that are only available
50 inside blocks or other scoping environments.
56 An C<ArrayRef> of keyword handlers that will be setup inside the built
57 scope. It is initialized by the L</default_inner> method.
59 =head1 REQUIRED METHODS
65 Required to return the name of the identifier of the current handler.
71 ArrayRef[Object] Object->default_inner ()
73 Returns an empty C<ArrayRef> by default. If you want to setup additional
74 keywords you will have to C<around> this method.
76 =head2 setup_inner_for
78 Object->setup_inner_for(ClassName $class, %args)
80 Sets up all handlers in the L</inner> attribute.
82 =head1 MODIFIED METHODS
86 Object->setup_for(ClassName $class, %args)
88 After the keyword is setup inside itself, this will call L</setup_inner_for>.
94 =item * L<MooseX::Declare>
96 =item * L<MooseX::Declare::Syntax::NamespaceHandling>
98 =item * L<MooseX::Declare::Syntax::MooseSetup>
102 =head1 AUTHOR, COPYRIGHT & LICENSE
104 See L<MooseX::Declare>