2 use Moose::Role -traits => 'MethodAttributes'; # Needed for role composition to work correctly with anon classes.
6 $c->res->header('X-Anon-Trait-Applied', 1);
11 package TestApp::Controller::Anon;
13 use Moose::Util qw/find_meta/;
14 use namespace::clean -except => 'meta';
15 BEGIN { extends 'Catalyst::Controller' };
17 sub COMPONENT { # Don't do this yourself, use CatalystX::Component::Traits!
18 my ($class, $app, $args) = @_;
20 my $meta = $class->meta->create_anon_class(
21 superclasses => [ $class->meta->name ],
22 roles => ['Anon::Trait'],
25 # Special move as the methodattributes trait has changed our metaclass..
26 $meta = find_meta($meta->name);
28 $meta->add_method('meta' => sub { $meta });
30 $class->new($app, $args);
33 sub test : Local ActionClass('+TestApp::Action::TestMyAction') {
35 $c->res->header('X-Component-Name-Controller', $self->_component_name);
36 $c->res->body('It works');
39 __PACKAGE__->meta->make_immutable;