FormatText/W3m.pm

filter: Statementstmt 63.2% 31 / 49 Branchbran 8.3% 1 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 83.3% 10 / 12 Podpod 100% 4 / 4 totaltotal 57.5% 46 / 80 CC 8 SCAR 22.7
CC
8
Cov
51%
_make_run
30.0
format
6.0
program_version
4.1
CRAP 9.7
« FormatText/Vilistextum.pm ↑ Summary FormatText/Elinks.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::W3m;
17 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use URI::file;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use HTML::FormatExternal;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 our @ISA = ('HTML::FormatExternal');
23  
24 3 our $VERSION = 26;
25  
26 3 ▶use constant DEFAULT_LEFTMARGIN => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 3 ▶use constant DEFAULT_RIGHTMARGIN => 80;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 6 ▶sub program_full_version {
Subroutine program_full_version: called CC=1 SCAR=0.0
Pod documented
30 6 my ($self_or_class) = @_;
31 6 return $self_or_class->_run_version (['w3m', '-version']);
32 }
33 2 ▶sub program_version {
Subroutine program_version: called CC=3 SCAR=14.2
Pod documented
34 2 my ($self_or_class) = @_;
35 2 my $version = $self_or_class->program_full_version;
36 2 ▶ if (! defined $version) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $version) 2 0 2
37  
38 # eg. "w3m version w3m/0.5.2, options lang=en,m17n,image,color,..."
39 0 ▶ $version =~ m{^w3m version (?:w3m/)?(.*?),}i
Branch: 1 branch
BranchTrueFalseTotal
$version =~ m[^w3m version (?:w3m/)?(.*?),]i or $version =~ /^(.*)/ 0 0 0
40 or $version =~ /^(.*)/; # whole first line if format not recognised
41 0 return $1 . substr($version,0,0); # retain taintedness
42 }
43  
44 0 ▶sub _make_run {
Subroutine _make_run: not called CC=5 SCAR=34.0
45 0 my ($class, $input_filename, $options) = @_;
46 0 my @command = ('w3m', '-dump', '-T', 'text/html');
47  
48 # w3m seems to use one less than the given -cols, presumably designed with
49 # a tty in mind so "-cols 80" prints just 79 so as not to wrap around
50 0 ▶ if (defined $options->{'_width'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{"_width"}) 0 0 0
51 0 push @command, '-cols', $options->{'_width'} + 1;
52 }
53  
54 0 ▶ if ($options->{'input_charset'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"input_charset"}) 0 0 0
55 0 push @command, '-I', $options->{'input_charset'};
56 }
57 0 ▶ if ($options->{'output_charset'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"output_charset"}) 0 0 0
58 0 push @command, '-O', $options->{'output_charset'};
59 }
60  
61 # 'w3m_options' not documented ...
62 0 ▶ push @command, @{$options->{'w3m_options'} || []};
Condition0%0/2
$options->{'w3m_options'} || []
l!l
00
MC/DC0%0/1
$options->{'w3m_options'} || []
$options->{'w3m_options'}
Truth table0%0/2
A
A= $options->{'w3m_options'}
Aresult
11
00
63  
64 # w3m (circa its version 0.5.3) interprets "%" in the input
65 # filename as URI style %ff hex encodings. Turn unusual filenames
66 # like "%" into full file:// using URI::file.
67 #
68 # Filenames merely starting "-" can be given as "./-" etc to avoid
69 # them being interpreted as options. The file:// does this too.
70 #
71 0 push @command, URI::file->new_abs($input_filename)->as_string;
72  
73 0 return (\@command);
74 }
75  
76 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
77 2 my ($class, %self) = @_;
78 2 return bless \%self, $class;
79 }
80 0 ▶sub format {
Subroutine format: not called CC=2 SCAR=17.9
Pod documented
81 0 my ($self, $html) = @_;
82 0 ▶ if (ref $html) { $html = $html->as_HTML; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $html) 0 0 0
83 0 return $self->format_string ($html, %$self);
84 }
85  
86 3 1;
87 __END__
« FormatText/Vilistextum.pm ↑ Summary FormatText/Elinks.pm »