| 1 | # Copyright 2008, 2009, 2010, 2013, 2015 Kevin Ryde | ||||||||||||
| 2 | |||||||||||||
| 3 | # HTML-FormatExternal is free software; you can redistribute it and/or | ||||||||||||
| 4 | # modify it under the terms of the GNU General Public License as published | ||||||||||||
| 5 | # by the Free Software Foundation; either version 3, or (at your option) any | ||||||||||||
| 6 | # later version. | ||||||||||||
| 7 | # | ||||||||||||
| 8 | # HTML-FormatExternal is distributed in the hope that it will be useful, but | ||||||||||||
| 9 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||
| 10 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||
| 11 | # for more details. | ||||||||||||
| 12 | # | ||||||||||||
| 13 | # You should have received a copy of the GNU General Public License along | ||||||||||||
| 14 | # with HTML-FormatExternal. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||
| 15 | |||||||||||||
| 16 | package HTML::FormatText::Netrik; | ||||||||||||
| 17 | 1 | ▶ | use 5.006; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 1 | ▶ | use URI::file; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 1 | ▶ | use HTML::FormatExternal; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 1 | our @ISA = ('HTML::FormatExternal'); | |||||||||||
| 23 | |||||||||||||
| 24 | # uncomment this to run the ### lines | ||||||||||||
| 25 | # use Smart::Comments; | ||||||||||||
| 26 | |||||||||||||
| 27 | 1 | our $VERSION = 26; | |||||||||||
| 28 | |||||||||||||
| 29 | 1 | ▶ | use constant DEFAULT_LEFTMARGIN => 3; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 30 | 1 | ▶ | use constant DEFAULT_RIGHTMARGIN => 77; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | |||||||||||||
| 32 | # as of Netrik 1.16.1 there's no input charsets, so entitize | ||||||||||||
| 33 | 1 | ▶ | use constant _WIDE_INPUT_CHARSET => 'entitize'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 34 | |||||||||||||
| 35 | # --dump here as otherwise netrik runs the curses interface on the initial | ||||||||||||
| 36 | # page given in ~/.netrikrc. If there's no such file then it prints a | ||||||||||||
| 37 | # little "usage: netrik html-file" but there's nothing interesting in that. | ||||||||||||
| 38 | # Option '-' to read stdin which _run_version() makes /dev/null. | ||||||||||||
| 39 | # | ||||||||||||
| 40 | # --bw avoids warnings on a monochrome terminal. Don't want colours for any | ||||||||||||
| 41 | # usage message etc anyway. | ||||||||||||
| 42 | # | ||||||||||||
| 43 | 5 | ▶ | sub program_full_version { | ||||||||||
|
Subroutine
program_full_version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 44 | 5 | my ($self_or_class) = @_; | |||||||||||
| 45 | 5 | return $self_or_class->_run_version (['netrik','--bw','--version','--dump','-'], '2>&1'); | |||||||||||
| 46 | } | ||||||||||||
| 47 | 2 | ▶ | sub program_version { | ||||||||||
|
Subroutine
program_version: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||
| 48 | 2 | my ($self_or_class) = @_; | |||||||||||
| 49 | 2 | my $version = $self_or_class->program_full_version; | |||||||||||
| 50 | 2 | ▶ | if (! defined $version) { return undef; } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | |||||||||||||
| 52 | # as of netrik 1.16.1 there doesn't seem to be any option that prints the | ||||||||||||
| 53 | # version number, it's possible it's not compiled into the binary at all | ||||||||||||
| 54 | 0 | return '(not reported)'; | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | 0 | ▶ | sub _make_run { | ||||||||||
|
Subroutine
_make_run: not called CC=4 SCAR=30.0
| |||||||||||||
| 58 | 0 | my ($class, $input_filename, $options) = @_; | |||||||||||
| 59 | ### Netrik _make_run() ... | ||||||||||||
| 60 | |||||||||||||
| 61 | # if (! $options->{'ansi_colour'}) { | ||||||||||||
| 62 | # push @command, '--bw'; | ||||||||||||
| 63 | # } | ||||||||||||
| 64 | |||||||||||||
| 65 | # COLUMNS influences the curses tigetnum("cols") used under --term-width. | ||||||||||||
| 66 | # Slightly hairy, but it has the right effect. | ||||||||||||
| 67 | 0 | ▶ | if (defined $options->{'_width'}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | 0 | $options->{'ENV'}->{'COLUMNS'} = $options->{'_width'}; | |||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | # netrik 1.16.1 does a curses setupterm() even for a --dump so it must | ||||||||||||
| 72 | # have a TERM. Think "TERM=dumb" is known to any termcap or terminfo. | ||||||||||||
| 73 | # But leave a user's existing TERM setting alone in case it does something | ||||||||||||
| 74 | # good for netrik, though you'd hope it wouldn't affect --dump. | ||||||||||||
| 75 | # | ||||||||||||
| 76 | 0 | ▶ | unless ($ENV{'TERM'}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 77 | 0 | $options->{'ENV'}->{'TERM'} = 'dumb'; | |||||||||||
| 78 | } | ||||||||||||
| 79 | |||||||||||||
| 80 | # --bw to avoid warnings when on a monochrome terminal. Don't want | ||||||||||||
| 81 | # colours in a dump anyway. (Option --bw is in options.txt and the | ||||||||||||
| 82 | # README.) | ||||||||||||
| 83 | # | ||||||||||||
| 84 | # 'netrik_options' not documented ... | ||||||||||||
| 85 | return ([ 'netrik', '--dump', '--bw', | ||||||||||||
| 86 | 0 | ▶ | @{$options->{'netrik_options'} || []}, | ||||||||||
|
Condition0%0/2
$options->{'netrik_options'} || []
MC/DC0%0/1
$options->{'netrik_options'} || []
$options->{'netrik_options'}
Truth table0%0/2
A
A= $options->{'netrik_options'}
| |||||||||||||
| 87 | |||||||||||||
| 88 | # netrik interprets "%" in the input filename as URI style %ff hex | ||||||||||||
| 89 | # encodings. And it rejects filenames with non-URI chars such as | ||||||||||||
| 90 | # "-" (except for "-" alone which means stdin). Turn unusual | ||||||||||||
| 91 | # filenames like "%" or "-" into full file:// using URI::file. | ||||||||||||
| 92 | URI::file->new_abs($input_filename)->as_string, | ||||||||||||
| 93 | ]); | ||||||||||||
| 94 | } | ||||||||||||
| 95 | |||||||||||||
| 96 | 1 | 1; | |||||||||||
| 97 | __END__ | ||||||||||||