Switch to catalyst_component_name
[catagits/Catalyst-Runtime.git] / t / lib / TestApp / Controller / Anon.pm
CommitLineData
5bb1a415 1package Anon::Trait;
2use Moose::Role -traits => 'MethodAttributes'; # Needed for role composition to work correctly with anon classes.
3
4after test => sub {
5 my ($self, $c) = @_;
6 $c->res->header('X-Anon-Trait-Applied', 1);
7};
8
9no Moose::Role;
10
11package TestApp::Controller::Anon;
12use Moose;
13use Moose::Util qw/find_meta/;
14use namespace::clean -except => 'meta';
15BEGIN { extends 'Catalyst::Controller' };
16
17sub COMPONENT { # Don't do this yourself, use CatalystX::Component::Traits!
18 my ($class, $app, $args) = @_;
19
20 my $meta = $class->meta->create_anon_class(
21 superclasses => [ $class->meta->name ],
22 roles => ['Anon::Trait'],
23 cache => 1,
24 );
25 # Special move as the methodattributes trait has changed our metaclass..
26 $meta = find_meta($meta->name);
27
28 $meta->add_method('meta' => sub { $meta });
29 $class = $meta->name;
30 $class->new($app, $args);
31}
32
33sub test : Local ActionClass('+TestApp::Action::TestMyAction') {
34 my ($self, $c) = @_;
8f6cebb2 35 $c->res->header('X-Component-Name-Controller', $self->catalyst_component_name);
5bb1a415 36 $c->res->body('It works');
37}
38
39__PACKAGE__->meta->make_immutable;
40