lib/Serge/Util/Pager.pm

filter: Statementstmt 53.4% 23 / 43 Branchbran 4.5% 1 / 22 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 3 totaltotal 34.4% 30 / 87 SCAR 41.3
CC
13
Cov
34%
init
110.0
close
12.0
print
6.0
CRAP 62.0
« lib/Serge/Engine/Plugin/run_command.pm ↑ Summary lib/Serge/Engine/Plugin/apply_xslt.pm »
1 package Serge::Util::Pager;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our @ISA = qw(Exporter);
9  
10 1 my $no_pager;
11 1 ▶GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("no-pager", \$no_pager) or die "Failed to parse some command-line parameters." 0 1 1
12 'no-pager' => \$no_pager,
13 ) or die "Failed to parse some command-line parameters.";
14  
15 1 my ($file_handle, $can_close);
16  
17 sub init {
18 0 ▶ my $pager;
Subroutine init: not called CC=10 SCAR=47.0
Pod undocumented
19  
20 # disable pager if STDOUT is not tied to an interactive terminal
21 # or if --no-pager option has been provided on a command line
22 0 ▶ if (-t STDOUT && !$no_pager) {
Branch: 1 branch
BranchTrueFalseTotal
if (-t STDOUT and not $no_pager) 0 0 0
Condition0%0/3
-t STDOUT and not $no_pager
!ll&&!rl&&r
000
MC/DC0%0/2
-t STDOUT and not $no_pager
-t STDOUT not $no_pager
Truth table0%0/3
A and not(B)
A= -t STDOUTB= not $no_pager
ABresult
0X0
100
111
23 0 ▶ if (!exists $ENV{'SERGE_PAGER'} && !exists $ENV{'PAGER'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $ENV{'SERGE_PAGER'} || exists $ENV{'PAGER'}) { } 0 0 0
Condition0%0/3
exists $ENV{'SERGE_PAGER'} || exists $ENV{'PAGER'}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $ENV{'SERGE_PAGER'} || exists $ENV{'PAGER'}
exists $ENV{'SERGE_PAGER'} exists $ENV{'PAGER'}
Truth table0%0/3
A || B
A= exists $ENV{'SERGE_PAGER'}B= exists $ENV{'PAGER'}
ABresult
1X1
011
000
24 # test if `less` pager is available; under Windows, this usually comes
25 # with other *nix utilities, including `which` (installed along with e.g. Git).
26 # so this either works together (`which less`) or doesn't work at all
27 0 `which less 2>&1`;
28 0 my $error_code = unpack 'c', pack 'C', $? >> 8; # error code
29 0 ▶ $pager = 'less -XFR' if ($error_code == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $error_code == 0 0 0 0
30  
31 # `more' pager is available under both *nix and Windows
32 0 ▶ $pager = 'more' unless $pager;
Branch: 1 branch
BranchTrueFalseTotal
unless $pager 0 0 0
33 } else {
34 0 $pager = $ENV{'PAGER'};
35 0 ▶ $pager = $ENV{'SERGE_PAGER'} if exists $ENV{'SERGE_PAGER'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $ENV{"SERGE_PAGER"} 0 0 0
36 }
37 }
38  
39 0 ▶ if ($pager) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pager) { } 0 0 0
40 0 ▶ open $file_handle, "|$pager" or die "Unable to start pager [$pager]: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $file_handle, "|$pager" or die "Unable to start pager [$pager]: $!" 0 0 0
41 0 $can_close = 1;
42 } else {
43 0 $file_handle = \*STDOUT;
44 }
45  
46 0 return $file_handle;
47 }
48  
49 sub print {
50 0 ▶ die "Pager file handle is undefined" unless defined $file_handle;
Subroutine print: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file_handle 0 0 0
51 0 print $file_handle @_;
52 }
53  
54 sub close {
55 0 ▶ if ($can_close) {
Subroutine close: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ($can_close) 0 0 0
56 0 ▶ close $file_handle or die "Unable to close pager: $!";;
Branch: 1 branch
BranchTrueFalseTotal
CORE::close $file_handle or die "Unable to close pager: $!" 0 0 0
57 0 undef $file_handle;
58 0 undef $can_close;
59 }
60 }
61  
62 1 1;
« lib/Serge/Engine/Plugin/run_command.pm ↑ Summary lib/Serge/Engine/Plugin/apply_xslt.pm »