File Coverage

blib/lib/HTML/FormatText/Zen.pm
Criterion Covered Total %
statement 26 31 83.8
branch 1 6 16.6
condition n/a
subroutine 9 10 90.0
pod 2 2 100.0
total 38 49 77.5


line stmt bran cond sub pod time code
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 .
15              
16             package HTML::FormatText::Zen;
17 1     1   11035 use 5.006;
  1         4  
18 1     1   6 use strict;
  1         3  
  1         33  
19 1     1   5 use warnings;
  1         1  
  1         35  
20 1     1   5 use HTML::FormatExternal;
  1         1  
  1         8  
21             our @ISA = ('HTML::FormatExternal');
22              
23             our $VERSION = 26;
24              
25 1     1   77 use constant DEFAULT_LEFTMARGIN => 0;
  1         2  
  1         96  
26 1     1   6 use constant DEFAULT_RIGHTMARGIN => 80;
  1         2  
  1         71  
27              
28             # no input charset options
29 1     1   11 use constant _WIDE_INPUT_CHARSET => 'entitize';
  1         2  
  1         300  
30              
31             sub program_full_version {
32 5     5 1 2366 my ($self_or_class) = @_;
33 5         28 return $self_or_class->_run_version (['zen', '--version']);
34             }
35             sub program_version {
36 2     2 1 530 my ($self_or_class) = @_;
37 2         6 my $version = $self_or_class->program_full_version;
38 2 50       9 if (! defined $version) { return undef; }
  2         6  
39              
40             # eg. "zen version 0.2.3"
41 0 0         $version =~ /^zen version (.*)/i
42             or $version =~ /^(.*)/; # whole first line if format not recognised
43 0           return $1 . substr($version,0,0); # retain taintedness
44             }
45              
46             sub _make_run {
47 0     0     my ($class, $input_filename, $options) = @_;
48              
49             # Is it worth enforcing/checking this ?
50             # Could use Encode.pm to convert the output without too much trouble.
51             #
52             # if (my $input_charset = $options->{'input_charset'}) {
53             # $input_charset =~ /^latin-?1$|^iso-?8859-1$/i
54             # or croak "Zen only accepts latin-1 input";
55             # }
56             # if (my $output_charset = $options->{'output_charset'}) {
57             # $output_charset =~ /^latin-?1$|^iso-?8859-1$/i
58             # or croak "Zen only produces latin-1 output";
59             # }
60              
61             # 'zen_options' not documented ...
62             return ([ 'zen', '-i', 'dump',
63 0 0         @{$options->{'zen_options'} || []},
  0            
64             '--', # end of options
65             $input_filename,
66             ]);
67             }
68              
69             1;
70             __END__