Aspect::Pointcut::Wantarray - A pointcut for the run-time wantarray context


Aspect documentation Contained in the Aspect distribution.

Index


Code Index:

NAME

Top

Aspect::Pointcut::Wantarray - A pointcut for the run-time wantarray context

SYNOPSIS

Top

  use Aspect;

  # High-level creation
  my $pointcut1 = wantlist | wantscalar | wantvoid;

  # Manual creation
  my $pointcut2 = Padre::Pointcut::Or->new(
    Padre::Pointcut::Wantarray->new( 1 ),     # List
    Padre::Pointcut::Wantarray->new( 0 ),     # Scalar
    Padre::Pointcut::Wantarray->new( undef ), # Void
  );

DESCRIPTION

Top

The Aspect::Pointcut::Wantarray pointcut allows the creation of aspects that only trap calls made in a particular calling context (list, scalar or void).

AUTHORS

Top

Adam Kennedy <adamk@cpan.org>

COPYRIGHT

Top


Aspect documentation Contained in the Aspect distribution.

package Aspect::Pointcut::Wantarray;

use strict;
use warnings;
use Carp             ();
use Aspect::Pointcut ();

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

use constant VOID   => 1;
use constant SCALAR => 2;
use constant LIST   => 3;





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

sub new {
	return bless [
		LIST,
		'$Aspect::POINT->{wantarray}',
	], $_[0] if $_[1];

	return bless [
		SCALAR,
		'defined $Aspect::POINT->{wantarray} and not $Aspect::POINT->{wantarray}',
	], $_[0] if defined $_[1];

	return bless [
		VOID,
		'not defined $Aspect::POINT->{wantarray}',
	], $_[0];
}





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

# This is a run-time only pointcut of no value at weave time
sub curry_weave {
	return;
}

# For wantarray pointcuts we keep the original
sub curry_runtime {
	return $_[0];
}

sub compile_runtime {
	$_[0]->[1];
}





######################################################################
# Optional XS Acceleration

BEGIN {
	local $@;
	eval <<'END_PERL';
use Class::XSAccessor::Array 1.08 {
	replace => 1,
	getters => {
		'compile_runtime' => 1,
	},
};
END_PERL
}

1;

__END__