lib/Pod/Perldoc/ToTerm.pm

filter: Statementstmt 59.0% 36 / 61 Branchbran 17.8% 5 / 28 Conditioncond 28.5% 4 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 68.1% 15 / 22 Podpod 0.0% 0 / 12 totaltotal 41.3% 60 / 145 CC 20 SCAR 21.6
CC
20
Cov
44%
pager_configuration
30.0
_get_columns_from_manwidth
19.9
parse_from_file
7.0
CRAP 8.7
« lib/Pod/Perldoc/ToText.pm ↑ Summary lib/Pod/Perldoc/ToRtf.pm »
1 package Pod::Perldoc::ToTerm;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 $VERSION = '3.28';
7  
8 3 ▶use parent qw(Pod::Perldoc::BaseTo);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶sub is_pageable { 1 }
Subroutine is_pageable: called CC=1 SCAR=0.0
Pod undocumented
11 1 ▶sub write_with_binmode { 0 }
Subroutine write_with_binmode: called CC=1 SCAR=0.0
Pod undocumented
12 1 ▶sub output_extension { 'txt' }
Subroutine output_extension: called CC=1 SCAR=0.0
Pod undocumented
13  
14 3 ▶use Pod::Text::Termcap ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub alt { shift->_perldoc_elem('alt' , @_) }
Subroutine alt: not called CC=1 SCAR=6.9
Pod undocumented
17 0 ▶sub indent { shift->_perldoc_elem('indent' , @_) }
Subroutine indent: not called CC=1 SCAR=6.9
Pod undocumented
18 0 ▶sub loose { shift->_perldoc_elem('loose' , @_) }
Subroutine loose: not called CC=1 SCAR=6.9
Pod undocumented
19 0 ▶sub quotes { shift->_perldoc_elem('quotes' , @_) }
Subroutine quotes: not called CC=1 SCAR=6.9
Pod undocumented
20 0 ▶sub sentence { shift->_perldoc_elem('sentence', @_) }
Subroutine sentence: not called CC=1 SCAR=6.9
Pod undocumented
21 1 ▶sub width {
Subroutine width: called CC=4 SCAR=17.9
Pod undocumented
22 1 my $self = shift;
23 1 ▶ $self->_perldoc_elem('width' , @_) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_perldoc_elem("width", @_) or $self->_get_columns_from_manwidth or $self->_get_columns_from_stty or $self->_get_default_width 0 1 1
Condition33%2/6
$self->_perldoc_elem("width", @_) or $self->_get_columns_from_manwidth or $self->_get_columns_from_stty
l!l&&r!l&&!r
001
$self->_perldoc_elem("width", @_) or $self->_get_columns_from_manwidth
l!l&&r!l&&!r
001
MC/DC0%0/3
$self->_perldoc_elem("width", @_) or $self->_get_columns_from_manwidth or $self->_get_columns_from_stty
$self->_perldoc_elem("width", @_) $self->_get_columns_from_manwidth $self->_get_columns_from_stty
Truth table25%1/4
A or B or C
A= $self->_perldoc_elem("width", @_)B= $self->_get_columns_from_manwidthC= $self->_get_columns_from_stty
ABCresult
1XX1
01X1
0011
0000
24 $self->_get_columns_from_manwidth ||
25 $self->_get_columns_from_stty ||
26 $self->_get_default_width;
27 }
28  
29 0 ▶sub pager_configuration {
Subroutine pager_configuration: not called CC=5 SCAR=34.0
Pod undocumented
30 0 my($self, $pager, $perldoc) = @_;
31  
32 # do not modify anything on Windows or DOS
33 0 ▶ return if ( $perldoc->is_mswin32 || $perldoc->is_dos );
Branch: 1 branch
BranchTrueFalseTotal
if $perldoc->is_mswin32 or $perldoc->is_dos 0 0 0
Condition0%0/3
$perldoc->is_mswin32 or $perldoc->is_dos
l!l&&r!l&&!r
000
MC/DC0%0/2
$perldoc->is_mswin32 or $perldoc->is_dos
$perldoc->is_mswin32 $perldoc->is_dos
Truth table0%0/3
A or B
A= $perldoc->is_mswin32B= $perldoc->is_dos
ABresult
1X1
011
000
34  
35 0 ▶ if ( $pager =~ /less/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pager =~ /less/) { } 0 0 0
elsif ($pager =~ /more/) { } 0 0 0
36 0 $self->_maybe_modify_environment('LESS');
37 }
38 elsif ( $pager =~ /more/ ) {
39 0 $self->_maybe_modify_environment('MORE');
40 }
41  
42 0 return;
43 }
44  
45 0 ▶sub _maybe_modify_environment {
Subroutine _maybe_modify_environment: not called CC=2 SCAR=17.9
46 0 my($self, $name) = @_;
47  
48 0 ▶ if ( ! defined $ENV{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ENV{$name}) 0 0 0
49 0 $ENV{$name} = "-R";
50 }
51  
52 # if the environment is set, don't modify
53 # anything
54  
55 }
56  
57 1 ▶sub _get_stty { `stty -a` }
Subroutine _get_stty: called CC=1 SCAR=0.0
58  
59 1 ▶sub _get_columns_from_stty {
Subroutine _get_columns_from_stty: called CC=3 SCAR=13.3
60 1 my $output = $_[0]->_get_stty;
61  
62 0 ▶ if( $output =~ /\bcolumns\s+(\d+)/ ) { return $1; }
Branch: 2 branches
BranchTrueFalseTotal
if ($output =~ /\bcolumns\s+(\d+)/) { } 0 1 1
elsif ($output =~ /;\s*(\d+)\s+columns;/) { } 0 1 1
63 0 elsif( $output =~ /;\s*(\d+)\s+columns;/ ) { return $1; }
64 1 else { return 0 }
65 }
66  
67 1 ▶sub _get_columns_from_manwidth {
Subroutine _get_columns_from_manwidth: called CC=5 SCAR=29.9
68 1 my( $self ) = @_;
69  
70 1 ▶ return 0 unless defined $ENV{MANWIDTH};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV{"MANWIDTH"} 1 0 1
71  
72 0 ▶ unless( $ENV{MANWIDTH} =~ m/\A\d+\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"MANWIDTH"} =~ /\A\d+\z/) 0 0 0
73 0 $self->warn( "Ignoring non-numeric MANWIDTH ($ENV{MANWIDTH})\n" );
74 0 return 0;
75 }
76  
77 0 ▶ if( $ENV{MANWIDTH} == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"MANWIDTH"} == 0) 0 0 0
78 0 $self->warn( "Ignoring MANWIDTH of 0. Really? Why even run the program? :)\n" );
79 0 return 0;
80 }
81  
82 0 ▶ if( $ENV{MANWIDTH} =~ m/\A(\d+)\z/ ) { return $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"MANWIDTH"} =~ /\A(\d+)\z/) 0 0 0
83  
84 0 return 0;
85 }
86  
87 1 ▶sub _get_default_width {
Subroutine _get_default_width: called CC=1 SCAR=0.0
88 1 76
89 }
90  
91  
92 1 ▶sub new { return bless {}, ref($_[0]) || $_[0] }
Subroutine new: called CC=2 SCAR=9.2
Pod undocumented
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
93  
94 1 ▶sub parse_from_file {
Subroutine parse_from_file: called CC=5 SCAR=19.4
Pod undocumented
95 1 my $self = shift;
96  
97 1 $self->{width} = $self->width();
98  
99 my @options =
100 1 map {; $_, $self->{$_} }
101 grep !m/^_/s,
102 keys %$self
103 ;
104  
105 1 ▶ defined(&Pod::Perldoc::DEBUG)
Branch: 3 branches
BranchTrueFalseTotal
defined &Pod::Perldoc::DEBUG and 0 and print "About to call new Pod::Text::Termcap ", $Pod::Text::VERSION ? "(v$Pod::Text::Termcap::VERSION) " : "", "with options: ", @options ? "[@options]" : "(nil)", "\n" 0 1 1
$Pod::Text::VERSION ? : 0 0 0
@options ? : 0 0 0
Condition50%1/2
defined &Pod::Perldoc::DEBUG and 0
!ll
01
MC/DC0%0/1
defined &Pod::Perldoc::DEBUG and 0
defined &Pod::Perldoc::DEBUG
Truth table50%1/2
A
A= defined &Pod::Perldoc::DEBUG
Aresult
00
11
106 and Pod::Perldoc::DEBUG()
107 and print "About to call new Pod::Text::Termcap ",
108 $Pod::Text::VERSION ? "(v$Pod::Text::Termcap::VERSION) " : '',
109 "with options: ",
110 @options ? "[@options]" : "(nil)", "\n";
111 ;
112  
113 1 Pod::Text::Termcap->new(@options)->parse_from_file(@_);
114 }
115  
116 3 1;
117  
118 =head1 NAME
119  
120 Pod::Perldoc::ToTerm - render Pod with terminal escapes
121  
122 =head1 SYNOPSIS
123  
124 perldoc -o term Some::Modulename
125  
126 =head1 DESCRIPTION
127  
128 This is a "plug-in" class that allows Perldoc to use
129 Pod::Text as a formatter class.
130  
131 It supports the following options, which are explained in
132 L<Pod::Text>: alt, indent, loose, quotes, sentence, width
133  
134 For example:
135  
136 perldoc -o term -w indent:5 Some::Modulename
137  
138 =head1 PAGER FORMATTING
139  
140 Depending on the platform, and because this class emits terminal escapes it
141 will attempt to set the C<-R> flag on your pager by injecting the flag into
142 your environment variable for C<less> or C<more>.
143  
144 On Windows and DOS, this class will not modify any environment variables.
145  
146 =head1 CAVEAT
147  
148 This module may change to use a different text formatter class in the
149 future, and this may change what options are supported.
150  
151 =head1 SEE ALSO
152  
153 L<Pod::Text>, L<Pod::Text::Termcap>, L<Pod::Perldoc>
154  
155 =head1 COPYRIGHT AND DISCLAIMERS
156  
157 Copyright (c) 2017 Mark Allen.
158  
159 This program is free software; you can redistribute it and/or modify it
160 under the terms of either: the GNU General Public License as published
161 by the Free Software Foundation; or the Artistic License.
162  
163 See http://dev.perl.org/licenses/ for more information.
164  
165 =head1 AUTHOR
166  
167 Mark Allen C<< <mallen@cpan.org> >>
168  
169 =cut
« lib/Pod/Perldoc/ToText.pm ↑ Summary lib/Pod/Perldoc/ToRtf.pm »