File Coverage

blib/lib/MooseX/Declare/Syntax/Keyword/With.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 29 29 100.0


line stmt bran cond sub pod time code
1             package MooseX::Declare::Syntax::Keyword::With;
2             # ABSTRACT: Apply roles within a class- or role-body
3              
4             our $VERSION = '0.43';
5              
6 24     24   14006 use Moose;
  24         37  
  24         147  
7 24     24   104216 use Moose::Util;
  24         33  
  24         166  
8 24     24   11666 use MooseX::Declare::Util qw( outer_stack_peek );
  24         51  
  24         80  
9 24     24   3494 use aliased 'MooseX::Declare::Context::Namespaced';
  24         32  
  24         134  
10 24     24   1813 use namespace::autoclean;
  24         36  
  24         84  
11              
12             #pod =head1 SYNOPSIS
13             #pod
14             #pod use MooseX::Declare;
15             #pod
16             #pod class ::Baz {
17             #pod with 'Qux';
18             #pod ...
19             #pod }
20             #pod
21             #pod =head1 DESCRIPTION
22             #pod
23             #pod The C<with> keyword allows you to apply roles to the local class or role. It
24             #pod differs from the C<with>-option of the C<class> and C<role> keywords in that it
25             #pod applies the roles immediately instead of deferring application until the end of
26             #pod the class- or role-definition.
27             #pod
28             #pod It also differs slightly from the C<with> provided by L<Moose|Moose> in that it
29             #pod expands relative role names (C<::Foo>) according to the current C<namespace>.
30             #pod
31             #pod =head1 CONSUMES
32             #pod
33             #pod =for :list
34             #pod * L<MooseX::Declare::Syntax::KeywordHandling>
35             #pod
36             #pod =cut
37              
38             with qw(
39             MooseX::Declare::Syntax::KeywordHandling
40             );
41              
42             around context_traits => sub { shift->(@_), Namespaced };
43              
44             #pod =method parse
45             #pod
46             #pod Object->parse(Object $context)
47             #pod
48             #pod Will skip the declarator and make with C<with> invocation apply the set of
49             #pod specified roles after possible C<namespace>-expanding has been done.
50             #pod
51             #pod =cut
52              
53             sub parse {
54 10     10 1 24 my ($self, $ctx) = @_;
55              
56 10         77 $ctx->skip_declarator;
57              
58 10         708 my $pkg = outer_stack_peek $ctx->caller_file;
59             $ctx->shadow(sub {
60             Moose::Util::apply_all_roles($pkg, map {
61 10     10   238 $ctx->qualify_namespace($_)
  13         75  
62             } @_);
63 10         117 });
64             }
65              
66             #pod =head1 SEE ALSO
67             #pod
68             #pod =for :list
69             #pod * L<MooseX::Declare>
70             #pod * L<MooseX::Declare::Syntax::Keyword::Namespace>
71             #pod
72             #pod =cut
73              
74             1;
75              
76             __END__
77              
78             =pod
79              
80             =encoding UTF-8
81              
82             =head1 NAME
83              
84             MooseX::Declare::Syntax::Keyword::With - Apply roles within a class- or role-body
85              
86             =head1 VERSION
87              
88             version 0.43
89              
90             =head1 SYNOPSIS
91              
92             use MooseX::Declare;
93              
94             class ::Baz {
95             with 'Qux';
96             ...
97             }
98              
99             =head1 DESCRIPTION
100              
101             The C<with> keyword allows you to apply roles to the local class or role. It
102             differs from the C<with>-option of the C<class> and C<role> keywords in that it
103             applies the roles immediately instead of deferring application until the end of
104             the class- or role-definition.
105              
106             It also differs slightly from the C<with> provided by L<Moose|Moose> in that it
107             expands relative role names (C<::Foo>) according to the current C<namespace>.
108              
109             =head1 METHODS
110              
111             =head2 parse
112              
113             Object->parse(Object $context)
114              
115             Will skip the declarator and make with C<with> invocation apply the set of
116             specified roles after possible C<namespace>-expanding has been done.
117              
118             =head1 CONSUMES
119              
120             =over 4
121              
122             =item *
123              
124             L<MooseX::Declare::Syntax::KeywordHandling>
125              
126             =back
127              
128             =head1 SEE ALSO
129              
130             =over 4
131              
132             =item *
133              
134             L<MooseX::Declare>
135              
136             =item *
137              
138             L<MooseX::Declare::Syntax::Keyword::Namespace>
139              
140             =back
141              
142             =head1 AUTHOR
143              
144             Florian Ragwitz <rafl@debian.org>
145              
146             =head1 COPYRIGHT AND LICENSE
147              
148             This software is copyright (c) 2008 by Florian Ragwitz.
149              
150             This is free software; you can redistribute it and/or modify it under
151             the same terms as the Perl 5 programming language system itself.
152              
153             =cut