Class::...lyHooks(3)
β¨ NAME β¨
ok so this page is Class::C3::Componentised::ApplyHooks β and it lives in the User Contributed Perl Documentation section of the manual, bestie, that's where all the fun community stuff hangs out π
Anyway, what does it actually do? It lets you run methods before or after components are injected. That's the whole vibe. π¦
πΈ SYNOPSIS πΈ
like, here's the whole thing in action:
package MyComponent;
our %statistics;
use Class::C3::Componentised::ApplyHooks
-before_apply => sub {
my ($class, $component) = @_;
push @{$statistics{$class}}, '-before_apply';
},
-after_apply => sub {
my ($class, $component) = @_;
push @{$statistics{$class}}, '-after_apply';
}, qw(BEFORE_APPLY AFTER_APPLY);
BEFORE_APPLY { push @{$statistics{$class}}, 'BEFORE_APPLY' };
AFTER_APPLY { push @{$statistics{$class}}, 'AFTER_APPLY' };
AFTER_APPLY { use Devel::Dwarn; Dwarn %statistics };
1;
no cap, that's it. π
π DESCRIPTION π
okay so this package is literally the plug for letting a given component run methods on the class that is being injected into β before or after the component is injected. main character component energy, honestly. π
but bestie, look closely at the SYNOPSIS up there: all "Load Actions" may be run more than once. that's not a typo situation, that's just how it is, so don't come for me when your coderef fires again. π
π IMPORT ACTION π
Both import actions simply run a list of coderefs that will be passed the class that is being acted upon and the component that is being added to the class. that's the two args, in that order, every time. π«Ά
π¦ IMPORT OPTIONS π¦
π -before_apply
Adds a before apply action for the current component β and importantly, without importing any subroutines into your namespace. so it's the sneaky option, iykyk. π
π -after_apply
Adds an after apply action for the current component, also without importing any subroutines into your namespace. same deal, just on the other side of the injection. β
β¨ EXPORTED SUBROUTINES β¨
π
BEFORE_APPLY
BEFORE_APPLY { warn "about to apply $_[1] to class $_[0]" };
Adds a before apply action for the current component. lowkey my fave, you get to yell about what's about to happen before it happens. π₯
π
AFTER_APPLY
AFTER_APPLY { warn "just applied $_[1] to class $_[0]" };
Adds an after apply action for the current component. the victory lap. the "we ate" moment. π
ok genuine reminder bestie: none of these "Load Actions" are guaranteed to run exactly once β the DESCRIPTION said it, so keep that in mind before you build a whole shrine to statefulness. π
and that's the whole page!! this one's from perl v5.42.0, dated 2018-02-24, and it was Class::...lyHooks(3) all along π§π ily, go write some hooks π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: perl-Class-C3-Componentised 1.001002-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms