Add Catalyst::Component::ContextClosure.
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Component / ContextClosure.pm
diff --git a/lib/Catalyst/Component/ContextClosure.pm b/lib/Catalyst/Component/ContextClosure.pm
new file mode 100644 (file)
index 0000000..0aaf8bf
--- /dev/null
@@ -0,0 +1,14 @@
+package Catalyst::Component::ContextClosure;
+
+use Moose::Role;
+use Scalar::Util 'weaken';
+use namespace::autoclean;
+
+sub make_context_closure {
+    my ($self, $closure, $ctx) = @_;
+    my $weak_ctx = $ctx;
+    weaken $ctx;
+    return sub { $closure->($ctx, @_) };
+}
+
+1;