stop using Moo as a test package
[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
5bb1a415 28 $class = $meta->name;
29 $class->new($app, $args);
30}
31
32sub test : Local ActionClass('+TestApp::Action::TestMyAction') {
33 my ($self, $c) = @_;
8f6cebb2 34 $c->res->header('X-Component-Name-Controller', $self->catalyst_component_name);
5bb1a415 35 $c->res->body('It works');
36}
37
38__PACKAGE__->meta->make_immutable;
39