Aspect::Advice::After(3pm)

Aspect::Advice::After3pm

Execute code after a function is called

Usage

  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+ $/

Overview

The "after" advice type is used to execute code after a function is called, regardless of whether or not the function returned normally or threw an exception.

The "after" advice type should be used when you need to potentially make multiple different changes to the returned value or the thrown exception.

If you only care about normally returned values you should use "returning" in the pointcut to exclude join points occuring due to exceptions.

If you only care about handling exceptions you should use "throwing" in the pointcut to exclude join points occuring due to normal return.

Releases

7 releases since Debian 7 (Wheezy); the text changed 4 times.

  1. 7
  2. 8–10
  3. 11
  4. 12
  5. 13

Authors

Adam Kennedy <[email protected]>

From libaspect-perl 1.04-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.