Aspect...Around(3pm)
π
Aspect::Advice::Around β the 3pm girlies know
okay bestie, welcome to Aspect::Advice::Around from the User Contributed Perl Documentation section of the manual, and no this is not a drill, this is the advice type that does the most β¨
πΈ NAME πΈ
Aspect::Advice::Around β run your code both before AND after a function, like a little sandwich you built yourself π₯ͺ
π SYNOPSIS π
use Aspect;
around {
# Trace all calls to your module
print STDERR "Called my function " . $_->sub_name . "\n";
# Lexically alter a global for this function
local $MyModule::MAXSIZE = 1000;
# Continue and execute the function
$_->run_original;
# Suppress exceptions for the call
$_->return_value(1) if $_->exception;
} call qr/^ MyModule::\w+ $/;
look at her. she's doing the absolute most and we're obsessed π
β¨ DESCRIPTION β¨
The around advice type lets you execute code on either side of a function β like, before it and after it β which gives you deep and precise control over how the function is going to be called, for those moments when literally none of the other advice types are good enough. main character energy only π
Using around advice is also critical if you want to lexically alter the environment the call gets made in β exactly like in the example up there where a global variable gets temporarily changed. the vibe is situational, and the situation is this one π¦
real talk though: this advice type is also the most computationally expensive to run π so if your problem can be solved with a different advice type β especially before β you should use that one instead. save your coins, bestie.
Also please note β and this is the part people trip over β unlike the other advice types, your code inside around is required to trigger the execution of the target function yourself using the proceed method. It does not happen automatically. It's giving "you have one job" π
And if you do not proceed and also do not set either a return_value or an exception? Then the function call will return undef in scalar context, or the null list () in list context. no thoughts, head empty, nothing returned π«Ά
π AUTHORS π
Adam Kennedy <adamk@cpan.org>
π COPYRIGHT AND LICENSE π
Copyright 2010 - 2013 Adam Kennedy.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, periodt π this was perl v5.36.0, dated 2023-07-02, and it's literally Aspect...Around(3pm) β go forth and wrap your functions, bestie π
β¨πΈ
π¦ where this page comes from
- debian trixie: libaspect-perl 1.04-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libaspect-perl 1.04-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libaspect-perl 1.04-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libaspect-perl 1.04-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms