Perldoc::Reader - Reader Class for Perldoc Parsers


Perldoc documentation Contained in the Perldoc distribution.

Index


Code Index:

NAME

Top

Perldoc::Reader - Reader Class for Perldoc Parsers

SYNOPSIS

Top

    package Perldoc::Reader;

DESCRIPTION

Top

Uniform reading interface.

XXX - Should be a mixin for Parsers.

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::Reader;
use Perldoc::Base -Base;

field 'string';
field 'stringref';
field 'filehandle';
field 'filepath';

sub all {
    for my $source (qw(string stringref filepath filehandle)) {
        if (defined $self->{$source}) {
            my $method = "_all_$source";
            return $self->$method();
        }
    }
    die "No input to read";
}

sub _all_string {
    return $self->string;
}

sub _all_stringref {
    return ${$self->stringref};
}

sub _all_filepath {
    my $filepath = $self->filepath;
    open my $input, $filepath
      or die "Can't open '$filepath' for input:\n$!";
    local $/;
    return <$input>
}

sub _all_filehandle {
    my $filehandle = $self->filehandle;
    local $/;
    return <$filehandle>;
}