App-PlUtils

 view release on metacpan or  search on metacpan

script/plhtml  view on Meta::CPAN

#!perl

our $DATE = '2020-04-29'; # DATE
our $VERSION = '0.122'; # VERSION

use 5.010;
use strict;
use warnings;

use App::PlUtils;
use File::Which;
use Perinci::CmdLine::Any;

our %SPEC;
$SPEC{plhtml} = {
    v => 1.1,
    summary => 'Render POD as HTML then show in browser',
    description => <<'_',

This function renders a POD document using <prog:pod2html>, then open a browser
to show the resulting HTML document.

_
    args => {
        file => $App::PlUtils::arg_file_single,
    },
    deps => {
        prog => 'pod2html',
    },
};
sub plhtml {
    require Browser::Open;
    require File::Temp;
    require File::Util::Tempdir;

    my %args = @_;

    my $file = $args{file};
    if (!(-f $file) && $file !~ m!/!) {
        # search file in PATH
        $file = which($file);
    }
    unless (-f $file) {
        return [404, "No such file '$args{file}'"];
    }

    my $tmpdir = File::Util::Tempdir::get_tempdir();
    my $cachedir = File::Temp::tempdir(CLEANUP => 1);
    my $name = $file; $name =~ s!.+/!!;
    my ($infh, $infile) = File::Temp::tempfile(
        "$name.XXXXXXXX", DIR=>$tmpdir, SUFFIX=>".pod");
    my $outfile = "$infile.html";
    system(
        "pod2html",
        "--infile", $file,
        "--outfile", $outfile,
        "--cachedir", $cachedir,
    );
    return [500, "Can't pod2html: $!"] if $?;
    my $err = Browser::Open::open_browser("file:$outfile");
    return [500, "Can't open browser"] if $err;
    [200];
}

Perinci::CmdLine::Any->new(
    url => '/main/plhtml',
    read_config => 0,
    read_env => 0,
)->run;

# ABSTRACT: Render POD as HTML then show in browser
# PODNAME: plhtml

__END__

=pod

=encoding UTF-8

=head1 NAME

plhtml - Render POD as HTML then show in browser

=head1 VERSION

This document describes version 0.122 of plhtml (from Perl distribution App-PlUtils), released on 2020-04-29.

=head1 SYNOPSIS

Basic usage:

 % plhtml <perl-script>

=head1 DESCRIPTION

This function renders a POD document using L<pod2html>, then open a browser
to show the resulting HTML document.

=head1 OPTIONS

C<*> marks required options.

=head2 Main options



( run in 0.932 second using v1.01-cache-2.11-cpan-39bf76dae61 )