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