Tangerine::Hook(3)

πŸ“¦
version 0.23 Β· 2 versions
, in fedora 43

πŸ’– 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 (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