package MooseX::Declare::Syntax::Keyword::With; BEGIN { $MooseX::Declare::Syntax::Keyword::With::AUTHORITY = 'cpan:FLORA'; } { $MooseX::Declare::Syntax::Keyword::With::VERSION = '0.35'; } # ABSTRACT: Apply roles within a class- or role-body use Moose; use Moose::Util; use MooseX::Declare::Util qw( outer_stack_peek ); use aliased 'MooseX::Declare::Context::Namespaced'; use namespace::autoclean 0.09; with qw( MooseX::Declare::Syntax::KeywordHandling ); around context_traits => sub { shift->(@_), Namespaced }; sub parse { my ($self, $ctx) = @_; $ctx->skip_declarator; my $pkg = outer_stack_peek $ctx->caller_file; $ctx->shadow(sub { Moose::Util::apply_all_roles($pkg, map { $ctx->qualify_namespace($_) } @_); }); } 1; __END__ =pod =encoding utf-8 =head1 NAME MooseX::Declare::Syntax::Keyword::With - Apply roles within a class- or role-body =head1 SYNOPSIS use MooseX::Declare; class ::Baz { with 'Qux'; ... } =head1 DESCRIPTION The C keyword allows you to apply roles to the local class or role. It differs from the C-option of the C and C keywords in that it applies the roles immediately instead of defering application until the end of the class- or role-definition. It also differs slightly from the C provided by L in that it expands relative role names (C<::Foo>) according to the currenc C. =head1 METHODS =head2 parse Object->parse(Object $context) Will skip the declarator and make with C invocation apply the set of specified roles after possible C-expanding has been done. =head1 CONSUMES =over 4 =item * L =back =head1 SEE ALSO =over 4 =item * L =item * L =back =head1 AUTHORS =over 4 =item * Florian Ragwitz =item * Ash Berlin =item * Chas. J. Owens IV =item * Chris Prather =item * Dave Rolsky =item * Devin Austin =item * Hans Dieter Pearcey =item * Justin Hunter =item * Matt Kraai =item * Michele Beltrame =item * Nelo Onyiah =item * nperez =item * Piers Cawley =item * Rafael Kitover =item * Robert 'phaylon' Sedlacek =item * Stevan Little =item * Tomas Doran =item * Yanick Champoux =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2011 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. =cut