Commit | Line | Data |
5bb1a415 |
1 | package Anon::Trait; |
2 | use Moose::Role -traits => 'MethodAttributes'; # Needed for role composition to work correctly with anon classes. |
3 | |
4 | after test => sub { |
5 | my ($self, $c) = @_; |
6 | $c->res->header('X-Anon-Trait-Applied', 1); |
7 | }; |
8 | |
9 | no Moose::Role; |
10 | |
11 | package TestApp::Controller::Anon; |
12 | use Moose; |
13 | use Moose::Util qw/find_meta/; |
14 | use namespace::clean -except => 'meta'; |
15 | BEGIN { extends 'Catalyst::Controller' }; |
16 | |
17 | sub 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 | |
32 | sub 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 | |