File Coverage

blib/lib/HTML/FormatText/Lynx.pm
Criterion Covered Total %
statement 33 53 62.2
branch 1 18 5.5
condition 1 3 33.3
subroutine 10 11 90.9
pod 2 2 100.0
total 47 87 54.0


line stmt bran cond sub pod time code
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 .
15              
16             package HTML::FormatText::Lynx;
17 1     1   5181 use 5.006;
  1         4  
  1         35  
18 1     1   5 use strict;
  1         2  
  1         40  
19 1     1   7 use warnings;
  1         3  
  1         58  
20 1     1   5 use URI::file;
  1         1  
  1         10  
21 1     1   20 use HTML::FormatExternal;
  1         2  
  1         5  
22             our @ISA = ('HTML::FormatExternal');
23              
24             our $VERSION = 24;
25              
26 1     1   51 use constant DEFAULT_LEFTMARGIN => 2;
  1         1  
  1         65  
27 1     1   4 use constant DEFAULT_RIGHTMARGIN => 72;
  1         1  
  1         111  
28              
29             # return true if the "-nomargins" option is available (new in Lynx
30             # 2.8.6dev.12 from June 2005)
31             use constant::defer _have_nomargins => sub {
32 1         254 my ($class) = @_;
33 1         5 my $help = $class->_run_version (['lynx', '-help']);
34 1   33     8 return (defined $help && $help =~ /-nomargins/);
35 1     1   4 };
  1         1  
  1         8  
36              
37             sub program_full_version {
38 5     5 1 1133 my ($self_or_class) = @_;
39 5         19 return $self_or_class->_run_version (['lynx', '-version']);
40             }
41             sub program_version {
42 2     2 1 342 my ($self_or_class) = @_;
43 2         11 my $version = $self_or_class->program_full_version;
44 2 50       7 if (! defined $version) { return undef; }
  2         5  
45              
46             # eg. "Lynx Version 2.8.7dev.10 (21 Sep 2008)"
47 0 0         $version =~ /^Lynx Version (.*?) \(/i
48             or $version =~ /^(.*)/; # whole first line if format not recognised
49 0           return $1 . substr($version,0,0); # retain taintedness
50             }
51              
52             sub _make_run {
53 0     0     my ($class, $input_filename, $options) = @_;
54 0           my @command = ('lynx', '-dump', '-force_html');
55              
56 0 0         if (defined $options->{'_width'}) {
57 0           push @command, '-width', $options->{'_width'};
58 0 0         if ($class->_have_nomargins) {
59 0           push @command, '-nomargins';
60             }
61             }
62 0 0         if (my $input_charset = $options->{'input_charset'}) {
63 0           push @command, '-assume_charset', $input_charset;
64             }
65 0 0         if (my $output_charset = $options->{'output_charset'}) {
66 0           push @command, '-display_charset', $output_charset;
67             }
68 0 0         if ($options->{'justify'}) {
69 0           push @command, '-justify';
70             }
71 0 0         if ($options->{'unique_links'}) {
72 0           push @command, '-unique_urls';
73             }
74              
75              
76             # -underscore gives _foo_ style for 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 0         push @command, @{$options->{'lynx_options'} || []};
  0            
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;
94             __END__