Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / MooseX / Declare / Syntax / Keyword / With.pm
1 package MooseX::Declare::Syntax::Keyword::With;
2
3 use Moose;
4 use Moose::Util;
5 use MooseX::Declare::Util qw( outer_stack_peek );
6 use aliased 'MooseX::Declare::Context::Namespaced';
7 use namespace::autoclean;
8
9 with qw(
10     MooseX::Declare::Syntax::KeywordHandling
11 );
12
13 around context_traits => sub { shift->(@_), Namespaced };
14
15 sub parse {
16     my ($self, $ctx) = @_;
17
18     $ctx->skip_declarator;
19
20     my $pkg = outer_stack_peek $ctx->caller_file;
21     $ctx->shadow(sub {
22         Moose::Util::apply_all_roles($pkg, map {
23             $ctx->qualify_namespace($_)
24         } @_);
25     });
26 }
27
28 1;
29
30 =head1 NAME
31
32 MooseX::Declare::Syntax::Keyword::With - Apply roles within a class- or role-body
33
34 =head1 SYNOPSIS
35
36   use MooseX::Declare;
37
38   class ::Baz {
39       with 'Qux';
40       ...
41   }
42
43 =head1 DESCRIPTION
44
45 The C<with> keyword allows you to apply roles to the local class or role. It
46 differs from the C<with>-option of the C<class> and C<role> keywords in that it
47 applies the roles immediately instead of defering application until the end of
48 the class- or role-definition.
49
50 It also differs slightly from the C<with> provided by L<Moose|Moose> in that it
51 expands relative role names (C<::Foo>) according to the currenc C<namespace>.
52
53 =head1 CONSUMES
54
55 =over
56
57 =item * L<MooseX::Declare::Syntax::KeywordHandling>
58
59 =back
60
61 =head1 METHODS
62
63 =head2 parse
64
65   Object->parse(Object $context)
66
67 Will skip the declarator and make with C<with> invocation apply the set of
68 specified roles after possible C<namespace>-expanding has been done.
69
70 =head1 SEE ALSO
71
72 =over
73
74 =item * L<MooseX::Declare>
75
76 =item * L<MooseX::Declare::Syntax::Keyword::Namespace>
77
78 =back
79
80 =head1 AUTHOR, COPYRIGHT & LICENSE
81
82 See L<MooseX::Declare>
83
84 =cut