Sub::DeferredPartial::Op::Unary - Unary operator.


Sub-DeferredPartial documentation Contained in the Sub-DeferredPartial distribution.

Index


Code Index:

NAME

Top

Sub::DeferredPartial::Op::Unary - Unary operator.

AUTHOR

Top

Steffen Goeldner <sgoeldner@cpan.org>

COPYRIGHT

Top


Sub-DeferredPartial documentation Contained in the Sub-DeferredPartial distribution.

package Sub::DeferredPartial::Op::Unary;

our $VERSION = '0.01';

use Sub::DeferredPartial(); @ISA = 'Sub::DeferredPartial';
use Carp;

our %Ops = map { $_ => eval "sub { $_ \$_[0] }" }
  qw( neg ! ~ abs sqrt exp log sin cos );
$Ops{neg} = eval "sub {  - \$_[0] }";
# -----------------------------------------------------------------------------
sub new
# -----------------------------------------------------------------------------
{
  my $class = shift;
  my $Op    = shift;
  my $Op1   = shift;

  confess "Operator '$Op' not implemented" unless exists $Ops{$Op};

  bless { Op => $Op, Op1 => $Op1 } => $class;
}
# -----------------------------------------------------------------------------
sub Apply
# -----------------------------------------------------------------------------
{
  my $self = shift;

  return ref( $self )->new( $self->{Op}, $self->{Op1}->Apply( @_ ) );
}
# -----------------------------------------------------------------------------
sub Eval
# -----------------------------------------------------------------------------
{
  my $self = shift;

  return $Ops{$self->{Op}}->( $self->{Op1}->Eval );
}
# -----------------------------------------------------------------------------
sub Free
# -----------------------------------------------------------------------------
{
  my $self = shift;

  return $self->{Op1}->Free;
}
# -----------------------------------------------------------------------------
sub Describe
# -----------------------------------------------------------------------------
{
  my $self = shift;

  return "( $self->{Op} $self->{Op1} )";
}
# -----------------------------------------------------------------------------
1;