| MooseX-Declare documentation | Contained in the MooseX-Declare distribution. |
MooseX::Declare::Syntax::InnerSyntaxHandling - Keywords inside blocks
This role allows you to setup keyword handlers that are only available inside blocks or other scoping environments.
ArrayRef[Object] Object->default_inner ()
Returns an empty ArrayRef by default. If you want to setup additional
keywords you will have to around this method.
Object->setup_inner_for(ClassName $class, %args)
Sets up all handlers in the inner class.
Str get_identifier ()
Required to return the name of the identifier of the current handler.
Object->setup_for(ClassName $class, %args)
After the keyword is setup inside itself, this will call setup_inner_for.
This software is copyright (c) 2010 by Florian Ragwitz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
| MooseX-Declare documentation | Contained in the MooseX-Declare distribution. |
package MooseX::Declare::Syntax::InnerSyntaxHandling; BEGIN { $MooseX::Declare::Syntax::InnerSyntaxHandling::AUTHORITY = 'cpan:FLORA'; } BEGIN { $MooseX::Declare::Syntax::InnerSyntaxHandling::VERSION = '0.34'; } # ABSTRACT: Keywords inside blocks use Moose::Role; use MooseX::Declare::Util qw( outer_stack_push ); use namespace::clean -except => 'meta'; requires qw( get_identifier ); sub default_inner { [] } after setup_for => sub { my ($self, $setup_class, %args) = @_; # make sure stack is valid my $stack = $args{stack} || []; # setup inner keywords if we're inside ourself if (grep { $_ eq $self->get_identifier } @$stack) { $self->setup_inner_for($setup_class, %args); } }; sub setup_inner_for { my ($self, $setup_class, %args) = @_; # setup each keyword in target class for my $inner (@{ $self->default_inner($args{stack}) }) { $inner->setup_for($setup_class, %args); } # push package onto stack for namespace management if (exists $args{file}) { outer_stack_push $args{file}, $args{outer_package}; } } 1; __END__