Perldoc::Writer - Writer Class for Perldoc Parsers


Perldoc documentation Contained in the Perldoc distribution.

Index


Code Index:

NAME

Top

Perldoc::Writer - Writer Class for Perldoc Parsers

SYNOPSIS

Top

    package Perldoc::Writer;

DESCRIPTION

Top

Uniform writing interface.

XXX - Should be a mixin for Emitters.

AUTHOR

Top

Ingy döt Net <ingy@cpan.org>

Audrey wrote the original code for this parser.

COPYRIGHT

Top


Perldoc documentation Contained in the Perldoc distribution.

package Perldoc::Writer;
use Perldoc::Base -Base;

field 'stringref';
field 'filehandle';
field 'filepath';
field 'handle' => -init => '$self->open_handle';

sub print {
    for my $target (qw(stringref filepath filehandle)) {
        if (defined $self->{$target}) {
            my $method = "_print_$target";
            return $self->$method(@_);
        }
    }
    die "No destination for Perldoc::Writer to write to";
}

sub _print_stringref {
    ${$self->stringref} .= shift(@_);
}

sub _print_filepath {
    my $filehandle = $self->handle;
    print $filehandle shift(@_);
}

sub _print_filehandle {
    my $filehandle = $self->filehandle;
    print $filehandle shift(@_);
}

sub open_handle {
    my $filepath = $self->filepath;
    $filepath = "> $filepath"
      unless $filepath =~ /^>/;
    open my $ouput, $filepath
      or die "Can't open '$filepath' for output:\n$!";
    return $filepath;
}