Tangerine::Hook(3)
π Tangerine::Hook β a simple hook class β¨
okay bestie, welcome to Tangerine::Hook(3) π
this is a page from the User Contributed Perl Documentation, and honestly? she's giving "small class, big responsibility." let's get into it π«Ά
β¨ SYNOPSIS β¨
package MyHook;
use parent 'Tangerine::Hook';
use Tangerine::HookData;
use Tangerine::Occurence;
sub run {
my ($self, $s) = @_;
if ($s->[0] eq 'use' && $self->type eq 'compile' &&
$s->[1] && $s->[1] eq 'MyModule') {
return Tangerine::HookData->new(
modules => { MyModule => Tangerine::Occurence->new },
)
}
return
}
like... that's the whole vibe right there πΈ subclass it, write a run, return a Tangerine::HookData when you find something, return nothing when you don't. iconic.
π¦ DESCRIPTION π¦
Hooks are the workhorses of Tangerine, fr fr π they're the ones actually reading the real code and handing back a Tangerine::HookData when it's applicable. no hook, no info. periodt.
Every hook has a type, and it can be exactly one of 'package', 'compile' or 'runtime'. the caller sets it, and it decides what the hook is interested in π
Every hook should implement the "run" method. she gets passed an array reference holding the significant children (peep PPI::Statement if you wanna know what that means) of the currently parsed Perl statement π
The caller is expecting a Tangerine::HookData instance that tells her:
- what
"modules"of the requested"type"we found π - what
"hooks"the caller should register πͺ - what
"children"should be examined next πΆ
and here's the cute part β you can return either of those, or all of them at once. no rules, just vibes π
π METHODS π
π "type"
Returns or sets the hook type. she may be one of "package", "compile" or "runtime". that's it, that's the whole method, slay β¨
π "run"
This is the one Tangerine calls, passing an array reference containing the significant children of the currently parsed Perl statement. she returns a Tangerine::HookData instance π«Ά
β οΈ not me reminding you: every hook needs to implement this method. like, mandatory mandatory. no run, no hook, no cap π
π SEE ALSO π
"Tangerine""PPI::Statement""Tangerine::HookData"
go read them, they're all part of the same little universe πͺ
π AUTHOR π
Petr Ε abata <contyk@redhat.com>
π COPYRIGHT AND LICENSE π
Copyright (c) 2014-2016 Petr Ε abata
See LICENSE for licensing details.
and that's the page bestie!! π tysm for reading, this was Tangerine::Hook(3) from perl v5.42.0, dated 2025-07-25 β stay hydrated, read your licenses, and go write a hook that actually returns something π
π¦β¨
π¦ where this page comes from
- fedora 43: perl-Tangerine 0.23-27.fc43 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms