Perldoc/ToFancy.pm

filter: Statementstmt 76.3% 58 / 76 Branchbran 70.5% 24 / 34 Conditioncond 68.0% 17 / 25 MC/DCmcdc 53.3% 8 / 15 Subroutinesub 67.8% 19 / 28 Podpod 5.8% 1 / 17 totaltotal 65.1% 127 / 195 CC 27 SCAR 18.1
CC
27
Cov
73%
pager_configuration
30.0
_theme_to_use
7.0
width
6.0
CRAP 6.1
« Text/Fancy.pm ↑ Summary
1 package Pod::Perldoc::ToFancy;
2 3 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 our $VERSION = "0.02";
6  
7 # Modeled after Pod::Perldoc::ToTerm (Pod-Perldoc 3.28).
8  
9 3 ▶use parent 'Pod::Perldoc::BaseTo';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use Pod::Text::Fancy ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub is_pageable { 1 }
Subroutine is_pageable: not called CC=1 SCAR=6.9
Pod undocumented
14 1 ▶sub write_with_binmode { 0 }
Subroutine write_with_binmode: called CC=1 SCAR=0.0
Pod undocumented
15 1 ▶sub output_extension { 'txt' }
Subroutine output_extension: called CC=1 SCAR=0.0
Pod undocumented
16  
17 17 ▶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
0170
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
18  
19 0 ▶sub alt { shift->_perldoc_elem('alt' , @_) }
Subroutine alt: not called CC=1 SCAR=6.9
Pod undocumented
20 0 ▶sub indent { shift->_perldoc_elem('indent' , @_) }
Subroutine indent: not called CC=1 SCAR=6.9
Pod undocumented
21 0 ▶sub loose { shift->_perldoc_elem('loose' , @_) }
Subroutine loose: not called CC=1 SCAR=6.9
Pod undocumented
22 0 ▶sub quotes { shift->_perldoc_elem('quotes' , @_) }
Subroutine quotes: not called CC=1 SCAR=6.9
Pod undocumented
23 0 ▶sub sentence { shift->_perldoc_elem('sentence', @_) }
Subroutine sentence: not called CC=1 SCAR=6.9
Pod undocumented
24 1 ▶sub theme { shift->_perldoc_elem('_theme' , @_) }
Subroutine theme: called CC=1 SCAR=0.0
Pod undocumented
25 1 ▶sub base { shift->_perldoc_elem('_base' , @_) }
Subroutine base: called CC=1 SCAR=0.0
Pod undocumented
26 1 ▶sub wall { shift->_perldoc_elem('_wall' , @_) }
Subroutine wall: called CC=1 SCAR=0.0
Pod undocumented
27  
28 # -w colormap:label=spec, repeatable.
29 2 ▶sub colormap {
Subroutine colormap: called CC=1 SCAR=0.0
Pod undocumented
30 2 my ($self, $value) = @_;
31 2 my ($label, $spec) = split /=/, $value, 2;
32 2 $self->{_colormap}{$label} = $spec;
33 }
34  
35 # Width given by the user (-w width or MANWIDTH) is the desired line
36 # length, which run-in may exceed. Terminal width is a physical limit,
37 # so leave room for run-in.
38 20 ▶sub width {
Subroutine width: called CC=6 SCAR=17.9
Pod documented
39 20 my $self = shift;
40 20 ▶ return $self->_perldoc_elem('width', @_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 19 20
41 $self->_perldoc_elem('width')
42 || $self->_get_columns_from_manwidth
43 19 ▶ || do {
Branch: 1 branch
BranchTrueFalseTotal
$self->_perldoc_elem("width") or $self->_get_columns_from_manwidth or do { my $cols = $self->_get_columns_from_stty; $cols ? $cols - "Pod::Text::Fancy"->runin : 0 } or $self->_get_default_width 4 15 19
Condition100%6/6
$self->_perldoc_elem("width") or $self->_get_columns_from_manwidth or do { my $cols = $self->_get_columns_from_stty; $cols ? $cols - "Pod::Text::Fancy"->runin : 0 }
l!l&&r!l&&!r
3115
$self->_perldoc_elem("width") or $self->_get_columns_from_manwidth
l!l&&r!l&&!r
1216
MC/DC100%3/3
$self->_perldoc_elem("width") or $self->_get_columns_from_manwidth or do { my $cols = $self->_get_columns_from_stty; $cols ? $cols - "Pod::Text::Fancy"->runin : 0 }
$self->_perldoc_elem("width") $self->_get_columns_from_manwidth do { my $cols = $self->_get_columns_from_stty; $cols ? $cols - "Pod::Text::Fancy"->runin : 0 }
Truth table100%4/4
A or B or C
A= $self->_perldoc_elem("width")B= $self->_get_columns_from_manwidthC= do { my $cols = $self->_get_columns_from_stty; $cols ? $cols - "Pod::Text::Fancy"->runin : 0 }
ABCresult
1XX1
01X1
0011
0000
44 16 my $cols = $self->_get_columns_from_stty;
45 16 ▶ $cols ? $cols - Pod::Text::Fancy->runin : 0;
Branch: 1 branch
BranchTrueFalseTotal
$cols ? : 1 15 16
46 }
47 || $self->_get_default_width;
48 }
49  
50 # An explicit theme is always used, unless NO_COLOR is set
51 # (no-color.org). The default theme quiet is used only on a terminal.
52 15 ▶sub _theme_to_use {
Subroutine _theme_to_use: called CC=7 SCAR=19.5
53 15 my $self = shift;
54 15 ▶ return 'none' if defined $ENV{NO_COLOR} and $ENV{NO_COLOR} ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"NO_COLOR"} and $ENV{"NO_COLOR"} ne "" 2 13 15
Condition100%3/3
defined $ENV{"NO_COLOR"} and $ENV{"NO_COLOR"} ne ""
!ll&&!rl&&r
1212
MC/DC100%2/2
defined $ENV{"NO_COLOR"} and $ENV{"NO_COLOR"} ne ""
defined $ENV{"NO_COLOR"} $ENV{"NO_COLOR"} ne ""
Truth table100%3/3
A and B
A= defined $ENV{"NO_COLOR"}B= $ENV{"NO_COLOR"} ne ""
ABresult
0X0
100
111
55 13 ▶ return $self->{_theme} if defined $self->{_theme};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_theme"} 2 11 13
56 11 ▶ return 'none' if !$ENV{TERM} or $ENV{TERM} eq 'dumb';
Branch: 1 branch
BranchTrueFalseTotal
if not $ENV{"TERM"} or $ENV{"TERM"} eq "dumb" 2 9 11
Condition100%3/3
not $ENV{"TERM"} or $ENV{"TERM"} eq "dumb"
l!l&&r!l&&!r
119
MC/DC100%2/2
not $ENV{"TERM"} or $ENV{"TERM"} eq "dumb"
not $ENV{"TERM"} $ENV{"TERM"} eq "dumb"
Truth table100%3/3
not(A) or B
A= not $ENV{"TERM"}B= $ENV{"TERM"} eq "dumb"
ABresult
1X1
011
000
57 9 ▶ return 'none' unless $self->_stdout_is_tty;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_stdout_is_tty 2 7 9
58 7 return 'quiet';
59 }
60  
61 1 ▶sub _stdout_is_tty { -t STDOUT }
Subroutine _stdout_is_tty: called CC=1 SCAR=0.0
62  
63 # Options passed to Pod::Text::Fancy->new.
64 15 ▶sub fancy_options {
Subroutine fancy_options: called CC=4 SCAR=13.9
Pod undocumented
65 15 my $self = shift;
66 0 my %opt = map { $_ => $self->{$_} } grep { !/^_/ } keys %$self;
67 15 $opt{width} = $self->width;
68 15 $opt{theme} = $self->_theme_to_use;
69 15 ▶ $opt{base} = $self->{_base} if defined $self->{_base};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_base"} 1 14 15
70 15 ▶ $opt{wall} = $self->{_wall} if defined $self->{_wall};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_wall"} 1 14 15
71 15 ▶ $opt{colormap} = { %{ $self->{_colormap} // {} } };
Condition100%2/2
$self->{"_colormap"} // {}
l!l
114
MC/DC100%1/1
$self->{"_colormap"} // {}
$self->{"_colormap"}
Truth table100%2/2
A
A= $self->{"_colormap"}
Aresult
11
00
72 15 return \%opt;
73 }
74  
75 0 ▶sub pager_configuration {
Subroutine pager_configuration: not called CC=5 SCAR=34.0
Pod undocumented
76 0 my ($self, $pager, $perldoc) = @_;
77 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
78 0 ▶ if ($pager =~ /less/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pager =~ /less/u) { } 0 0 0
elsif ($pager =~ /more/u) { } 0 0 0
79 0 $self->_maybe_modify_environment('LESS');
80 } elsif ($pager =~ /more/) {
81 0 $self->_maybe_modify_environment('MORE');
82 }
83 0 return;
84 }
85  
86 0 ▶sub _maybe_modify_environment {
Subroutine _maybe_modify_environment: not called CC=2 SCAR=17.9
87 0 my ($self, $name) = @_;
88 0 ▶ $ENV{$name} = '-R' unless defined $ENV{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV{$name} 0 0 0
89 }
90  
91 0 ▶sub _get_stty { `stty -a` }
Subroutine _get_stty: not called CC=1 SCAR=6.9
92  
93 16 ▶sub _get_columns_from_stty {
Subroutine _get_columns_from_stty: called CC=4 SCAR=14.2
94 16 ▶ my $output = $_[0]->_get_stty // '';
Condition50%1/2
$_[0]->_get_stty // ""
l!l
160
MC/DC0%0/1
$_[0]->_get_stty // ""
$_[0]->_get_stty
Truth table50%1/2
A
A= $_[0]->_get_stty
Aresult
11
00
95 16 ▶ return $1 if $output =~ /\bcolumns\s+(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $output =~ /\bcolumns\s+(\d+)/u 0 16 16
96 16 ▶ return $1 if $output =~ /;\s*(\d+)\s+columns;/;
Branch: 1 branch
BranchTrueFalseTotal
if $output =~ /;\s*(\d+)\s+columns;/u 1 15 16
97 15 return 0;
98 }
99  
100 18 ▶sub _get_columns_from_manwidth {
Subroutine _get_columns_from_manwidth: called CC=4 SCAR=15.5
101 18 my $self = shift;
102 18 my $w = $ENV{MANWIDTH};
103 18 ▶ return 0 unless defined $w;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $w 16 2 18
104 2 ▶ unless ($w =~ /\A\d+\z/ and $w > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($w =~ /\A\d+\z/u and $w > 0) 0 2 2
Condition33%1/3
$w =~ /\A\d+\z/u and $w > 0
!ll&&!rl&&r
002
MC/DC0%0/2
$w =~ /\A\d+\z/u and $w > 0
$w =~ /\A\d+\z/u $w > 0
Truth table33%1/3
A and B
A= $w =~ /\A\d+\z/uB= $w > 0
ABresult
0X0
100
111
105 0 $self->warn("Ignoring invalid MANWIDTH ($w)\n");
106 0 return 0;
107 }
108 2 return $w;
109 }
110  
111 15 ▶sub _get_default_width { 76 }
Subroutine _get_default_width: called CC=1 SCAR=0.0
112  
113 1 ▶sub parse_from_file {
Subroutine parse_from_file: called CC=1 SCAR=0.0
Pod undocumented
114 1 my $self = shift;
115 1 my %opt = %{ $self->fancy_options };
116 1 Pod::Text::Fancy->new(%opt)->parse_from_file(@_);
117 }
118  
119 3 1;
120 __END__
« Text/Fancy.pm ↑ Summary