FormatText/Elinks.pm

filter: Statementstmt 64.0% 32 / 50 Branchbran 10.0% 1 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 83.3% 10 / 12 Podpod 100% 2 / 2 totaltotal 58.4% 45 / 77 CC 7 SCAR 22.7
CC
7
Cov
53%
_make_run
30.0
program_version
4.1
_elinks_mung_charset
2.0
CRAP 9.6
« FormatText/W3m.pm ↑ Summary FormatText/Netrik.pm »
1 # Copyright 2008, 2009, 2010, 2012, 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  
17 # elinks.conf(5) describes the various config options
18 #
19 # Maybe:
20 # --dump-charset UTF-8 ??
21 #
22  
23  
24 package HTML::FormatText::Elinks;
25 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use URI::file;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use HTML::FormatExternal;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 our @ISA = ('HTML::FormatExternal');
31  
32 2 our $VERSION = 26;
33  
34 2 ▶use constant DEFAULT_LEFTMARGIN => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use constant DEFAULT_RIGHTMARGIN => 77;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 (['elinks', '-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
BranchTrueFalseTotal
unless (defined $version) 2 0 2
45  
46 # eg. "ELinks 0.12pre2\n
47 # Built on Oct 2 2008 18:34:16"
48 #
49 0 ▶ $version =~ /^ELinks (.*)/i
Branch: 1 branch
BranchTrueFalseTotal
$version =~ /^ELinks (.*)/i or $version =~ /^(.*)/ 0 0 0
50 or $version =~ /^(.*)/; # whole first line if format not recognised
51 0 return $1 . substr($version,0,0); # retain taintedness
52 }
53  
54 0 ▶sub _make_run {
Subroutine _make_run: not called CC=5 SCAR=34.0
55 0 my ($class, $input_filename, $options) = @_;
56 0 my @command = ('elinks', '-dump', '-force-html');
57  
58 # if ($options->{'ansi_colour'}) {
59 # push @command, '-eval', 'set document.dump.color_mode=1';
60 # }
61  
62 0 ▶ if (defined $options->{'_width'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{"_width"}) 0 0 0
63 push @command,
64 0 '-dump-width', $options->{'_width'},
65 '-eval', 'set document.browse.margin_width=0';
66 }
67  
68 0 ▶ if (my $input_charset = $options->{'input_charset'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $input_charset = $options->{"input_charset"}) 0 0 0
69 0 $input_charset = _elinks_mung_charset ($input_charset);
70 0 push @command,
71 '-eval', ('set document.codepage.assume='
72 . _quote_config_stringarg($input_charset)),
73 '-eval', 'set document.codepage.force_assumed=1';
74  
75 }
76 0 ▶ if (my $output_charset = $options->{'output_charset'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $output_charset = $options->{"output_charset"}) 0 0 0
77 0 push @command, '-dump-charset', _elinks_mung_charset ($output_charset);
78 }
79  
80 # 'elinks_options' not documented ...
81 0 ▶ push @command, @{$options->{'elinks_options'} || []};
Condition0%0/2
$options->{'elinks_options'} || []
l!l
00
MC/DC0%0/1
$options->{'elinks_options'} || []
$options->{'elinks_options'}
Truth table0%0/2
A
A= $options->{'elinks_options'}
Aresult
11
00
82  
83 # elinks takes any "-foo" to be an option (except a bare "-") and
84 # there's no apparent "--" to end options (in its version 0.12pre5).
85 # Filenames starting "http:" are rejected.
86 # Turn into file:// using URI::file to ensure literal filename.
87 #
88 0 push @command, URI::file->new_abs($input_filename)->as_string;
89  
90 0 return (\@command);
91 }
92  
93 # elinks (version 0.12pre2 at least) is picky about charset names in a
94 # similar fashion to the main "links" program (see Links.pm). Turn
95 # "latin-1" into "latin1" here for convenience.
96 #
97 0 ▶sub _elinks_mung_charset {
Subroutine _elinks_mung_charset: not called CC=1 SCAR=6.9
98 0 my ($charset) = @_;
99 0 $charset =~ s/^(latin)-([0-9]+)$/$1$2/i;
100 0 return $charset;
101 }
102  
103 # Return $str with quotes around it, and backslashed within it, suitable for
104 # use in an elinks config file or -eval of a config file line.
105 3 ▶sub _quote_config_stringarg {
Subroutine _quote_config_stringarg: called CC=1 SCAR=0.0
106 3 my ($str) = @_;
107 3 $str =~ s/'/\\'/g; # ' -> \'
108 3 return "'$str'"; # '$str' surrounding quotes
109 }
110  
111 2 1;
112 __END__
« FormatText/W3m.pm ↑ Summary FormatText/Netrik.pm »