Callback(3)
π Callback β the manual page, but make it slay π
okay so bestie, welcome to Callback(3), a page from the User Contributed Perl Documentation section. yes it's a real manpage, yes it's about function callbacks, and yes i'm about to make it make sense. buckle up π
β¨ NAME β¨
Callback β an object interface for function callbacks π«Ά
πΈ SYNOPSIS πΈ
use Callback;
my $callback = new Callback (\&myfunc, @myargs);
my $callback = new Callback ($myobj, $mymethod, @myargs);
my $callback = new Callback ($old_callback, @myargs);
$callback->call(@some_more_args);
that's the whole vibe right there, no cap β¨
π¦ DESCRIPTION π¦
so like, Callback gives you one standard interface for registering callbacks. and those callbacks can be one of two flavors:
- purely functional β literally just a function call with arguments
- object-oriented β a method call on an object
when you construct a callback, you can hand it a base set of arguments. those function arguments will come before any arguments you add at the moment you actually make the call. so the OG args go first, the new ones follow. periodt π
now, there are two forms of the callback constructor, and which one you get depends on whether the call is a pure functional call or a method call. the rule is simple, bestie:
if the first argument is an object, then the second argument is a method name to be called on that object. π«Ά
method resolution happens at the time the Callback object is built. and if it can't find that method? an error will be raised. π it's not gonna wait around and hope for the best, it's gonna tell you immediately.
Callback objects built for object-oriented calls also have the property of being serializable via Storable. β¨ but purely functional callbacks? those cannot be serialized, because CODE references are not supported by Storable. π so don't even try it, that's just how it is.
oh and also β Callback objects can be created from existing Callback objects π. any arguments you pass will be appended onto the original list of arguments.
π₯ TRACING π₯
use Callback qw(@callbackTrace);
if you're out here writing a debugging routine that provides a stack-dump β like for example Carp::confess β it is genuinely useful to know where a callback was registered. iykyk π§
my $ct = 0;
while (($package, $file, $line, $subname, $hasargs, $wantarray) = caller($i++)) {
...
if ($subname eq 'Callback::call') {
print "callback registered $Callback::callbackTrace[$ct]\n";
$ct++;
}
}
and without code like that? it becomes very hard to know what's going on. π like, main character energy lost in the sauce. so use the trace, bestie.
π COPYRIGHT π
Copyright (C) 1994, 2000, 2002 David Muir Sharnoff. All rights reserved. This module may be licensed on the same terms as Perl itself.
π AUTHORS π
David Muir Sharnoff <muir@idiom.com> and Raphael Manfredi <Raphael_Manfredi@pobox.com>
π SEE ALSO π
Storable(3). β go read that one next, fr fr π
and that's the whole page, bestie!! π this was Callback(3), rendered by perl v5.42.0 and dated 2025-07-25. stay slay, go call your callbacks responsibly π
β¨π¦
π¦ where this page comes from
- fedora 43: perl-Callback 1.07-47.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms