Aspect::Pointcut::Highest - Pointcut for preventing recursive matching


Aspect documentation Contained in the Aspect distribution.

Index


Code Index:

NAME

Top

Aspect::Pointcut::Highest - Pointcut for preventing recursive matching

SYNOPSIS

Top

  use Aspect;

  # High-level creation
  my $pointcut1 = highest;

  # Manual creation
  my $pointcut2 = Aspect::Pointcut::Highest->new;

DESCRIPTION

Top

For aspects including timers and other Aspect::Advice::Around (around)-based advice, recursion can be significant problem.

The highest pointcut solves this problem by matching only on the highest invocation of a function. If the function is called again recursively within the first call, at any depth, the deeper calls will be not match and the advice will not be executed.

AUTHORS

Top

Adam Kennedy <adamk@cpan.org>

Marcel Grünauer <marcel@cpan.org>

Ran Eilam <eilara@cpan.org>

COPYRIGHT

Top


Aspect documentation Contained in the Aspect distribution.

package Aspect::Pointcut::Highest;

use strict;
use warnings;
use Carp                               ();
use Scalar::Util                       ();
use Params::Util                       ();
use Aspect::Guard                      ();
use Aspect::Pointcut                   ();

our $VERSION = '1.01';
our @ISA     = 'Aspect::Pointcut';





######################################################################
# Constructor Methods

sub new {
	bless [ ], $_[0];
}





######################################################################
# Weaving Methods

# The highest pointcut is a run-time only pointcut
sub curry_weave {
	return;
}

# Call pointcuts curry away to null, because they are the basis
# for which methods to hook in the first place. Any method called
# at run-time has already been checked.
sub curry_runtime {
	bless [ 0 ], $_[0];
}





######################################################################
# Runtime Methods

sub compile_runtime {
	my $depth = 0;
	return sub {
		$_->{highest} = Aspect::Guard->new( sub { $depth-- } );
		return ! $depth++;
	};
}

1;

__END__