FormatText/Html2text.pm

filter: Statementstmt 68.3% 41 / 60 Branchbran 7.1% 1 / 14 Conditioncond 18.1% 2 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 80.0% 12 / 15 Podpod 100% 2 / 2 totaltotal 53.2% 58 / 109 CC 12 SCAR 28.3
CC
12
Cov
52%
_make_run
56.0
_WIDE_OUTPUT_CHARSET
6.0
program_version
4.1
CRAP 16.9
« FormatText/Lynx.pm ↑ Summary FormatText/Links.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::Html2text;
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 HTML::FormatExternal;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 our @ISA = ('HTML::FormatExternal');
22  
23 # uncomment this to run the ### lines
24 # use Smart::Comments;
25  
26 1 our $VERSION = 26;
27  
28 1 ▶use constant DEFAULT_LEFTMARGIN => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use constant DEFAULT_RIGHTMARGIN => 79;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 my $have_ascii;
32 my $have_utf8;
33 1 ▶use constant::defer _check_help => sub { # run once only
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: called CC=3 SCAR=12.3
34 1 my ($class) = @_;
35 1 my $help = $class->_run_version (['html2text', '-help']);
36 1 ▶ $have_ascii = (defined $help && $help =~ /-ascii/);
Condition33%1/3
defined $help && $help =~ /-ascii/
!ll&&!rl&&r
100
MC/DC0%0/2
defined $help && $help =~ /-ascii/
defined $help $help =~ /-ascii/
Truth table33%1/3
A && B
A= defined $helpB= $help =~ /-ascii/
ABresult
0X0
100
111
37 1 ▶ $have_utf8 = (defined $help && $help =~ /-utf8/);
Condition33%1/3
defined $help && $help =~ /-utf8/
!ll&&!rl&&r
100
MC/DC0%0/2
defined $help && $help =~ /-utf8/
defined $help $help =~ /-utf8/
Truth table33%1/3
A && B
A= defined $helpB= $help =~ /-utf8/
ABresult
0X0
100
111
38 1 return undef;
39 1 };
40  
41 # return true if the "-ascii" option is available (new in html2text
42 # version 1.3.2 from Jan 2004)
43 1 ▶sub _have_ascii {
Subroutine _have_ascii: called CC=1 SCAR=0.0
44 1 my ($class) = @_;
45 1 $class->_check_help();
46 1 return $have_ascii;
47 }
48  
49 # return true if the "-utf8" option is available (a Debian addition circa 2009)
50 0 ▶sub _have_utf8 {
Subroutine _have_utf8: not called CC=1 SCAR=6.9
51 0 my ($class) = @_;
52 0 $class->_check_help();
53 0 return $have_utf8;
54 }
55  
56 # The Debian -utf8 option can give UTF-8 output.
57 # For input believe entitized is the only way to be confident of working
58 # with both original and Debian extended.
59 #
60 1 ▶use constant _WIDE_INPUT_CHARSET => 'entitize';
Subroutine BEGIN: called CC=1 SCAR=0.0
61 0 ▶sub _WIDE_OUTPUT_CHARSET {
Subroutine _WIDE_OUTPUT_CHARSET: not called CC=2 SCAR=17.9
62 0 my ($class) = @_;
63 0 ▶ return ($class->_have_utf8() ? 'UTF-8' : 'iso-8859-1');
Branch: 1 branch
BranchTrueFalseTotal
$class->_have_utf8 ? : 0 0 0
64 }
65  
66 5 ▶sub program_full_version {
Subroutine program_full_version: called CC=1 SCAR=0.0
Pod documented
67 5 my ($self_or_class) = @_;
68 5 return $self_or_class->_run_version (['html2text','-version'], '2>&1');
69 }
70 2 ▶sub program_version {
Subroutine program_version: called CC=3 SCAR=14.2
Pod documented
71 2 my ($self_or_class) = @_;
72 2 my $version = $self_or_class->program_full_version;
73 2 ▶ if (! defined $version) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $version) 2 0 2
74  
75 # eg. "This is html2text, version 1.3.2a"
76 0 ▶ $version =~ /^.*version (.*)/
Branch: 1 branch
BranchTrueFalseTotal
$version =~ /^.*version (.*)/ or $version =~ /^(.*)/ 0 0 0
77 or $version =~ /^(.*)/; # whole first line if format not recognised
78 0 return $1 . substr($version,0,0); # retain taintedness
79 }
80  
81 0 ▶sub _make_run {
Subroutine _make_run: not called CC=7 SCAR=40.3
82 0 my ($class, $input_filename, $options) = @_;
83  
84 # -nobs means don't do underlining with "_ backspace X" sequences.
85 # Backspaces are fun for teletype output, but the intention here is plain
86 # text. The Debian html2text has -nobs by default anyway.
87 #
88 0 my @command = ('html2text', '-nobs');
89  
90 0 ▶ if (defined $options->{'_width'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{"_width"}) 0 0 0
91 0 push @command, '-width', $options->{'_width'};
92 }
93  
94 0 ▶ if ($class->_have_ascii) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->_have_ascii) 0 0 0
95 0 ▶ if (my $output_charset = $options->{'output_charset'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $output_charset = $options->{"output_charset"}) 0 0 0
96 0 $output_charset = lc($output_charset);
97 0 ▶ if ($output_charset eq 'ascii' || $output_charset eq 'ansi_x3.4-1968') {
Branch: 1 branch
BranchTrueFalseTotal
if ($output_charset eq "ascii" or $output_charset eq "ansi_x3.4-1968") 0 0 0
Condition0%0/3
$output_charset eq "ascii" or $output_charset eq "ansi_x3.4-1968"
l!l&&r!l&&!r
000
MC/DC0%0/2
$output_charset eq "ascii" or $output_charset eq "ansi_x3.4-1968"
$output_charset eq "ascii" $output_charset eq "ansi_x3.4-1968"
Truth table0%0/3
A or B
A= $output_charset eq "ascii"B= $output_charset eq "ansi_x3.4-1968"
ABresult
1X1
011
000
98 0 push @command, '-ascii';
99 }
100 }
101 }
102  
103 # 'html2text_options' not documented ...
104 0 ▶ push @command, @{$options->{'html2text_options'} || []};
Condition0%0/2
$options->{'html2text_options'} || []
l!l
00
MC/DC0%0/1
$options->{'html2text_options'} || []
$options->{'html2text_options'}
Truth table0%0/2
A
A= $options->{'html2text_options'}
Aresult
11
00
105  
106 # "html2text -" input filename "-" means read standard input.
107 # Any other "-foo" starting with "-" is an option and there's no apparent
108 # "--" to mark the end of options (as of its version 1.3.2a).
109 #
110 # Normally html2text takes URL style file: or http:, but the debian
111 # version mangles it to a bare filename only. This makes it hard to
112 # escape a name suitably to get through both. Instead use standard input
113 # which both versions read by default.
114  
115 0 return (\@command,
116 '<', $input_filename);
117 }
118  
119 1 1;
120 __END__
« FormatText/Lynx.pm ↑ Summary FormatText/Links.pm »