blib/lib/HTML/FormatText/Html2textPY.pm

filter: Statementstmt 65.0% 26 / 40 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.7% 8 / 11 Podpod 100% 2 / 2 totaltotal 61.0% 36 / 59 CC 4 SCAR 14.2
CC
4
Cov
57%
program_version
12.0
_make_run
6.0
program_full_version
2.0
CRAP 4.1
↑ Summary
1 package HTML::FormatText::Html2textPY;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use base 'HTML::FormatExternal';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.13';
12  
13 1 ▶use constant DEFAULT_LEFTMARGIN => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use constant DEFAULT_RIGHTMARGIN => 79;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use constant _WIDE_CHARSET => 'iso-8859-1';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 HTML::FormatText::Html2textPY - format HTML as plain text using html2text python script
20  
21 =head1 SYNOPSIS
22  
23 use HTML::FormatText::Html2textPY;
24 $text = HTML::FormatText::Html2textPY->format_file ($filename);
25 $text = HTML::FormatText::Html2textPY->format_string ($html_string);
26  
27 $formatter = HTML::FormatText::Html2textPY->new;
28 $tree = HTML::TreeBuilder->new_from_file ($filename);
29 $text = $formatter->format ($tree);
30  
31 #if you don't want wrapping do this
32 $formatter = HTML::FormatText::Html2textPY->new( rightmargin => -1 );
33 $formatter->format_string ($html_string);
34  
35 =head1 DESCRIPTION
36  
37 C<HTML::FormatText::Html2textPY> turns HTML into plain text using the
38 C<html2text> python script. Please make sure you have it installed before
39 using this package.
40  
41 =cut
42  
43 0 ▶sub program_full_version {
Subroutine program_full_version: not called CC=1 SCAR=6.9
Pod documented
44 0 my ( $self_or_class ) = @_;
45 0 return $self_or_class->_run_version ( [ 'html2text', '--version' ], '2>&1' );
46 }
47  
48 0 ▶sub program_version {
Subroutine program_version: not called CC=3 SCAR=24.8
Pod documented
49 0 my ( $self_or_class ) = @_;
50 0 my $version = $self_or_class->program_full_version;
51 0 ▶ if (! defined $version) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $version) 0 0 0
52  
53 0 ▶ $version =~ /^html2text (.*)/ or $version =~ /^(.*)/;
Branch: 1 branch
BranchTrueFalseTotal
$version =~ /^html2text (.*)/ or $version =~ /^(.*)/ 0 0 0
54 0 return $1;
55 }
56  
57 0 ▶sub _make_run {
Subroutine _make_run: not called CC=2 SCAR=17.9
58 0 my ( $class, $input_filename, $options ) = @_;
59 0 my @command;
60  
61 #turn wrapping off if right margin is set to < 0 in caller
62 0 ▶ if ( $class->{rightmargin} < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->{'rightmargin'} < 0) { } 0 0 0
63 0 @command = ( 'html2text', '--body-width=0' );
64 } else {
65 0 @command = ( 'html2text' );
66 }
67  
68 0 return ( \@command, '<', $input_filename );
69 }
70  
71 =head1 SEE ALSO
72  
73 L<HTML::FormatExternal>
74  
75 =head1 AUTHOR
76  
77 Alex Pavlovic, C<alex.pavlovic@taskforce-1.com>
78  
79 =head1 COPYRIGHT
80  
81 Copyright (c) 2013
82 the HTML::FormatText::Html2textPY L</AUTHOR>
83 as listed above.
84  
85 =head1 LICENSE
86  
87 This program is free software, you can redistribute it and/or modify it
88 under the same terms as Perl itself.
89  
90 =cut
91  
92 1 1;
93 __END__
↑ Summary