| Perldoc documentation | Contained in the Perldoc distribution. |
Perldoc::Writer - Writer Class for Perldoc Parsers
package Perldoc::Writer;
Uniform writing interface.
XXX - Should be a mixin for Emitters.
Ingy döt Net <ingy@cpan.org>
Audrey wrote the original code for this parser.
Copyright (c) 2006. Ingy döt Net. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 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; }