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