Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / MooseX / Declare / Syntax / InnerSyntaxHandling.pm
1 package MooseX::Declare::Syntax::InnerSyntaxHandling;
2
3 use Moose::Role;
4
5 use MooseX::Declare::Util qw( outer_stack_push );
6
7 use namespace::clean -except => 'meta';
8
9 requires qw(
10     get_identifier
11 );
12
13 sub default_inner { [] }
14
15 after setup_for => sub {
16     my ($self, $setup_class, %args) = @_;
17
18     # make sure stack is valid
19     my $stack = $args{stack} || [];
20
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);
24     }
25 };
26
27 sub setup_inner_for {
28     my ($self, $setup_class, %args) = @_;
29
30     # setup each keyword in target class
31     for my $inner (@{ $self->default_inner($args{stack}) }) {
32         $inner->setup_for($setup_class, %args);
33     }
34
35     # push package onto stack for namespace management
36     if (exists $args{file}) {
37         outer_stack_push $args{file}, $args{outer_package};
38     }
39 }
40
41 1;
42
43 =head1 NAME
44
45 MooseX::Declare::Syntax::InnerSyntaxHandling - Keywords inside blocks
46
47 =head1 DESCRIPTION
48
49 This role allows you to setup keyword handlers that are only available
50 inside blocks or other scoping environments.
51
52 =head1 ATTRIBUTES
53
54 =head2 inner
55
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.
58
59 =head1 REQUIRED METHODS
60
61 =head2 get_identifier
62
63   Str get_identifier ()
64
65 Required to return the name of the identifier of the current handler.
66
67 =head1 METHODS
68
69 =head2 default_inner
70
71   ArrayRef[Object] Object->default_inner ()
72
73 Returns an empty C<ArrayRef> by default. If you want to setup additional
74 keywords you will have to C<around> this method.
75
76 =head2 setup_inner_for
77
78   Object->setup_inner_for(ClassName $class, %args)
79
80 Sets up all handlers in the L</inner> attribute.
81
82 =head1 MODIFIED METHODS
83
84 =head2 setup_for
85
86   Object->setup_for(ClassName $class, %args)
87
88 After the keyword is setup inside itself, this will call L</setup_inner_for>.
89
90 =head1 SEE ALSO
91
92 =over
93
94 =item * L<MooseX::Declare>
95
96 =item * L<MooseX::Declare::Syntax::NamespaceHandling>
97
98 =item * L<MooseX::Declare::Syntax::MooseSetup>
99
100 =back
101
102 =head1 AUTHOR, COPYRIGHT & LICENSE
103
104 See L<MooseX::Declare>
105
106 =cut