File: Anon.pm

package info (click to toggle)
libcatalyst-perl 5.90132-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: perl: 11,061; makefile: 7
file content (39 lines) | stat: -rw-r--r-- 1,122 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package Anon::Trait;
use Moose::Role -traits => 'MethodAttributes'; # Needed for role composition to work correctly with anon classes.

after test => sub {
    my ($self, $c) = @_;
    $c->res->header('X-Anon-Trait-Applied', 1);
};

no Moose::Role;

package TestApp::Controller::Anon;
use Moose;
use Moose::Util qw/find_meta/;
use namespace::clean -except => 'meta';
BEGIN { extends 'Catalyst::Controller' };

sub COMPONENT { # Don't do this yourself, use CatalystX::Component::Traits!
    my ($class, $app, $args) = @_;

    my $meta = $class->meta->create_anon_class(
            superclasses => [ $class->meta->name ],
            roles        => ['Anon::Trait'],
            cache        => 1,
    );
    # Special move as the methodattributes trait has changed our metaclass..
    $meta = find_meta($meta->name);

    $class = $meta->name;
    $class->new($app, $args);
}

sub test : Local ActionClass('+TestApp::Action::TestMyAction') {
    my ($self, $c) = @_;
    $c->res->header('X-Component-Name-Controller', $self->catalyst_component_name);
    $c->res->body('It works');
}

__PACKAGE__->meta->make_immutable;