FFI::P...losure(3pm)

πŸ’– FFI::P...losure(3pm) β€” the whole vibe πŸ’–

okay so real talk, this is the man page for FFI::Platypus::Closure, straight out of the User Contributed Perl Documentation (section 3pm, iykyk) β€” yes the header gets truncated to FFI::P...losure which is giving "my name got cut off on the group chat" energy 😭 but she's fine, she's iconic.


✨ NAME ✨

FFI::Platypus::Closure β€” the Platypus closure object, periodt πŸ¦‹

πŸŽ€ VERSION πŸŽ€

version 2.11 πŸ’…

🌸 SYNOPSIS 🌸

create closure with OO interface

use FFI::Platypus::Closure;
my $closure = FFI::Platypus::Closure->new(sub { print "hello world\n" });

create closure from Platypus object

use FFI::Platypus 2.00;
my $ffi = FFI::Platypus->new( api => 2 );
my $closure = $ffi->closure(sub { print "hello world\n" });

use closure

$ffi->function(foo => ['()->void'] => 'void')->call($closure);

πŸ¦‹ DESCRIPTION πŸ¦‹

So this class is literally a Perl code reference that compiled code can call. That's the whole gig. When you make a closure object, you can hand it to any function that wants a function pointer β€” slay, versatility πŸ’….

But bestie, listen. Care needs to be taken with closures because compiled languages handle object lifetimes completely differently, and the vibes are not transferable. ⚠️ You have to make sure that if the compiled code is gonna call a closure, that closure object is still in scope somewhere, or has been made sticky. Otherwise... you might get a segment violation or some other mysterious crash. Not cute. Not the moment. πŸ˜­πŸ’€

fr fr do not skip the lifetime talk. segfaults do not care about your feelings.

🧚 CONSTRUCTOR 🧚

new

my $closure = FFI::Platypus::Closure->new($coderef);

Creates a shiny new closure object. $coderef must be a subroutine code reference β€” no exceptions, no substitutes, she's picky 🌈

⭐ METHODS ⭐

call

$closure->call(@arguments);
$closure->(@arguments);

Calls the closure from Perl space. Also works if you just treat the closure object like a code reference β€” same energy, different syntax, both ate 🫢

sticky

$closure->sticky;

Marks the closure sticky, meaning it won't be free'd even if all the references to the object fall out of scope. she's holding on and she's not letting go πŸ’œ

unstick

$closure->unstick;

Unmarks the closure as sticky. back to your regularly scheduled garbage collection ✨


πŸ‘‘ AUTHOR πŸ‘‘

Author: Graham Ollis <plicease@cpan.org>

Contributors (the whole squad, no cap):

  • Bakkiaraj Murugesan (bakkiaraj)
  • Dylan Cali (calid)
  • pipcet
  • Zaki Mughal (zmughal)
  • Fitz Elliott (felliott)
  • Vickenty Fesunov (vyf)
  • Gregor Herrmann (gregoa)
  • Shlomi Fish (shlomif)
  • Damyan Ivanov
  • Ilya Pavlov (Ilya33)
  • Petr PΓ­saΕ™ (ppisar)
  • Mohammad S Anwar (MANWAR)
  • HΓ₯kon HΓ¦gland (hakonhagland, HAKONH)
  • Meredith (merrilymeredith, MHOWARD)
  • Diab Jerius (DJERIUS)
  • Eric Brine (IKEGAMI)
  • szTheory
  • JosΓ© JoaquΓ­n Atria (JJATRIA)
  • Pete Houston (openstrike, HOUSTON)
  • Lukas Mai (MAUKE)

This software is copyright (c) 2015-2022 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. πŸ“


πŸŽ€ cute little sign-off: this gem was rendered by perl v5.42.3, dated 2026-08-20, and it lives at FFI::P...losure(3pm) in the User Contributed Perl Documentation. go forth and make closures responsibly, bestie πŸ’–βœ¨
πŸ“¦ where this page comes from