| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
-t STDOUT and not $no_pager
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
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | if (!exists $ENV{'SERGE_PAGER'} && !exists $ENV{'PAGER'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $ENV{'SERGE_PAGER'} || exists $ENV{'PAGER'}
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'}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # `more' pager is available under both *nix and Windows | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | $pager = 'more' unless $pager; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | } else { | ||||||||||||||||||||||||||||
| 34 | 0 | $pager = $ENV{'PAGER'}; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | $pager = $ENV{'SERGE_PAGER'} if exists $ENV{'SERGE_PAGER'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ($pager) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | open $file_handle, "|$pager" or die "Unable to start pager [$pager]: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | close $file_handle or die "Unable to close pager: $!";; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | undef $file_handle; | |||||||||||||||||||||||||||
| 58 | 0 | undef $can_close; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | 1; | |||||||||||||||||||||||||||