package B::Simple::Node::Apply;
use Moose;

extends 'B::Simple::Node';

has 'operator' => (
    is  => 'ro',
    isa => 'B::Simple::Node::Sym | B::Simple::Node::Op',
);

has 'operands' => (
    is  => 'ro',
    isa => 'ArrayRef',
);

sub pprint {
    my ($self, $indent) = @_;
    $indent ||= '';
    return "${indent}[ " 
         . $self->type 
         . " ]=(\n"
         . "${indent}  " 
         . $self->operator->pprint 
         . "\n"
         . (join "${indent}\n" => map { 
                blessed($_) 
                    ? $_->pprint(($indent . "  ")) 
                    : "${indent}  '$_'" 
             } @{$self->operands})
         . "\n${indent})";
}

sub sexpr {
    my $self = shift;
    "(" 
    . $self->type 
    . " " 
    . $self->operator->sexpr 
    . " "
    . (join " " => map { 
            blessed($_) ? $_->sexpr : $_ 
         } @{$self->operands})
    . ")"
}

sub perl {
    my $self = shift; 
    if ($self->operator->is_binary) {
        $self->operands->[0]->perl
        . ' '
        . $self->operator->perl         
        . ' '        
        . $self->operands->[1]->perl
        . '';   
    }
    else {
       $self->operator->perl 
       . '('
       . (join ", " => map { 
           blessed($_) ? $_->perl : $_ 
         } @{$self->operands})
       . ');';
    }
}

1;

__END__

=pod

=cut