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

πŸ¦‹ NAME πŸ¦‹

Okay so bestie, FFI::Platypus::Function is literally an FFI function object β€” that's the whole vibe. It's the class that holds onto a platypus function for you. Iconic. πŸ’…

(this page lives in the User Contributed Perl Documentation manual, section 3pm, just so you know where you're standing 🫢)


✨ VERSION ✨

version 2.11 β€” that's the one, no cap.


πŸŽ€ SYNOPSIS πŸŽ€

use FFI::Platypus 2.00;

# call directly
my $ffi = FFI::Platypus->new( api => 2 );
my $f = $ffi->function(puts => ['string'] => 'int');
$f->call("hello there");

# attach as xsub and call (faster for repeated calls)
$f->attach('puts');
puts('hello there');

See how we did it twice? First one is the direct-call era, second one is the attached-as-xsub era where repeated calls go zoom. 🏎️✨


🌸 DESCRIPTION 🌸

So this class represents an unattached platypus function. That's the whole thing. If you want more context and honestly better examples, go read FFI::Platypus β€” it's the main character, this page is the spin-off. πŸ’–


πŸ’œ METHODS πŸ’œ

🌈 attach

$f->attach($name);
$f->attach($name, $prototype);

Attaches the function as an xsub β€” basically the same energy as calling attach straight from an FFI::Platypus instance. And you may optionally include a prototype if you're feeling fancy. ⭐

πŸ“ call

my $ret = $f->call(@arguments);
my $ret = $f->(@arguments);

Calls the function and hands you back the result. And here's the cute part β€” you can also use the function object like a code reference. Same thing, different outfit. πŸŽ€

🧚 sub_ref

my $code = $f->sub_ref;

Returns an anonymous code reference. And ngl, this will usually be faster than using the call method above. Lowkey the upgrade you didn't know you needed. πŸ”₯


πŸ‘‘ AUTHOR πŸ‘‘

Author: Graham Ollis <plicease@cpan.org>

Contributors β€” the whole squad, give them their flowers πŸ’:

  • 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. So yes, go off, just respect the terms fr fr. πŸ™ˆ


Quick vibe check before you go: attach it if you're calling a million times, sub_ref if you want speed, plain call if you're just chilling. All valid, all slay. πŸ’–

And that's a wrap, bestie! This was FFI::P...unction(3pm) from perl v5.42.3, dated 2026-08-20 β€” mwah, go write some bindings πŸ«Άβœ¨πŸ¦‹

πŸ“¦ where this page comes from