| 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::Lynx; | ||||||||||||||||||||
| 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 | 1 | our $VERSION = 26; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 1 | ▶ | use constant DEFAULT_LEFTMARGIN => 2; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | 1 | ▶ | use constant DEFAULT_RIGHTMARGIN => 72; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | # return true if the "-nomargins" option is available (new in Lynx | ||||||||||||||||||||
| 30 | # 2.8.6dev.12 from June 2005) | ||||||||||||||||||||
| 31 | 1 | ▶ | use constant::defer _have_nomargins => sub { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||
| 32 | 1 | my ($class) = @_; | |||||||||||||||||||
| 33 | 1 | my $help = $class->_run_version (['lynx', '-help']); | |||||||||||||||||||
| 34 | 1 | ▶ | return (defined $help && $help =~ /-nomargins/); | ||||||||||||||||||
|
Condition33%1/3
defined $help && $help =~ /-nomargins/
MC/DC0%0/2
defined $help && $help =~ /-nomargins/
defined $help
$help =~ /-nomargins/
Truth table33%1/3
A && B
A= defined $helpB= $help =~ /-nomargins/
| |||||||||||||||||||||
| 35 | 1 | }; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 5 | ▶ | sub program_full_version { | ||||||||||||||||||
|
Subroutine
program_full_version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 38 | 5 | my ($self_or_class) = @_; | |||||||||||||||||||
| 39 | 5 | return $self_or_class->_run_version (['lynx', '-version']); | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | 2 | ▶ | sub program_version { | ||||||||||||||||||
|
Subroutine
program_version: called CC=3 SCAR=14.2
Pod
documented
| |||||||||||||||||||||
| 42 | 2 | my ($self_or_class) = @_; | |||||||||||||||||||
| 43 | 2 | my $version = $self_or_class->program_full_version; | |||||||||||||||||||
| 44 | 2 | ▶ | if (! defined $version) { return undef; } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | # eg. "Lynx Version 2.8.7dev.10 (21 Sep 2008)" | ||||||||||||||||||||
| 47 | 0 | ▶ | $version =~ /^Lynx Version (.*?) \(/i | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | or $version =~ /^(.*)/; # whole first line if format not recognised | ||||||||||||||||||||
| 49 | 0 | return $1 . substr($version,0,0); # retain taintedness | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | sub _make_run { | ||||||||||||||||||
|
Subroutine
_make_run: not called CC=8 SCAR=42.8
| |||||||||||||||||||||
| 53 | 0 | my ($class, $input_filename, $options) = @_; | |||||||||||||||||||
| 54 | 0 | my @command = ('lynx', '-dump', '-force_html'); | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | ▶ | if (defined $options->{'_width'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 0 | push @command, '-width', $options->{'_width'}; | |||||||||||||||||||
| 58 | 0 | ▶ | if ($class->_have_nomargins) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | 0 | push @command, '-nomargins'; | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | 0 | ▶ | if (my $input_charset = $options->{'input_charset'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | 0 | push @command, '-assume_charset', $input_charset; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | 0 | ▶ | if (my $output_charset = $options->{'output_charset'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | 0 | push @command, '-display_charset', $output_charset; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | 0 | ▶ | if ($options->{'justify'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | 0 | push @command, '-justify'; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | 0 | ▶ | if ($options->{'unique_links'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 0 | push @command, '-unique_urls'; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | # -underscore gives _foo_ style for <u> underline, though it seems to need | ||||||||||||||||||||
| 77 | # -with_backspaces to come out. It doesn't use backspaces it seems, | ||||||||||||||||||||
| 78 | # unlike the name would suggest ... | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | # 'lynx_options' not documented ... | ||||||||||||||||||||
| 81 | 0 | ▶ | push @command, @{$options->{'lynx_options'} || []}; | ||||||||||||||||||
|
Condition0%0/2
$options->{'lynx_options'} || []
MC/DC0%0/1
$options->{'lynx_options'} || []
$options->{'lynx_options'}
Truth table0%0/2
A
A= $options->{'lynx_options'}
| |||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | # "lynx -" means read standard input. | ||||||||||||||||||||
| 84 | # Any other "-foo" is an option. | ||||||||||||||||||||
| 85 | # Recent lynx has "--" to mean end of options, but not circa 2.8.6. | ||||||||||||||||||||
| 86 | # "lynx dir/http:" attempts to connect to something. | ||||||||||||||||||||
| 87 | # Escape all this by URI::file. | ||||||||||||||||||||
| 88 | 0 | push @command, URI::file->new_abs($input_filename)->as_string; | |||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | return (\@command); | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 1 | 1; | |||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||