File Coverage

blib/lib/HTML/FormatText/Zen.pm
Criterion Covered Total %
statement 27 32 84.3
branch 1 6 16.6
condition n/a
subroutine 9 10 90.0
pod 2 2 100.0
total 39 50 78.0


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   3053 use 5.006;
  1         4  
  1         62  
18 1     1   7 use strict;
  1         2  
  1         58  
19 1     1   6 use warnings;
  1         2  
  1         47  
20 1     1   7 use HTML::FormatExternal;
  1         2  
  1         10  
21             our @ISA = ('HTML::FormatExternal');
22              
23             our $VERSION = 24;
24              
25 1     1   87 use constant DEFAULT_LEFTMARGIN => 0;
  1         2  
  1         79  
26 1     1   4 use constant DEFAULT_RIGHTMARGIN => 80;
  1         1  
  1         43  
27              
28             # no input charset options
29 1     1   4 use constant _WIDE_INPUT_CHARSET => 'entitize';
  1         1  
  1         222  
30              
31             sub program_full_version {
32 5     5 1 1279 my ($self_or_class) = @_;
33 5         24 return $self_or_class->_run_version (['zen', '--version']);
34             }
35             sub program_version {
36 2     2 1 238 my ($self_or_class) = @_;
37 2         5 my $version = $self_or_class->program_full_version;
38 2 50       7 if (! defined $version) { return undef; }
  2         5  
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 0 0         return ([ 'zen', '-i', 'dump',
63 0           @{$options->{'zen_options'} || []},
64             '--', # end of options
65             $input_filename,
66             ]);
67             }
68              
69             1;
70             __END__