GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Catalyst::Component::ContextClosure(3) User Contributed Perl Documentation Catalyst::Component::ContextClosure(3)

Catalyst::Component::ContextClosure - Moose Role for components which need to close over the $ctx, without leaking

    package MyApp::Controller::Foo;
    use Moose;
    use namespace::clean -except => 'meta';
    BEGIN {
        extends 'Catalyst::Controller';
        with 'Catalyst::Component::ContextClosure';
    }

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

A common problem with stashing a closure, that closes over the Catalyst context (often called $ctx or $c), is the circular reference it creates, as the closure holds onto a reference to context, and the context holds a reference to the closure in its stash. This creates a memory leak, unless you always carefully weaken the closures context reference.

This role provides a convenience method to create closures, that closes over $ctx.

Returns a code reference, that will invoke $closure with a weakened reference to $ctx. All other parameters to the returned code reference will be passed along to $closure.

Catalyst::Component

Catalyst::Controller

CatalystX::LeakChecker

This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
2020-07-26 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.