sub _as_generic { my($self, $type, $dot, $output) = @_; my $program = $self->{LAYOUT}; my $buffer; if ( ref $output || UNIVERSAL::isa(\$output, 'GLOB') ) { # $output is a filehandle or a scalar reference or something. # have to take a reference to a bare filehandle or run will # complain my $out = ref $output ? $output : \$output; my $pid = open my $pipe, '-|', qq[ echo $dot | $program $type ] or die $!; binmode $pipe; print $out <$pipe>; return; } elsif (defined $output) { # if it's defined it must be a filename so we'll write to it. system qq[ echo $dot | $program $type > $output ] ; return; } else { # but otherwise we capture output in a scalar my $pid = open my $pipe, '-|', qq[ echo $dot | $program $type ] or die $!; binmode $pipe; return do{ local $/; <$pipe> }; } }