Aspect...::After(3pm)

πŸ“¦
version 1.04 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

Aspect::Advice::After β€” bestie, this one runs your code after a function gets called πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

use Aspect;

after {
    # Trace all returning calls to your module
    print STDERR "Called my function " . $_->sub_name . "\n";

    # Suppress exceptions AND alter the results to foo()
    if ( $_->short_name eq 'foo' ) {
        if ( $_->exception ) {
            $_->return_value(1);
        } else {
            $_->return_value( $_->return_value + 1 );
        }
    }

} call qr/^ MyModule::\w+ $/

πŸ’… DESCRIPTION πŸ’…

Okay so the after advice type is the one you reach for when you wanna run some code after a function is called β€” and the way that it does not care whether that function returned all normally or just fully threw an exception?? iconic. it handles both, no cap. πŸ”₯

You want after specifically when you need to potentially make multiple different changes to the returned value or the thrown exception β€” like, more than one thing going on, bestie.

If you only care about normally returned values, then use returning in the pointcut, because that excludes join points occurring due to exceptions. ✨

And if you only care about handling exceptions, use throwing in the pointcut, which excludes join points occurring due to normal return. 🌸


πŸ‘‘ AUTHORS πŸ‘‘

Adam Kennedy <adamk@cpan.org>


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.


k that's the whole page, mwah 🫢 this was documented by the lovely folks behind perl v5.36.0, dated 2023-07-02, and yes the page is literally titled Aspect...::After(3pm) β€” go off, filename πŸ’œ

πŸ“¦ where this page comes from