File: ContextClosure.pm

package info (click to toggle)
libcatalyst-perl 5.80025-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,104 kB
  • ctags: 1,183
  • sloc: perl: 15,616; makefile: 7
file content (29 lines) | stat: -rw-r--r-- 664 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
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');
}

__PACKAGE__->meta->make_immutable;

1;