/
Pod6.pm
78 lines (52 loc) · 1.74 KB
/
Pod6.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package App::Grok::Parser::Pod6;
# blows up if we use strict before this, damn source filter
use Perl6::Perldoc::Parser;
use strict;
use warnings;
our $VERSION = '0.18_02';
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: $!";
my $result = $self->render_file($handle, $format);
close $handle;
return $result;
}
1;
=encoding UTF-8
=head1 NAME
App::Grok::Parser::Pod6 - A Pod 6 backend for grok
=head1 METHODS
=head2 C<new>
This is the constructor. It currently takes no arguments.
=head2 C<render_file>
Takes two arguments, a filename and the name of an output format. Returns
a string containing the rendered document. It will C<die> if there is an
error.
=head2 C<render_string>
Takes two arguments, a string and the name of an output format. Returns
a string containing the rendered document. It will C<die> if there is an
error.
=head1 AUTHOR
Hinrik Örn Sigurðsson, L<hinrik.sig@gmail.com>
=head1 LICENSE AND COPYRIGHT
Copyright 2009 Hinrik Örn Sigurðsson
C<grok> is distributed under the terms of the Artistic License 2.0.
For more details, see the full text of the license in the file F<LICENSE>
that came with this distribution.
=cut