File Coverage

blib/lib/App/sdview/Output/Plain.pm
Criterion Covered Total %
statement 43 43 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 0 4 0.0
total 53 57 92.9


line stmt bran cond sub pod time code
1             # You may distribute under the terms of either the GNU General Public License
2             # or the Artistic License (the same terms as Perl itself)
3             #
4             # (C) Paul Evans, 2021-2023 -- leonerd@leonerd.org.uk
5              
6 2     2   1474 use v5.26;
  2         9  
7 2     2   16 use warnings;
  2         4  
  2         159  
8 2     2   15 use utf8;
  2         5  
  2         20  
9              
10 2     2   88 use Object::Pad 0.807;
  2         18  
  2         143  
11              
12             package App::sdview::Output::Plain 0.20;
13             class App::sdview::Output::Plain :strict(params);
14              
15 1     1   1159 inherit App::sdview::Output::Formatted;
  1         5  
  1         134  
16              
17 2     2   655 use constant format => "plain";
  2         6  
  2         2430  
18              
19             =head1 NAME
20              
21             C - generate plain-text output from L
22              
23             =head1 SYNOPSIS
24              
25             $ sdview README.pod -o plain > README.txt
26              
27             =head1 DESCRIPTION
28              
29             This output module allows L to generate output text without any
30             special formatting, other than indentation and spacing applied in plain text
31             characters. The generated output should be similar to the formatted output
32             rendered for terminal use, except with none of the embedded terminal control
33             codes used to apply formatting.
34              
35             =cut
36              
37 8     8 0 17 method setup_output ()
  8         21  
  8         15  
38             {
39 8         197 STDOUT->binmode( ":encoding(UTF-8)" );
40             }
41              
42 8     8 0 23 method width ()
  8         32  
  8         20  
43             {
44 8         24 return 80;
45             }
46              
47 52     52 0 126 method say ( @s )
  52         191  
  52         122  
  52         79  
48             {
49 52         149 say map { "$_" } @s; # stringify to remove the String::Tagged formatting
  90         329  
50             }
51              
52             # Ugh this is all backwards; the ::Terminal plugin really wants to be written
53             # to use this instead
54 8     8 0 107 method generate ( @p )
  8         30  
  8         22  
  8         17  
55             {
56 8         254 open my $outh, ">:encoding(UTF-8)", \( my $outbuf = "" );
57             {
58 8         762 my $oldh = select;
  8         41  
59 8         28 select $outh;
60              
61 8         69 $self->output( @p );
62              
63 8         208 select $oldh;
64             }
65 8         181 close $outh;
66              
67 8         77 return Encode::decode( "UTF-8", $outbuf );
68             }
69              
70             =head1 AUTHOR
71              
72             Paul Evans
73              
74             =cut
75              
76             0x55AA;