| 1 | package App::Grok::Parser::Pod5; | ||||||||||
| 2 | 17 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 17 | $App::Grok::Parser::Pod5::AUTHORITY = 'cpan:HINRIK'; | |||||||||
| 4 | } | ||||||||||
| 5 | { | ||||||||||
| 6 | 17 | $App::Grok::Parser::Pod5::VERSION = '0.26'; | |||||||||
| 7 | } | ||||||||||
| 8 | |||||||||||
| 9 | 17 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 17 | ▶ | use warnings FATAL => 'all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 17 | ▶ | use File::Temp qw<tempfile>; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 17 | my %formatter = ( | |||||||||
| 14 | text => 'Pod::Text', | ||||||||||
| 15 | ansi => 'Pod::Text::Ansi', | ||||||||||
| 16 | xhtml => 'Pod::Xhtml', | ||||||||||
| 17 | pod => 'Pod::Perldoc::ToPod', | ||||||||||
| 18 | ); | ||||||||||
| 19 | |||||||||||
| 20 | 16 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 21 | 16 | my ($package, %self) = @_; | |||||||||
| 22 | 16 | return bless \%self, $package; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 17 | ▶ | sub render_file { | ||||||||
|
Subroutine
render_file: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||
| 26 | 17 | my ($self, $file, $format) = @_; | |||||||||
| 27 | |||||||||||
| 28 | 17 | my $form = $formatter{$format}; | |||||||||
| 29 | 17 | ▶ | die __PACKAGE__ . " doesn't support the '$format' format" if !defined $form; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 17 | eval "require $form"; | |||||||||
| 31 | 17 | ▶ | die $@ if $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | 17 | my $done = ''; | |||||||||
| 34 | ## no critic (InputOutput::RequireBriefOpen) | ||||||||||
| 35 | 17 | ▶ | open my $out_fh, '>', \$done or die "Can't open output filehandle: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | |||||||||||
| 37 | 17 | ▶ | if ($form eq 'Pod::Perldoc::ToPod') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 2 | my ($temp_fh, $temp) = tempfile(); | |||||||||
| 39 | 2 | my $pod = do { local $/ = undef; scalar <$file> }; | |||||||||
| 40 | 2 | print $temp_fh $pod; | |||||||||
| 41 | 2 | $file = $temp; | |||||||||
| 42 | } | ||||||||||
| 43 | else { | ||||||||||
| 44 | 15 | ▶ | binmode $out_fh, ':utf8' if $form ne 'Pod::Perldoc::ToPod'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 17 | $form->new->parse_from_file($file, $out_fh); | |||||||||
| 48 | 17 | close $out_fh; | |||||||||
| 49 | 17 | return $done; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 15 | ▶ | sub render_string { | ||||||||
|
Subroutine
render_string: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 53 | 15 | my ($self, $string, $format) = @_; | |||||||||
| 54 | |||||||||||
| 55 | 15 | ▶ | open my $handle, '<', \$string or die "Can't open input filehandle: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 15 | my $result = $self->render_file($handle, $format); | |||||||||
| 57 | 15 | close $handle; | |||||||||
| 58 | 15 | return $result; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 17 | 1; | |||||||||
| 62 | |||||||||||
| 63 | =encoding utf8 | ||||||||||
| 64 | |||||||||||
| 65 | =head1 NAME | ||||||||||
| 66 | |||||||||||
| 67 | App::Grok::Parser::Pod5 - A Pod 5 backend for grok | ||||||||||
| 68 | |||||||||||
| 69 | =head1 METHODS | ||||||||||
| 70 | |||||||||||
| 71 | =head2 C<new> | ||||||||||
| 72 | |||||||||||
| 73 | This is the constructor. It currently takes no arguments. | ||||||||||
| 74 | |||||||||||
| 75 | =head2 C<render_file> | ||||||||||
| 76 | |||||||||||
| 77 | Takes two arguments, a filename and the name of an output format. Returns | ||||||||||
| 78 | a string containing the rendered document. It will C<die> if there is an | ||||||||||
| 79 | error. | ||||||||||
| 80 | |||||||||||
| 81 | =head2 C<render_string> | ||||||||||
| 82 | |||||||||||
| 83 | Takes two arguments, a string and the name of an output format. Returns | ||||||||||
| 84 | a string containing the rendered document. It will C<die> if there is an | ||||||||||
| 85 | error. | ||||||||||
| 86 | |||||||||||
| 87 | =head1 AUTHOR | ||||||||||
| 88 | |||||||||||
| 89 | Hinrik Örn Sigurðsson, L<hinrik.sig@gmail.com> | ||||||||||
| 90 | |||||||||||
| 91 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 92 | |||||||||||
| 93 | Copyright 2009 Hinrik Örn Sigurðsson | ||||||||||
| 94 | |||||||||||
| 95 | C<grok> is distributed under the terms of the Artistic License 2.0. | ||||||||||
| 96 | For more details, see the full text of the license in the file F<LICENSE> | ||||||||||
| 97 | that came with this distribution. | ||||||||||
| 98 | |||||||||||
| 99 | =cut | ||||||||||