Pager/Buffered.pm

filter: Statementstmt 44.1% 19 / 43 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 45.4% 5 / 11 Podpod 100% 3 / 3 totaltotal 28.4% 27 / 95 SCAR 45.4
CC
14
Cov
26%
new
90.0
CLOSE
12.0
PRINT
6.0
CRAP 93.3
« Pager.pm ↑ Summary Pager/less.pm »
1 package IO::Pager::Buffered;
2 1 our $VERSION = 1.04; #Untouched since 1.03
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base qw( IO::Pager );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use SelectSaver;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 sub new(;$) { # [FH], procedural
10 0 ▶ my($class, $tied_fh);
Subroutine new: not called CC=9 SCAR=45.0
Pod documented
11  
12 0 eval { ($class, $tied_fh) = &IO::Pager::_init };
13 #We're not on a TTY so...
14 0 ▶ if( defined($class) && $class eq '0' or $@ =~ '!TTY' ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $class and $class eq 0 or $@ =~ /!TTY/) 0 0 0
Condition0%0/6
defined $class and $class eq 0 or $@ =~ /!TTY/
l!l&&r!l&&!r
000
defined $class and $class eq 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $class and $class eq 0 or $@ =~ /!TTY/
defined $class $class eq 0 $@ =~ /!TTY/
Truth table0%0/5
A and B or C
A= defined $classB= $class eq 0C= $@ =~ /!TTY/
ABCresult
11X1
0X11
1011
0X00
1000
15 #...leave filehandle alone if procedural
16 0 ▶ return $_[1] if defined($_[2]) && $_[2] eq 'procedural';
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[2] and $_[2] eq "procedural" 0 0 0
Condition0%0/3
defined $_[2] and $_[2] eq "procedural"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[2] and $_[2] eq "procedural"
defined $_[2] $_[2] eq "procedural"
Truth table0%0/3
A and B
A= defined $_[2]B= $_[2] eq "procedural"
ABresult
0X0
100
111
17  
18 #...fall back to IO::Handle for transparent OO programming
19 0 ▶ eval "require IO::Handle" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require IO::Handle" or die $@ 0 0 0
20 0 return IO::Handle->new_from_fd(fileno($_[1]), 'w');
21 }
22 0 ▶ $!=$@, return 0 if $@ =~ 'pipe';
Branch: 1 branch
BranchTrueFalseTotal
if $@ =~ /pipe/ 0 0 0
23  
24 0 ▶ tie *$tied_fh, $class, $tied_fh or return 0;
Branch: 1 branch
BranchTrueFalseTotal
tie *$tied_fh, $class, $tied_fh or return 0 0 0 0
25 }
26  
27 #Punt to base, preserving FH ($_[0]) for pass by reference to gensym
28 sub open(;$) { # [FH]
29 # IO::Pager::open($_[0], 'IO::Pager::Buffered');
30 0 ▶ &new('IO::Pager::Buffered', $_[0], 'procedural');
Subroutine open: not called CC=1 SCAR=6.9
Pod documented
31 }
32  
33  
34 # Overload IO::Pager methods
35  
36 sub PRINT {
37 0 ▶ my ($self, @args) = @_;
Subroutine PRINT: not called CC=2 SCAR=17.9
38 0 ▶ $self->{buffer} .= join($,||'', @args);
Condition0%0/2
$, || ''
l!l
00
MC/DC0%0/1
$, || ''
$,
Truth table0%0/2
A
A= $,
Aresult
11
00
39 }
40  
41  
42 sub CLOSE {
43 0 ▶ my ($self) = @_;
Subroutine CLOSE: not called CC=3 SCAR=24.8
44 # Print buffer and close using IO::Pager's methods
45 $self->SUPER::PRINT($self->{buffer}) if
46 0 ▶ exists($self->{buffer}) && length($self->{buffer});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"buffer"} and length $self->{"buffer"} 0 0 0
Condition0%0/3
exists $self->{"buffer"} and length $self->{"buffer"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"buffer"} and length $self->{"buffer"}
exists $self->{"buffer"} length $self->{"buffer"}
Truth table0%0/3
A and B
A= exists $self->{"buffer"}B= length $self->{"buffer"}
ABresult
0X0
100
111
47 0 $self->{buffer}='';
48 0 $self->SUPER::CLOSE();
49 }
50  
51 1 ▶{ no warnings 'once'; *DESTROY = \&CLOSE; }
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 sub TELL {
54 # Return the size of the buffer
55 0 ▶ my ($self) = @_;
Subroutine TELL: not called CC=2 SCAR=10.1
56 1 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 0 ▶ return exists($self->{buffer}) ? length($self->{buffer}) : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'buffer'} ? : 0 0 0
58 }
59  
60  
61 sub flush(;*) {
62 0 ▶ my ($self) = @_;
Subroutine flush: not called CC=2 SCAR=17.9
Pod documented
63 0 ▶ if( exists $self->{buffer} ){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"buffer"}) 0 0 0
64 0 my $saver = SelectSaver->new($self->{real_fh});
65 0 local $|=1;
66 0 ($_, $self->{buffer}) = ( $self->{buffer}, '');
67 0 $self->SUPER::PRINT($_);
68 }
69 }
70  
71  
72 1 1;
73  
74 __END__
« Pager.pm ↑ Summary Pager/less.pm »