FormatText/Links.pm

filter: Statementstmt 73.3% 44 / 60 Branchbran 8.3% 1 / 12 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 93.3% 14 / 15 Podpod 100% 2 / 2 totaltotal 63.9% 62 / 97 CC 9 SCAR 25.0
CC
9
Cov
60%
_make_run
42.0
program_version
4.1
__ANON__
2.1
CRAP 12.2
« FormatText/Html2text.pm ↑ Summary FormatText/Vilistextum.pm »
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::Links;
17 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use URI::file;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use HTML::FormatExternal;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 our @ISA = ('HTML::FormatExternal');
23  
24 # uncomment this to run the ### lines
25 # use Smart::Comments;
26  
27  
28 2 our $VERSION = 26;
29  
30 2 ▶use constant DEFAULT_LEFTMARGIN => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶use constant DEFAULT_RIGHTMARGIN => 77;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use constant _WIDE_INPUT_CHARSET => 'entitize';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use constant _WIDE_OUTPUT_CHARSET => 'iso-8859-1';
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 # It seems maybe some people make "links" an alias for "elinks", and the
36 # latter doesn't have -html-margin. Maybe it'd be worth adapting to use
37 # elinks style "set document.browse.margin_width=0" in that case, but for
38 # now just don't use it if it doesn't work.
39 #
40 2 ▶use constant::defer _have_html_margin => sub {
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine __ANON__: called CC=2 SCAR=7.6
41 1 my ($class) = @_;
42 1 my $help = $class->_run_version (['links', '-help']);
43 1 ▶ return (defined $help && $help =~ /-html-margin/);
Condition33%1/3
defined $help && $help =~ /-html-margin/
!ll&&!rl&&r
100
MC/DC0%0/2
defined $help && $help =~ /-html-margin/
defined $help $help =~ /-html-margin/
Truth table33%1/3
A && B
A= defined $helpB= $help =~ /-html-margin/
ABresult
0X0
100
111
44 2 };
45  
46 5 ▶sub program_full_version {
Subroutine program_full_version: called CC=1 SCAR=0.0
Pod documented
47 5 my ($self_or_class) = @_;
48 5 return $self_or_class->_run_version (['links', '-version']);
49 }
50 2 ▶sub program_version {
Subroutine program_version: called CC=3 SCAR=14.2
Pod documented
51 2 my ($self_or_class) = @_;
52 2 my $version = $self_or_class->program_full_version;
53 2 ▶ if (! defined $version) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $version) 2 0 2
54  
55 # first line like "Links 1.00pre12" or "Links 2.2"
56 0 ▶ $version =~ /^Links (.*)/i
Branch: 1 branch
BranchTrueFalseTotal
$version =~ /^Links (.*)/i or $version =~ /^(.*)/ 0 0 0
57 or $version =~ /^(.*)/; # whole first line if format not recognised
58 0 return $1 . substr($version,0,0); # retain taintedness
59 }
60  
61 0 ▶sub _make_run {
Subroutine _make_run: not called CC=6 SCAR=37.4
62 0 my ($class, $input_filename, $options) = @_;
63 0 my @command = ('links', '-dump', '-force-html');
64  
65 0 ▶ if (defined $options->{'_width'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{"_width"}) 0 0 0
66 0 push @command, '-width', $options->{'_width'};
67 0 ▶ if ($class->_have_html_margin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->_have_html_margin) 0 0 0
68 0 push @command, '-html-margin', 0;
69 }
70 }
71  
72 0 ▶ if (my $input_charset = $options->{'input_charset'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $input_charset = $options->{"input_charset"}) 0 0 0
73 0 push @command,
74 '-html-assume-codepage', _links_mung_charset ($input_charset),
75 '-html-hard-assume', 1;
76 }
77 0 ▶ if (my $output_charset = $options->{'output_charset'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $output_charset = $options->{"output_charset"}) 0 0 0
78 0 push @command, '-codepage', _links_mung_charset ($output_charset);
79 }
80  
81 # 'links_options' not documented ...
82 0 ▶ push @command, @{$options->{'links_options'} || []};
Condition0%0/2
$options->{'links_options'} || []
l!l
00
MC/DC0%0/1
$options->{'links_options'} || []
$options->{'links_options'}
Truth table0%0/2
A
A= $options->{'links_options'}
Aresult
11
00
83  
84 # links interprets "%" in the input filename as URI style %ff hex
85 # encodings. Turn unusual filenames like "%" or "-" into full
86 # file:// using URI::file.
87 0 push @command, URI::file->new_abs($input_filename)->as_string;
88  
89 0 return (\@command);
90 }
91  
92 # links (version 2.2 at least) accepts "latin1" but not "latin-1". The
93 # latter is accepted by the other FormatExternal programs, so turn "latin-1"
94 # into "latin1" for convenience.
95 #
96 2 ▶sub _links_mung_charset {
Subroutine _links_mung_charset: called CC=1 SCAR=0.0
97 2 my ($charset) = @_;
98 2 $charset =~ s/^(latin)-([0-9]+)$/$1$2/i;
99 2 return $charset;
100 }
101  
102  
103 2 1;
104 __END__
« FormatText/Html2text.pm ↑ Summary FormatText/Vilistextum.pm »