File Coverage

blib/lib/IO/Pager/Unbuffered.pm
Criterion Covered Total %
statement 21 26 80.7
branch 5 10 50.0
condition 5 9 55.5
subroutine 5 6 83.3
pod 2 2 100.0
total 38 53 71.7


line stmt bran cond sub pod time code
1             package IO::Pager::Unbuffered;
2             our $VERSION = 1.04; #Untouched since 1.02
3              
4 3     3   1158 use strict;
  3         6  
  3         89  
5 3     3   15 use warnings;
  3         6  
  3         94  
6 3     3   17 use base qw( IO::Pager );
  3         7  
  3         401  
7 3     3   965 use SelectSaver;
  3         558  
  3         776  
8              
9              
10             sub new(;$) { # [FH], procedural
11 4     4 1 10 my($class, $tied_fh);
12              
13 4         8 eval { ($class, $tied_fh) = &IO::Pager::_init };
  4         28  
14             #We're not on a TTY so...
15 4 100 66     43 if( defined($class) && $class eq '0' or $@ =~ '!TTY' ){
      66        
16             #...leave filehandle alone if procedural
17 2 50 33     12 return $_[1] if defined($_[2]) && $_[2] eq 'procedural';
18              
19             #...fall back to IO::Handle for transparent OO programming
20 2 50       113 eval "require IO::Handle" or die $@;
21 2         4513 return IO::Handle->new_from_fd(fileno($_[1]), 'w');
22             }
23 2 50       8 $!=$@, return 0 if $@ =~ 'pipe';
24              
25 2 0       19 my $self = tie *$tied_fh, $class, $tied_fh or return 0;
26             { # Truly unbuffered
27 0           my $saver = SelectSaver->new($self->{real_fh});
  0            
28 0           $|=1;
29             }
30 0           return $self;
31             }
32              
33             #Punt to base, preserving FH ($_[0]) for pass by reference to gensym
34             sub open(;$) { # [FH]
35             # IO::Pager::open($_[0], 'IO::Pager::Unbuffered');
36 0     0 1   &new('IO::Pager::procedural', $_[0], 'procedural');
37             }
38              
39              
40             1;
41              
42             __END__