package B::Simple::Role::WithChildren;
use Moose::Role;
use MooseX::AttributeHelpers;

requires 'type';

has 'children' => (
    metaclass => 'Collection::Array',
    is        => 'rw',
    isa       => 'ArrayRef',
    default   => sub {[]},
    provides  => {
        # ...
    }
);

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

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

sub perl {
   my $self = shift; 
   (join " " => map { 
       blessed($_) ? $_->perl : $_ 
    } @{$self->children});
}

1;

__END__

=pod

=cut