MooseX::Declare::Syntax::InnerSyntaxHandling - Keywords inside blocks


MooseX-Declare documentation Contained in the MooseX-Declare distribution.

Index


Code Index:

NAME

Top

MooseX::Declare::Syntax::InnerSyntaxHandling - Keywords inside blocks

DESCRIPTION

Top

This role allows you to setup keyword handlers that are only available inside blocks or other scoping environments.

METHODS

Top

default_inner

  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.

setup_inner_for

  Object->setup_inner_for(ClassName $class, %args)

Sets up all handlers in the inner class.

REQUIRED METHODS

Top

get_identifier

  Str get_identifier ()

Required to return the name of the identifier of the current handler.

MODIFIED METHODS

Top

setup_for

  Object->setup_for(ClassName $class, %args)

After the keyword is setup inside itself, this will call setup_inner_for.

SEE ALSO

Top

AUTHORS

Top

COPYRIGHT AND LICENSE

Top


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__