App::Grok::Parser::Pod6 - A Pod 6 backend for grok


grok documentation Contained in the grok distribution.

Index


Code Index:

NAME

Top

App::Grok::Parser::Pod6 - A Pod 6 backend for grok

METHODS

Top

new

This is the constructor. It currently takes no arguments.

render_file

Takes two arguments, a filename and the name of an output format. Returns a string containing the rendered document. It will die if there is an error.

render_string

Takes two arguments, a string and the name of an output format. Returns a string containing the rendered document. It will die if there is an error.

AUTHOR

Top

Hinrik Örn Sigurðsson, hinrik.sig@gmail.com

LICENSE AND COPYRIGHT

Top


grok documentation Contained in the grok distribution.

package App::Grok::Parser::Pod6;
BEGIN {
  $App::Grok::Parser::Pod6::AUTHORITY = 'cpan:HINRIK';
}
BEGIN {
  $App::Grok::Parser::Pod6::VERSION = '0.25';
}

# blows up if we use strict before this, damn source filter
use Perl6::Perldoc::Parser;

use strict;
use warnings FATAL => 'all';

sub new {
    my ($package, %self) = @_;
    return bless \%self, $package;
}

sub render_file {
    my ($self, $file, $format) = @_;

    if ($format !~ /^(?:ansi|text|xhtml)$/) {
        die __PACKAGE__ . " doesn't support the '$format' format";
    }
    eval "require Perl6::Perldoc::To::\u$format";
    die $@ if $@;

    my $method = "to_$format";
    return Perl6::Perldoc::Parser->parse($file, {all_pod=>'auto'})
                                 ->report_errors()
                                 ->$method();
}

sub render_string {
    my ($self, $string, $format) = @_;

    open my $handle, '<', \$string or die "Can't open input filehandle: $!";
    binmode $handle, ':utf8';
    my $result = $self->render_file($handle, $format);
    close $handle;
    return $result;
}

1;