File Coverage

blib/lib/App/sdview/Output/Man.pm
Criterion Covered Total %
statement 89 91 97.8
branch 13 14 92.8
condition 6 12 50.0
subroutine 16 16 100.0
pod 0 6 0.0
total 124 139 89.2


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, 2022-2023 -- leonerd@leonerd.org.uk
5              
6 2     2   1461 use v5.26;
  2         9  
7 2     2   14 use warnings;
  2         5  
  2         152  
8              
9 2     2   14 use Object::Pad 0.807;
  2         16  
  2         104  
10              
11             package App::sdview::Output::Man 0.20;
12             class App::sdview::Output::Man :strict(params);
13              
14 1     1   1089 apply App::sdview::Output;
  1         3  
  1         118  
15              
16 2     2   569 use constant format => "Man";
  2         5  
  2         181  
17              
18 2     2   18 use List::Util qw( any );
  2         6  
  2         6699  
19              
20             field $_current_mode = "";
21              
22 2     2 0 4 method output_head1 ( $para ) { $self->_output_head( ".SH", $para ); }
  2         7  
  2         3  
  2         4  
  2         10  
23 1     1 0 2 method output_head2 ( $para ) { $self->_output_head( ".SS", $para ); }
  1         4  
  1         2  
  1         2  
  1         5  
24              
25 3     3   6 method _output_head ( $directive, $para )
  3         8  
  3         7  
  3         7  
  3         5  
26             {
27 3         15 $self->say( $directive, " ", $self->_convert_str( $para->text ) );
28 3         19 $_current_mode = "PP";
29             }
30              
31 4     4 0 9 method output_plain ( $para )
  4         40  
  4         8  
  4         8  
32             {
33 4 100       22 $self->say( ".PP" ) unless $_current_mode eq "PP";
34 4         30 $_current_mode = "";
35              
36 4         18 $self->say( $self->_convert_str( $para->text ) );
37             }
38              
39 1     1 0 2 method output_verbatim ( $para )
  1         4  
  1         2  
  1         69  
40             {
41 1         7 $self->say( ".EX" );
42              
43 1         6 $self->say( $_ ) for split m/\n/, $para->text;
44              
45 1         4 $self->say( ".EE" );
46             }
47              
48 1     1 0 3 method output_list_bullet ( $para ) { $self->_output_list( $para ); }
  1         3  
  1         3  
  1         69  
  1         9  
49 1     1 0 4 method output_list_text ( $para ) { $self->_output_list( $para ); }
  1         4  
  1         3  
  1         2  
  1         5  
50              
51 2     2   5 method _output_list ( $para )
  2         6  
  2         5  
  2         3  
52             {
53 2         10 foreach my $item ( $para->items ) {
54 7 100       36 if( $item->type ne "item" ) {
    100          
    50          
55 1         6 $self->say( ".IP" );
56             }
57             elsif( $para->listtype eq "bullet" ) {
58 3         10 $self->say( ".IP \\(bu" );
59             }
60             elsif( $para->listtype eq "text" ) {
61 3         13 $self->say( ".TP" );
62 3         14 $self->say( $self->_convert_str( $item->term ) );
63             }
64              
65 7         31 $self->say( $self->_convert_str( $item->text ) );
66             }
67             }
68              
69 17     17   30 method _convert_str ( $s )
  17         38  
  17         28  
  17         28  
70             {
71 17         32 my $ret = "";
72              
73 17         25 my @fontstack;
74              
75 21         42 $s->iter_substr_nooverlap(
76 21     21   1697 sub ( $substr, %tags ) {
  21         36  
  21         32  
77             $ret .= "\\fP", pop @fontstack
78 21   66     85 while @fontstack and !$tags{ $fontstack[-1] };
79              
80             $tags{monospace} and (
81 21 100 66     78 any { $_ eq "monospace" } @fontstack or
  4         15  
82             $ret .= "\\f(CW", push @fontstack, "monospace" );
83             $tags{bold} and (
84 21 100 33     77 any { $_ eq "bold" } @fontstack or
  0         0  
85             $ret .= "\\fB", push @fontstack, "bold" );
86             $tags{italic} and (
87 21 100 33     63 any { $_ eq "italic" } @fontstack or
  0         0  
88             $ret .= "\\fI", push @fontstack, "italic" );
89              
90 21         84 my $man = $substr =~ s/([\\-])/\\$1/gr;
91              
92 21         76 $ret .= $man;
93             }
94 17         152 );
95              
96 17         447 $ret .= "\\fP", pop @fontstack
97             while @fontstack;
98              
99 17         92 return $ret;
100             }
101              
102             0x55AA;