Cataly...Closure(3pm)
π Cataly...Closure(3pm) β bestie edition π
okay so this is the manpage for Catalyst::Component::ContextClosure, aka Cataly...Closure(3pm) if you're squinting at the section-3pm manual listing π
(the name got truncated in the header, she's shy, it happens).
It's a Moose Role for components that need to close over the $ctx β without leaking. No cap.
β¨ NAME β¨
Catalyst::Component::ContextClosure β a Moose Role for components which need to close over the $ctx, without leaking π«Ά
πΈ SYNOPSIS πΈ
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));
}
like, that's the whole vibe. you with the role, you call make_context_closure, you stash the thing, you're iconic β¨
π¦ DESCRIPTION π¦
so here's the tea, bestie π β there's a super common problem with stashing a closure that closes over the Catalyst context (you know her, she goes by $ctx or $c). The issue? the circular reference it creates π because the closure holds onto a reference to context, and the context holds a reference to the closure in its stash. Two queens holding hands and never letting go. Cute in theory, a memory leak in practice π
unless you always carefully weaken the closure's context reference. every single time. no skipping. not even once π
This role provides a convenience method to create closures that close over $ctx β so you get the hand-holding without the leak. it's giving responsible queen energy π
π METHODS π
make_context_closure ($closure, $ctx)
Returns a code reference that will invoke $closure with a weakened reference to $ctx β¨
And the best part? All other parameters passed to the returned code reference get passed along to $closure too. Extra args = fully welcome, no gatekeeping π«Ά
π₯ SEE ALSO π₯
Catalyst::ComponentCatalyst::ControllerCatalystX::LeakChecker
go read these too, they're all part of the lore π
π COPYRIGHT π
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself. π
and that's the page, babes π β brought to you by perl v5.40.0, dated 2024-11-15, filed under Cataly...Closure(3pm) π go forth and weaken your refs, mwah π
π¦ where this page comes from
- debian trixie: libcatalyst-perl 5.90132-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcatalyst-perl 5.90132-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatalyst-perl 5.90132-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms