File: ContextClosure.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 (34 lines) | stat: -rw-r--r-- 768 bytes parent folder | download | duplicates (6)
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
package TestApp::Controller::ContextClosure;

use Moose;

BEGIN {
    extends 'Catalyst::Controller';
    with 'Catalyst::Component::ContextClosure';
}

sub normal_closure : Local {
    my ($self, $ctx) = @_;
    $ctx->stash(closure => sub {
        $ctx->response->body('from normal closure');
    });
    $ctx->response->body('stashed normal closure');
}

sub context_closure : Local {
    my ($self, $ctx) = @_;
    $ctx->stash(closure => $self->make_context_closure(sub {
        my ($ctx) = @_;
        $ctx->response->body('from context closure');
    }, $ctx));
    $ctx->response->body('stashed context closure');
}

sub non_closure : Local {
    my ($self, $ctx) = @_;
    $ctx->stash(no_closure => "not a closure");
}

__PACKAGE__->meta->make_immutable;

1;