| 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
Condition0%0/6
defined $class and $class eq 0 or $@ =~ /!TTY/
defined $class and $class eq 0
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/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | #...leave filehandle alone if procedural | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | return $_[1] if defined($_[2]) && $_[2] eq 'procedural'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_[2] and $_[2] eq "procedural"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | #...fall back to IO::Handle for transparent OO programming | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | eval "require IO::Handle" or die $@; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | return IO::Handle->new_from_fd(fileno($_[1]), 'w'); | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | $!=$@, return 0 if $@ =~ 'pipe'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | tie *$tied_fh, $class, $tied_fh or return 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
$, || ''
MC/DC0%0/1
$, || ''
$,
Truth table0%0/2
A
A= $,
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $self->{"buffer"} and length $self->{"buffer"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||