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   948 use v5.26;
  2         8  
7 2     2   12 use warnings;
  2         5  
  2         58  
8 2     2   10 use utf8;
  2         4  
  2         15  
9              
10 2     2   74 use Object::Pad 0.800;
  2         14  
  2         83  
11              
12             package App::sdview::Output::Plain 0.13;
13             class App::sdview::Output::Plain
14             :isa(App::sdview::Output::Formatted)
15 1     1   621 :strict(params);
  1         4  
  1         64  
16              
17 2     2   585 use constant format => "plain";
  2         6  
  2         1493  
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 9         15 method setup_output ()
  9         18  
38 9     9 0 22 {
39 8         102 STDOUT->binmode( ":encoding(UTF-8)" );
40             }
41              
42 8         14 method width ()
  8         13  
43 8     8 0 23 {
44 8         17 return 80;
45             }
46              
47 47         70 method say ( @s )
  47         69  
  47         85  
48 47     47 0 106 {
49 47         84 say map { "$_" } @s; # stringify to remove the String::Tagged formatting
  84         238  
50             }
51              
52             # Ugh this is all backwards; the ::Terminal plugin really wants to be written
53             # to use this instead
54 8         12 method generate ( @p )
  8         14  
  8         11  
55 8     8 0 33 {
56 8         156 open my $outh, ">:encoding(UTF-8)", \( my $outbuf = "" );
57             {
58 8         1367 my $oldh = select;
  8         24  
59 8         19 select $outh;
60              
61 8         36 $self->output( @p );
62              
63 8         115 select $oldh;
64             }
65 8         96 close $outh;
66              
67 8         32 return Encode::decode( "UTF-8", $outbuf );
68             }
69              
70             =head1 AUTHOR
71              
72             Paul Evans
73              
74             =cut
75              
76             0x55AA;